From fd19a89ed432a2b644a623e42dd509ba0fc317b0 Mon Sep 17 00:00:00 2001 From: Richard Darst Date: Sun, 7 Oct 2018 19:25:25 +0300 Subject: [PATCH] Code cleanup: remove commented code and reformat try/except - Thanks to @jhamrick --- nbgrader/converters/base.py | 14 ++++++++------ nbgrader/exchange/exchange.py | 6 ++++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/nbgrader/converters/base.py b/nbgrader/converters/base.py index 158d11663..8c87509bf 100644 --- a/nbgrader/converters/base.py +++ b/nbgrader/converters/base.py @@ -251,10 +251,10 @@ def set_permissions(self, assignment_id, student_id): os.chmod(os.path.join(dirname, filename), permissions) # If groupshared, set dir permissions - see comment below. if self.coursedir.groupshared and os.stat(dirname).st_uid == os.getuid(): - #for subdirname in subdirnames: - # subdirname = os.path.join(dirname, subdirname) - try: os.chmod(dirname, (os.stat(dirname).st_mode|0o2770) & 0o2777) - except PermissionError: pass + try: + os.chmod(dirname, (os.stat(dirname).st_mode|0o2770) & 0o2777) + except PermissionError: + pass # If groupshared, set write permissions on directories. Directories # are created within ipython_genutils.path.ensure_dir_exists via # nbconvert.writer, (unless there are supplementary files) with a @@ -264,8 +264,10 @@ def set_permissions(self, assignment_id, student_id): # Root may be created in this step, and is not included above. rootdir = self.coursedir.format_path(self._output_directory, '.', '.') # Add 2770 to existing dir permissions (don't unconditionally override) - try: os.chmod(rootdir, (os.stat(rootdir).st_mode|0o2770) & 0o2777) - except PermissionError: pass + try: + os.chmod(rootdir, (os.stat(rootdir).st_mode|0o2770) & 0o2777) + except PermissionError: + pass def convert_single_notebook(self, notebook_filename): diff --git a/nbgrader/exchange/exchange.py b/nbgrader/exchange/exchange.py index 9687fd6c1..a802fa101 100644 --- a/nbgrader/exchange/exchange.py +++ b/nbgrader/exchange/exchange.py @@ -126,8 +126,10 @@ def do_copy(self, src, dest): if self.coursedir.groupshared: for dirname, _, filenames in os.walk(dest): # dirs become ug+rwx - try: os.chmod(dirname, (os.stat(dirname).st_mode|0o2770) & 0o2777) - except PermissionError: pass + try: + os.chmod(dirname, (os.stat(dirname).st_mode|0o2770) & 0o2777) + except PermissionError: + pass for filename in filenames: filename = os.path.join(dirname, filename) try: os.chmod(filename, (os.stat(filename).st_mode|0o660) & 0o777)