summaryrefslogtreecommitdiff
path: root/tools/deploystatic/deploystatic.py
diff options
context:
space:
mode:
authorMagnus Hagander2018-12-14 14:43:56 +0000
committerMagnus Hagander2018-12-14 15:31:28 +0000
commit7dea97f90b534f71cbec6d0e5dfbdf237403b1f1 (patch)
tree48c53ef74987f68c05f12fb1e97b02f25a13e45a /tools/deploystatic/deploystatic.py
parente0bfd4f892e43db89bc996c1474f59c2dd6a8dc6 (diff)
Fix blankline related warnings
Diffstat (limited to 'tools/deploystatic/deploystatic.py')
-rwxr-xr-xtools/deploystatic/deploystatic.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/tools/deploystatic/deploystatic.py b/tools/deploystatic/deploystatic.py
index bd131243..ce4d8a3e 100755
--- a/tools/deploystatic/deploystatic.py
+++ b/tools/deploystatic/deploystatic.py
@@ -25,6 +25,7 @@ import markdown
from datetime import datetime, date, time
import dateutil.parser
+
#
# Some useful filters. We include them inline in this file to make it
# standalone useful.
@@ -35,6 +36,7 @@ def filter_groupby_sort(objects, keyfield, sortkey):
group = [(key, list(group)) for key, group in groupby(objects, lambda x: getattr(x, keyfield))]
return sorted(group, key=lambda y: y[0] and getattr(y[0], sortkey) or None)
+
# Shuffle the order in a list, for example to randomize the order of sponsors
def filter_shuffle(l):
try:
@@ -44,6 +46,7 @@ def filter_shuffle(l):
except:
return l
+
# Format a datetime. If it's a datetime, call strftime. If it's a
# string, assume it's iso format and convert it to a date first.
def filter_datetimeformat(value, fmt):
@@ -52,6 +55,7 @@ def filter_datetimeformat(value, fmt):
else:
return dateutil.parser.parse(value).strftime(fmt)
+
# Slugify a text
def filter_slugify(value):
if not value:
@@ -60,6 +64,7 @@ def filter_slugify(value):
value = re.sub(r'[^\w\s-]', '', value).strip().lower()
return re.sub(r'[-\s]+', '-', value)
+
global_filters = {
'groupby_sort': filter_groupby_sort,
'shuffle': filter_shuffle,
@@ -69,7 +74,6 @@ global_filters = {
}
-
# Wrap operations on a generic directory
class SourceWrapper(object):
def __init__(self, root):
@@ -100,6 +104,7 @@ class SourceWrapper(object):
else:
return None
+
# Wrap operations on a tarfile
class TarWrapper(object):
def __init__(self, tarstream):
@@ -157,6 +162,7 @@ class JinjaTarLoader(jinja2.BaseLoader):
return (self.tarwrapper.readfile(t).decode('utf8'), None, None)
raise jinja2.TemplateNotFound(template)
+
# Optionally load a JSON context
def load_context(jsondata):
if jsondata:
@@ -164,6 +170,7 @@ def load_context(jsondata):
else:
return {}
+
# Locate which git revision we're on
def find_git_revision(path):
while path != '/':
@@ -185,6 +192,7 @@ def find_git_revision(path):
path = os.path.dirname(path)
return None
+
# Actual deployment function
def deploy_template(env, template, destfile, context):
t = env.get_template(template)
@@ -199,6 +207,7 @@ def deploy_template(env, template, destfile, context):
with open(destfile, 'w') as f:
f.write(s)
+
def _deploy_static(source, destpath):
knownfiles = []
# We could use copytree(), but we need to know which files are there so we can
@@ -234,6 +243,7 @@ def remove_unknown(knownfiles, destpath):
# in it.
shutil.rmtree(os.path.join(destpath, d))
+
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Deploy jinja based static site')
parser.add_argument('sourcepath', type=str, help='Source path')
@@ -278,7 +288,6 @@ if __name__ == "__main__":
print "'{0}' subdirectory does not exist in source!".format(d)
sys.exit(1)
-
if args.templates:
# Just deploy templates. They are simply copied over, for use by backend
# system.
@@ -320,7 +329,6 @@ if __name__ == "__main__":
# Load a context that can override everything, including static hashes
context.update(load_context(source.readfile('templates/context.override.json')))
-
knownfiles = []
knownfiles = _deploy_static(source, args.destpath)