From b59da89e80552ab9ace9a116049dd14b5f1f3946 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 11 Mar 2013 08:25:47 -0400 Subject: [PATCH] Convert '.' and '..' to the less magical os.curdir and os.pardir While I'm cleaning up path manipulation, I might as well make things more semantic. --- docs/conf.py | 2 +- pelican/__init__.py | 2 +- pelican/generators.py | 2 +- pelican/settings.py | 2 +- pelican/tests/test_pelican.py | 2 +- pelican/tests/test_settings.py | 3 ++- pelican/tests/test_utils.py | 6 +++--- pelican/tools/pelican_quickstart.py | 7 ++++--- pelican/tools/templates/publishconf.py.in | 3 ++- pelican/utils.py | 6 +++--- 10 files changed, 19 insertions(+), 16 deletions(-) mode change 100644 => 100755 pelican/tools/templates/publishconf.py.in diff --git a/docs/conf.py b/docs/conf.py index 6c8ececa..40de84c7 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals import sys, os -sys.path.append(os.path.abspath('..')) +sys.path.append(os.path.abspath(os.pardir)) from pelican import __version__, __major__ diff --git a/pelican/__init__.py b/pelican/__init__.py index 0e3db788..2c67c5f3 100644 --- a/pelican/__init__.py +++ b/pelican/__init__.py @@ -52,7 +52,7 @@ class Pelican(object): signals.initialized.send(self) def init_path(self): - if not any(p in sys.path for p in ['', '.']): + if not any(p in sys.path for p in ['', os.curdir]): logger.debug("Adding current directory to system path") sys.path.insert(0, '') diff --git a/pelican/generators.py b/pelican/generators.py index f0d78d2c..97315a26 100644 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -588,7 +588,7 @@ class StaticGenerator(Generator): def generate_output(self, writer): self._copy_paths(self.settings['THEME_STATIC_PATHS'], self.theme, - 'theme', self.output_path, '.') + 'theme', self.output_path, os.curdir) # copy all Static files for sc in self.staticfiles: source_path = os.path.join(self.path, sc.source_path) diff --git a/pelican/settings.py b/pelican/settings.py index 834b90af..25685d72 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -17,7 +17,7 @@ logger = logging.getLogger(__name__) DEFAULT_THEME = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'themes', 'notmyidea') -_DEFAULT_CONFIG = {'PATH': '.', +_DEFAULT_CONFIG = {'PATH': os.curdir, 'ARTICLE_DIR': '', 'ARTICLE_EXCLUDES': ('pages',), 'PAGE_DIR': 'pages', diff --git a/pelican/tests/test_pelican.py b/pelican/tests/test_pelican.py index 0b94bd02..c8f1daf5 100644 --- a/pelican/tests/test_pelican.py +++ b/pelican/tests/test_pelican.py @@ -14,7 +14,7 @@ from pelican.tests.support import LoggedTestCase CURRENT_DIR = os.path.dirname(os.path.abspath(__file__)) SAMPLES_PATH = os.path.abspath(os.path.join( - CURRENT_DIR, '..', '..', 'samples')) + CURRENT_DIR, os.pardir, os.pardir, 'samples')) OUTPUT_PATH = os.path.abspath(os.path.join(CURRENT_DIR, 'output')) INPUT_PATH = os.path.join(SAMPLES_PATH, "content") diff --git a/pelican/tests/test_settings.py b/pelican/tests/test_settings.py index d9bca2e5..5f1f4ede 100644 --- a/pelican/tests/test_settings.py +++ b/pelican/tests/test_settings.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals, print_function import copy +import os from os.path import dirname, abspath, join from pelican.settings import (read_settings, configure_settings, @@ -62,7 +63,7 @@ class TestSettingsConfiguration(unittest.TestCase): settings = { 'SITEURL': 'http://blog.notmyidea.org/', 'LOCALE': '', - 'PATH': '.', + 'PATH': os.curdir, 'THEME': DEFAULT_THEME, } configure_settings(settings) diff --git a/pelican/tests/test_utils.py b/pelican/tests/test_utils.py index ab9ae226..ae2e0a13 100644 --- a/pelican/tests/test_utils.py +++ b/pelican/tests/test_utils.py @@ -71,9 +71,9 @@ class TestUtils(LoggedTestCase): def test_get_relative_path(self): - samples = (('test/test.html', '..'), - ('test/test/test.html', '../..'), - ('test.html', '.')) + samples = (('test/test.html', os.pardir), + ('test/test/test.html', os.path.join(os.pardir, os.pardir)), + ('test.html', os.curdir)) for value, expected in samples: self.assertEquals(utils.get_relative_path(value), expected) diff --git a/pelican/tools/pelican_quickstart.py b/pelican/tools/pelican_quickstart.py index 6d4264d3..02aa62d3 100755 --- a/pelican/tools/pelican_quickstart.py +++ b/pelican/tools/pelican_quickstart.py @@ -18,7 +18,7 @@ _TEMPLATES_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), CONF = { 'pelican': 'pelican', 'pelicanopts': '', - 'basedir': '.', + 'basedir': os.curdir, 'ftp_host': 'localhost', 'ftp_user': 'anonymous', 'ftp_target_dir': '/', @@ -146,7 +146,7 @@ def main(): parser = argparse.ArgumentParser( description="A kickstarter for Pelican", formatter_class=argparse.ArgumentDefaultsHelpFormatter) - parser.add_argument('-p', '--path', default=".", + parser.add_argument('-p', '--path', default=os.curdir, help="The path to generate the blog into") parser.add_argument('-t', '--title', metavar="title", help='Set the title of the website') @@ -166,7 +166,8 @@ needed by Pelican. '''.format(v=__version__)) - project = os.path.join(os.environ.get('VIRTUAL_ENV', '.'), '.project') + project = os.path.join( + os.environ.get('VIRTUAL_ENV', os.curdir), '.project') if os.path.isfile(project): CONF['basedir'] = open(project, 'r').read().rstrip("\n") print('Using project associated with current virtual environment.' diff --git a/pelican/tools/templates/publishconf.py.in b/pelican/tools/templates/publishconf.py.in old mode 100644 new mode 100755 index 7115a6a1..8fd2a4f7 --- a/pelican/tools/templates/publishconf.py.in +++ b/pelican/tools/templates/publishconf.py.in @@ -4,8 +4,9 @@ # This file is only used if you use `make publish` or # explicitly specify it as your config file. +import os import sys -sys.path.append('.') +sys.path.append(os.curdir) from pelicanconf import * SITEURL = '$siteurl' diff --git a/pelican/utils.py b/pelican/utils.py index 4e1c8156..a0473ecb 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -306,9 +306,9 @@ def get_relative_path(path): """Return the relative path from the given path to the root path.""" nslashes = path.count('/') if nslashes == 0: - return '.' + return os.curdir else: - return '/'.join(['..'] * nslashes) + return '/'.join([os.pardir] * nslashes) def truncate_html_words(s, num, end_text='...'): @@ -429,7 +429,7 @@ def files_changed(path, extensions, ignores=[]): def file_times(path): """Return the last time files have been modified""" for root, dirs, files in os.walk(path): - dirs[:] = [x for x in dirs if x[0] != '.'] + dirs[:] = [x for x in dirs if x[0] != os.curdir] for f in files: if any(f.endswith(ext) for ext in extensions) \ and not any(fnmatch.fnmatch(f, ignore)