mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Replace os.sep.join with the more robust os.path.join
From the Python docs for os.sep [1]: Note that knowing this is not sufficient to be able to parse or concatenate pathnames - use os.path.split() and os.path.join()... Where I touched a line, I also changed double quoted string literals to single quotes, since they are used more often in the source: wking@mjolnir ~/src/pelican $ git grep "'" pelican/*.py | wc -l 683 wking@mjolnir ~/src/pelican $ git grep '"' pelican/*.py | wc -l 181 [1]: http://docs.python.org/3/library/os.html#os.sep
This commit is contained in:
parent
4e5454912f
commit
e5e455e0e5
3 changed files with 26 additions and 22 deletions
|
|
@ -347,7 +347,7 @@ class ArticlesGenerator(Generator):
|
|||
def generate_drafts(self, write):
|
||||
"""Generate drafts pages."""
|
||||
for article in self.drafts:
|
||||
write('drafts/%s.html' % article.slug,
|
||||
write(os.path.join('drafts', '%s.html' % article.slug),
|
||||
self.get_template(article.template), self.context,
|
||||
article=article, category=article.category,
|
||||
all_articles=self.articles)
|
||||
|
|
|
|||
|
|
@ -15,21 +15,22 @@ from os.path import isabs
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
DEFAULT_THEME = os.sep.join([os.path.dirname(os.path.abspath(__file__)),
|
||||
"themes/notmyidea"])
|
||||
DEFAULT_THEME = os.path.join(os.path.dirname(os.path.abspath(__file__)),
|
||||
'themes', 'notmyidea')
|
||||
_DEFAULT_CONFIG = {'PATH': '.',
|
||||
'ARTICLE_DIR': '',
|
||||
'ARTICLE_EXCLUDES': ('pages',),
|
||||
'PAGE_DIR': 'pages',
|
||||
'PAGE_EXCLUDES': (),
|
||||
'THEME': DEFAULT_THEME,
|
||||
'OUTPUT_PATH': 'output/',
|
||||
'OUTPUT_PATH': 'output',
|
||||
'MARKUP': ('rst', 'md'),
|
||||
'STATIC_PATHS': ['images', ],
|
||||
'THEME_STATIC_PATHS': ['static', ],
|
||||
'FEED_ALL_ATOM': 'feeds/all.atom.xml',
|
||||
'CATEGORY_FEED_ATOM': 'feeds/%s.atom.xml',
|
||||
'TRANSLATION_FEED_ATOM': 'feeds/all-%s.atom.xml',
|
||||
'FEED_ALL_ATOM': os.path.join('feeds', 'all.atom.xml'),
|
||||
'CATEGORY_FEED_ATOM': os.path.join('feeds', '%s.atom.xml'),
|
||||
'TRANSLATION_FEED_ATOM': os.path.join(
|
||||
'feeds', 'all-%s.atom.xml'),
|
||||
'FEED_MAX_ITEMS': '',
|
||||
'SITEURL': '',
|
||||
'SITENAME': 'A Pelican Blog',
|
||||
|
|
@ -49,17 +50,18 @@ _DEFAULT_CONFIG = {'PATH': '.',
|
|||
'ARTICLE_LANG_URL': '{slug}-{lang}.html',
|
||||
'ARTICLE_LANG_SAVE_AS': '{slug}-{lang}.html',
|
||||
'PAGE_URL': 'pages/{slug}.html',
|
||||
'PAGE_SAVE_AS': 'pages/{slug}.html',
|
||||
'PAGE_SAVE_AS': os.path.join('pages', '{slug}.html'),
|
||||
'PAGE_LANG_URL': 'pages/{slug}-{lang}.html',
|
||||
'PAGE_LANG_SAVE_AS': 'pages/{slug}-{lang}.html',
|
||||
'PAGE_LANG_SAVE_AS': os.path.join(
|
||||
'pages', '{slug}-{lang}.html'),
|
||||
'STATIC_URL': '{path}',
|
||||
'STATIC_SAVE_AS': '{path}',
|
||||
'CATEGORY_URL': 'category/{slug}.html',
|
||||
'CATEGORY_SAVE_AS': 'category/{slug}.html',
|
||||
'CATEGORY_SAVE_AS': os.path.join('category', '{slug}.html'),
|
||||
'TAG_URL': 'tag/{slug}.html',
|
||||
'TAG_SAVE_AS': 'tag/{slug}.html',
|
||||
'TAG_SAVE_AS': os.path.join('tag', '{slug}.html'),
|
||||
'AUTHOR_URL': 'author/{slug}.html',
|
||||
'AUTHOR_SAVE_AS': 'author/{slug}.html',
|
||||
'AUTHOR_SAVE_AS': os.path.join('author', '{slug}.html'),
|
||||
'YEAR_ARCHIVE_SAVE_AS': False,
|
||||
'MONTH_ARCHIVE_SAVE_AS': False,
|
||||
'DAY_ARCHIVE_SAVE_AS': False,
|
||||
|
|
@ -141,8 +143,10 @@ def configure_settings(settings):
|
|||
|
||||
# lookup the theme in "pelican/themes" if the given one doesn't exist
|
||||
if not os.path.isdir(settings['THEME']):
|
||||
theme_path = os.sep.join([os.path.dirname(
|
||||
os.path.abspath(__file__)), "themes/%s" % settings['THEME']])
|
||||
theme_path = os.path.join(
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
'themes',
|
||||
settings['THEME'])
|
||||
if os.path.exists(theme_path):
|
||||
settings['THEME'] = theme_path
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ from pelican.settings import read_settings
|
|||
from pelican.tests.support import LoggedTestCase
|
||||
|
||||
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
SAMPLES_PATH = os.path.abspath(os.sep.join((CURRENT_DIR, "..", "..",
|
||||
"samples")))
|
||||
OUTPUT_PATH = os.path.abspath(os.sep.join((CURRENT_DIR, "output")))
|
||||
SAMPLES_PATH = os.path.abspath(os.path.join(
|
||||
CURRENT_DIR, '..', '..', 'samples'))
|
||||
OUTPUT_PATH = os.path.abspath(os.path.join(CURRENT_DIR, 'output'))
|
||||
|
||||
INPUT_PATH = os.path.join(SAMPLES_PATH, "content")
|
||||
SAMPLE_CONFIG = os.path.join(SAMPLES_PATH, "pelican.conf.py")
|
||||
|
|
@ -23,11 +23,11 @@ SAMPLE_CONFIG = os.path.join(SAMPLES_PATH, "pelican.conf.py")
|
|||
|
||||
def recursiveDiff(dcmp):
|
||||
diff = {
|
||||
'diff_files': [os.sep.join((dcmp.right, f))
|
||||
'diff_files': [os.path.join(dcmp.right, f)
|
||||
for f in dcmp.diff_files],
|
||||
'left_only': [os.sep.join((dcmp.right, f))
|
||||
'left_only': [os.path.join(dcmp.right, f)
|
||||
for f in dcmp.left_only],
|
||||
'right_only': [os.sep.join((dcmp.right, f))
|
||||
'right_only': [os.path.join(dcmp.right, f)
|
||||
for f in dcmp.right_only],
|
||||
}
|
||||
for sub_dcmp in dcmp.subdirs.values():
|
||||
|
|
@ -74,7 +74,7 @@ class TestPelican(LoggedTestCase):
|
|||
})
|
||||
pelican = Pelican(settings=settings)
|
||||
pelican.run()
|
||||
dcmp = dircmp(self.temp_path, os.sep.join((OUTPUT_PATH, "basic")))
|
||||
dcmp = dircmp(self.temp_path, os.path.join(OUTPUT_PATH, 'basic'))
|
||||
self.assertFilesEqual(recursiveDiff(dcmp))
|
||||
self.assertLogCountEqual(
|
||||
count=10,
|
||||
|
|
@ -90,5 +90,5 @@ class TestPelican(LoggedTestCase):
|
|||
})
|
||||
pelican = Pelican(settings=settings)
|
||||
pelican.run()
|
||||
dcmp = dircmp(self.temp_path, os.sep.join((OUTPUT_PATH, "custom")))
|
||||
dcmp = dircmp(self.temp_path, os.path.join(OUTPUT_PATH, 'custom'))
|
||||
self.assertFilesEqual(recursiveDiff(dcmp))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue