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.
This commit is contained in:
W. Trevor King 2013-03-11 08:25:47 -04:00
commit b59da89e80
10 changed files with 19 additions and 16 deletions

View file

@ -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__

View file

@ -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, '')

View file

@ -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)

View file

@ -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',

View file

@ -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")

View file

@ -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)

View file

@ -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)

View file

@ -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.'

3
pelican/tools/templates/publishconf.py.in Normal file → Executable file
View file

@ -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'

View file

@ -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)