Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,21 @@ def open(name, *a, **kw):
diff.update({b: False for b in remove})
else:
diff = {f: os.path.isfile(f) for f in diff}
deploy_data = {'subreddit': os.getenv('subreddit')}
for image, exists in diff.items():
data = dict(deploy_data)
with open(image) as image_file:
if exists:
data['image_path'] = image
else:
data['name'] = os.path.splitext(
os.path.basename(image_file.name)
)[0]
getattr(
reddit,
"{0}_image".format("upload" if exists else "delete")
)(**data)
for subreddit in os.getenv('subreddit').split('+'):
deploy_data = {'subreddit': subreddit}
for image, exists in diff.items():
Copy link
Copy Markdown
Owner

@13steinj 13steinj Jul 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running for loops consecutively is slow cause CPython isn't a JIT compiler. Do you mind moving things around so the "subreddit" for loop occurs within the diff loop, data initially being an empty dict instead of a copied version of deploydata, and then set 'subreddit' on it within that loop?

E: grammar

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm no saint on this, but any updates? Or if you don't have the time, may I squash and merge?

Copy link
Copy Markdown
Author

@jewel-andraia jewel-andraia Jun 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, go ahead and merge/rework it however you like.

data = dict(deploy_data)
with open(image) as image_file:
if exists:
data['image_path'] = image
else:
data['name'] = os.path.splitext(
os.path.basename(image_file.name)
)[0]
getattr(
reddit,
"{0}_image".format("upload" if exists else "delete")
)(**data)


def deploy(force=ast.literal_eval(os.getenv('force_deploy', 'False'))):
Expand All @@ -79,8 +80,10 @@ def deploy(force=ast.literal_eval(os.getenv('force_deploy', 'False'))):
if update_images or force:
deploy_images(image_diff, r, force)
if update_css or force:
with open(stylesheet, 'r') as css:
r.set_stylesheet(os.getenv('subreddit'), css.read())
with open(stylesheet, 'r') as stylesheet_file:
css = stylesheet_file.read()
for subreddit in os.getenv('subreddit').split('+'):
r.set_stylesheet(subreddit, css)

if __name__ == '__main__':
deploy()