From 10e668a87cd0e1fba125d04bcf93465600c81ba6 Mon Sep 17 00:00:00 2001 From: solsTiCe d'Hiver Date: Mon, 9 Jul 2012 15:25:13 +0200 Subject: [PATCH 1/4] Fix issue #175 Force world-readable permission on files and directory of the themes installed by pelican-themes. Only on posix system i.e. mostly non Windows Rationale: If the theme's files have only -rw------- permissions, once installed system wide and owned by root, they will not be accessible to any user but only root. --- pelican/tools/pelican_themes.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pelican/tools/pelican_themes.py b/pelican/tools/pelican_themes.py index 6a021ecc..0083dd50 100755 --- a/pelican/tools/pelican_themes.py +++ b/pelican/tools/pelican_themes.py @@ -180,8 +180,19 @@ def install(path, v=False, u=False): print("Copying `{p}' to `{t}' ...".format(p=path, t=theme_path)) try: shutil.copytree(path, theme_path) - except Exception, e: + + if os.name == 'posix': + for root, dirs, files in os.walk(theme_path): + for d in dirs: + dname = os.path.join(root, d) + os.chmod(dname, 0755) + for f in files: + fname = os.path.join(root, f) + os.chmod(fname, 0644) + except shutil.Error, e: err("Cannot copy `{p}' to `{t}':\n{e}".format(p=path, t=theme_path, e=str(e))) + except OSError, e: + err("Cannot change permissions of files or directory in `{r}':\n{e}".format(r=theme_path, e=str(e)), die=False) def symlink(path, v=False): From 4acbbb8d0fa157fbb0cb10e2b0c6abc428f8ffab Mon Sep 17 00:00:00 2001 From: solsTiCe d'Hiver Date: Mon, 9 Jul 2012 19:48:53 +0200 Subject: [PATCH 2/4] Use logging module instead of err function --- pelican/tools/pelican_themes.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pelican/tools/pelican_themes.py b/pelican/tools/pelican_themes.py index 0083dd50..2fe4f459 100755 --- a/pelican/tools/pelican_themes.py +++ b/pelican/tools/pelican_themes.py @@ -192,7 +192,9 @@ def install(path, v=False, u=False): except shutil.Error, e: err("Cannot copy `{p}' to `{t}':\n{e}".format(p=path, t=theme_path, e=str(e))) except OSError, e: - err("Cannot change permissions of files or directory in `{r}':\n{e}".format(r=theme_path, e=str(e)), die=False) + import logging + logger = logging.getLogger(__name__) + logger.warning("Cannot change permissions of files or directory in `{r}':\n{e}".format(r=theme_path, e=str(e))) def symlink(path, v=False): From 842817f110481c280b7a121e96a9a818c8354f6a Mon Sep 17 00:00:00 2001 From: solsTiCe d'Hiver Date: Mon, 9 Jul 2012 20:05:21 +0200 Subject: [PATCH 3/4] Revert "Use logging module instead of err function" This reverts commit 4acbbb8d0fa157fbb0cb10e2b0c6abc428f8ffab. I don't know how to use logging/logger This throws: No handlers could be found for logger "pelican.tools.pelican_themes" --- pelican/tools/pelican_themes.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pelican/tools/pelican_themes.py b/pelican/tools/pelican_themes.py index 2fe4f459..0083dd50 100755 --- a/pelican/tools/pelican_themes.py +++ b/pelican/tools/pelican_themes.py @@ -192,9 +192,7 @@ def install(path, v=False, u=False): except shutil.Error, e: err("Cannot copy `{p}' to `{t}':\n{e}".format(p=path, t=theme_path, e=str(e))) except OSError, e: - import logging - logger = logging.getLogger(__name__) - logger.warning("Cannot change permissions of files or directory in `{r}':\n{e}".format(r=theme_path, e=str(e))) + err("Cannot change permissions of files or directory in `{r}':\n{e}".format(r=theme_path, e=str(e)), die=False) def symlink(path, v=False): From a0d2d3446649066e7f03560953b5962d9fdcadf5 Mon Sep 17 00:00:00 2001 From: solsTiCe d'Hiver Date: Mon, 9 Jul 2012 20:07:31 +0200 Subject: [PATCH 4/4] shutil.copytree seems to throw OSError exception too So revert to previous Exception handling --- pelican/tools/pelican_themes.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/pelican/tools/pelican_themes.py b/pelican/tools/pelican_themes.py index 0083dd50..d13e60e9 100755 --- a/pelican/tools/pelican_themes.py +++ b/pelican/tools/pelican_themes.py @@ -181,18 +181,19 @@ def install(path, v=False, u=False): try: shutil.copytree(path, theme_path) - if os.name == 'posix': - for root, dirs, files in os.walk(theme_path): - for d in dirs: - dname = os.path.join(root, d) - os.chmod(dname, 0755) - for f in files: - fname = os.path.join(root, f) - os.chmod(fname, 0644) - except shutil.Error, e: + try: + if os.name == 'posix': + for root, dirs, files in os.walk(theme_path): + for d in dirs: + dname = os.path.join(root, d) + os.chmod(dname, 0755) + for f in files: + fname = os.path.join(root, f) + os.chmod(fname, 0644) + except OSError, e: + err("Cannot change permissions of files or directory in `{r}':\n{e}".format(r=theme_path, e=str(e)), die=False) + except Exception, e: err("Cannot copy `{p}' to `{t}':\n{e}".format(p=path, t=theme_path, e=str(e))) - except OSError, e: - err("Cannot change permissions of files or directory in `{r}':\n{e}".format(r=theme_path, e=str(e)), die=False) def symlink(path, v=False):