Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: sitescripts/cms/sources.py

Issue 5567002995326976: Multiple CMS improvements (Closed)
Patch Set: Addressed comments Created Dec. 11, 2013, 12:02 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sitescripts/cms/converters.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sitescripts/cms/sources.py
===================================================================
--- a/sitescripts/cms/sources.py
+++ b/sitescripts/cms/sources.py
@@ -22,16 +22,20 @@ from ConfigParser import SafeConfigParse
class Source:
def resolve_link(self, url, locale):
parsed = urlparse.urlparse(url)
page = parsed.path
if parsed.scheme != "" or page.startswith("/") or page.startswith("."):
# Not a page link
return None, None
+ if parsed.path == "" and url != "":
+ # Page-relative link
+ return None, None
+
config = self.read_config()
default_locale = config.get("general", "defaultlocale")
default_page = config.get("general", "defaultpage")
checked_page = page
if config.has_option("locale_overrides", page):
checked_page = config.get("locale_overrides", page)
@@ -62,17 +66,17 @@ class Source:
@staticmethod
def page_filename(page, format):
return "pages/%s.%s" % (page, format)
def list_pages(self):
for filename in self.list_files("pages"):
root, ext = os.path.splitext(filename)
- format = ext[1:]
+ format = ext[1:].lower()
yield root, format
def has_page(self, page, format):
return self.has_file(self.page_filename(page, format))
def read_page(self, page, format):
return self.read_file(self.page_filename(page, format))
@@ -82,17 +86,17 @@ class Source:
@staticmethod
def localizable_file_filename(locale, filename):
return "locales/%s/%s" % (locale, filename)
def list_localizable_files(self):
default_locale = self.read_config().get("general", "defaultlocale")
return filter(
- lambda f: os.path.splitext(f)[1] != ".json",
+ lambda f: os.path.splitext(f)[1].lower() != ".json",
self.list_files("locales/%s" % default_locale)
)
def has_localizable_file(self, locale, filename):
return self.has_file(self.localizable_file_filename(locale, filename))
def read_localizable_file(self, locale, filename):
return self.read_file(self.localizable_file_filename(locale, filename), binary=True)
@@ -237,17 +241,21 @@ class FileSource(Source):
def read_file(self, filename, binary=False):
encoding = None if binary else "utf-8"
with codecs.open(self.get_path(filename), "rb", encoding=encoding) as handle:
return handle.read()
def list_files(self, subdir):
result = []
def do_list(dir, relpath):
- files = os.listdir(dir)
+ try:
+ files = os.listdir(dir)
+ except OSError:
+ return
+
for filename in files:
path = os.path.join(dir, filename)
if os.path.isfile(path):
result.append(relpath + filename)
elif os.path.isdir(path):
do_list(path, relpath + filename + "/")
do_list(self.get_path(subdir), "")
return result
« no previous file with comments | « sitescripts/cms/converters.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld