Skip to content

Commit 525c5fd

Browse files
rhttimabbott
authored andcommitted
Apply Black with string normalization.
1 parent 55ce545 commit 525c5fd

File tree

12 files changed

+227
-227
lines changed

12 files changed

+227
-227
lines changed

archive.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22

3-
'''
3+
"""
44
This is the main program for the Zulip archive system. For help:
55
66
python archive.py -h
@@ -15,7 +15,7 @@
1515
1616
lib/html.py
1717
lib/populate.py
18-
'''
18+
"""
1919

2020

2121
# The workflow (timing for the leanprover Zulip chat, on my slow laptop):
@@ -54,25 +54,25 @@
5454
except ModuleNotFoundError:
5555
# TODO: Add better instructions.
5656
exit_immediately(
57-
'''
57+
"""
5858
We can't find settings.py.
5959
6060
Please copy default_settings.py to settings.py
6161
and then edit the settings.py file to fit your use case.
6262
6363
For testing, you can often leave the default settings,
6464
but you will still want to review them first.
65-
'''
65+
"""
6666
)
6767

68-
NO_JSON_DIR_ERROR_WRITE = '''
68+
NO_JSON_DIR_ERROR_WRITE = """
6969
We cannot find a place to write JSON files.
7070
7171
Please run the below command:
7272
73-
mkdir {}'''
73+
mkdir {}"""
7474

75-
NO_JSON_DIR_ERROR_READ = '''
75+
NO_JSON_DIR_ERROR_READ = """
7676
We cannot find a place to read JSON files.
7777
7878
Please run the below command:
@@ -81,14 +81,14 @@
8181
8282
And then fetch the JSON:
8383
84-
python archive.py -t'''
84+
python archive.py -t"""
8585

86-
NO_HTML_DIR_ERROR = '''
86+
NO_HTML_DIR_ERROR = """
8787
We cannot find a place to write HTML files.
8888
8989
Please run the below command:
9090
91-
mkdir {}'''
91+
mkdir {}"""
9292

9393

9494
def get_json_directory(for_writing):
@@ -105,7 +105,7 @@ def get_json_directory(for_writing):
105105
exit_immediately(error_msg)
106106

107107
if not json_dir.is_dir():
108-
exit_immediately(str(json_dir) + ' needs to be a directory')
108+
exit_immediately(str(json_dir) + " needs to be a directory")
109109

110110
return settings.json_directory
111111

@@ -119,50 +119,50 @@ def get_html_directory():
119119
exit_immediately(error_msg)
120120

121121
if not html_dir.is_dir():
122-
exit_immediately(str(html_dir) + ' needs to be a directory')
122+
exit_immediately(str(html_dir) + " needs to be a directory")
123123

124124
return settings.html_directory
125125

126126

127127
def get_client_info():
128-
config_file = './zuliprc'
128+
config_file = "./zuliprc"
129129
client = zulip.Client(config_file=config_file)
130130

131131
# It would be convenient if the Zulip client object
132132
# had a `site` field, but instead I just re-read the file
133133
# directly to get it.
134134
config = configparser.RawConfigParser()
135135
config.read(config_file)
136-
zulip_url = config.get('api', 'site')
136+
zulip_url = config.get("api", "site")
137137

138138
return client, zulip_url
139139

140140

141141
def run():
142142
parser = argparse.ArgumentParser(
143-
description='Build an html archive of the Zulip chat.'
143+
description="Build an html archive of the Zulip chat."
144144
)
145145
parser.add_argument(
146-
'-b', action='store_true', default=False, help='Build .md files'
146+
"-b", action="store_true", default=False, help="Build .md files"
147147
)
148148
parser.add_argument(
149-
'-t', action='store_true', default=False, help='Make a clean json archive'
149+
"-t", action="store_true", default=False, help="Make a clean json archive"
150150
)
151151
parser.add_argument(
152-
'-i',
153-
action='store_true',
152+
"-i",
153+
action="store_true",
154154
default=False,
155-
help='Incrementally update the json archive',
155+
help="Incrementally update the json archive",
156156
)
157157

158158
results = parser.parse_args()
159159

160160
if results.t and results.i:
161-
print('Cannot perform both a total and incremental update. Use -t or -i.')
161+
print("Cannot perform both a total and incremental update. Use -t or -i.")
162162
exit(1)
163163

164164
if not (results.t or results.i or results.b):
165-
print('\nERROR!\n\nYou have not specified any work to do.\n')
165+
print("\nERROR!\n\nYou have not specified any work to do.\n")
166166
parser.print_help()
167167
exit(1)
168168

@@ -208,5 +208,5 @@ def run():
208208
)
209209

210210

211-
if __name__ == '__main__':
211+
if __name__ == "__main__":
212212
run()

default_settings.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,56 +12,56 @@
1212
import yaml
1313
from pathlib import Path
1414

15-
'''
15+
"""
1616
You generally want to start in debug mode to test out the archive,
1717
and then set PROD_ARCHIVE to turn on production settings here. In
1818
production you usually change two things--the site_url and your
1919
html_directory.
20-
'''
20+
"""
2121

22-
if os.getenv('PROD_ARCHIVE'):
22+
if os.getenv("PROD_ARCHIVE"):
2323
DEBUG = False
2424
else:
2525
DEBUG = True
2626

27-
'''
27+
"""
2828
Set the site url. The default below is good for local testing, but you will
2929
definitely need to set your own value for prod.
30-
'''
30+
"""
3131

3232
if DEBUG:
33-
site_url = 'http://127.0.0.1:4000'
33+
site_url = "http://127.0.0.1:4000"
3434
else:
35-
site_url = os.getenv('SITE_URL')
35+
site_url = os.getenv("SITE_URL")
3636
if not site_url:
3737
raise Exception("You need to configure site_url for prod")
3838

39-
'''
39+
"""
4040
Set the zulip icon url. Folks can press the icon to see a
4141
message in the actual Zulip instance.
42-
'''
42+
"""
4343

4444
if DEBUG:
45-
zulip_icon_url = 'http://127.0.0.1:4000/assets/img/zulip.svg'
45+
zulip_icon_url = "http://127.0.0.1:4000/assets/img/zulip.svg"
4646
else:
4747
# Set this according to how you serve your prod assets.
4848
zulip_icon_url = os.getenv("ZULIP_ICON_URL", None)
4949

5050

51-
'''
51+
"""
5252
Set the HTML title of your Zulip archive here.
53-
'''
54-
title = 'Zulip Chat Archive' # Modify me!
53+
"""
54+
title = "Zulip Chat Archive" # Modify me!
5555

56-
'''
56+
"""
5757
Set the path prefix of your URLs for your website.
5858
5959
For example, you might want your main page to have
6060
the path of archive/index.html
61-
'''
61+
"""
6262
html_root = os.getenv("HTML_ROOT", "archive") # Modify me!
6363

64-
'''
64+
"""
6565
When we get content from your Zulip instance, we first create
6666
JSON files that include all of the content data from the Zulip
6767
instance. Having the data in JSON makes it easy to incrementally
@@ -70,43 +70,43 @@
7070
You will want to put this in a permanent location outside of
7171
your repo. Here we assume a sibling directory named zulip_json, but
7272
you may prefer another directory structure.
73-
'''
73+
"""
7474

7575
json_directory = Path(os.getenv("JSON_DIRECTORY", "../zulip_json"))
7676

77-
'''
77+
"""
7878
We write HTML to here.
79-
'''
79+
"""
8080
if DEBUG:
81-
html_directory = Path('./archive') # Modify me!
81+
html_directory = Path("./archive") # Modify me!
8282
else:
8383
try:
8484
html_directory = Path(os.getenv("HTML_DIRECTORY", None))
8585
except TypeError:
8686
raise Exception(
87-
'''
87+
"""
8888
You need to set html_directory for prod, and it
8989
should be a different location than DEBUG mode,
9090
since files will likely have different urls in
9191
anchor tags.
92-
'''
92+
"""
9393
)
9494

9595

96-
'''
96+
"""
9797
This is where you modify the <head> section of every page.
98-
'''
98+
"""
9999
page_head_html = (
100100
'<html>\n<head><meta charset="utf-8"><title>Zulip Chat Archive</title></head>\n'
101101
)
102102

103-
'''
103+
"""
104104
This is where you modify the <footer> section of every page.
105-
'''
106-
page_footer_html = '\n</html>'
105+
"""
106+
page_footer_html = "\n</html>"
107107

108108

109-
'''
109+
"""
110110
You may only want to include certain streams. In `streams.yaml`
111111
file, mention the streams you want to include under `included` section.
112112
@@ -141,7 +141,7 @@
141141
- checkins
142142
- development help
143143
144-
'''
144+
"""
145145

146146
try:
147147
with open("streams.yaml") as f:

github.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,43 @@
1313
from datetime import datetime
1414
import time, argparse, subprocess
1515

16-
parser = argparse.ArgumentParser(description='Push/pull repo.')
16+
parser = argparse.ArgumentParser(description="Push/pull repo.")
1717

1818
# resets the current repository to match origin/master
1919
def github_pull():
20-
print(subprocess.check_output(['git', 'fetch', 'origin', 'master']))
21-
print(subprocess.check_output(['git', 'reset', '--hard', 'origin/master']))
20+
print(subprocess.check_output(["git", "fetch", "origin", "master"]))
21+
print(subprocess.check_output(["git", "reset", "--hard", "origin/master"]))
2222

2323

2424
# commits changes in archive/ and pushes the current repository to origin/master
2525
def github_push():
26-
print(subprocess.check_output(['git', 'add', 'archive/*']))
27-
print(subprocess.check_output(['git', 'add', '_includes/archive_update.html']))
26+
print(subprocess.check_output(["git", "add", "archive/*"]))
27+
print(subprocess.check_output(["git", "add", "_includes/archive_update.html"]))
2828
print(
2929
subprocess.check_output(
3030
[
31-
'git',
32-
'commit',
33-
'-m',
34-
'auto update: {}'.format(
31+
"git",
32+
"commit",
33+
"-m",
34+
"auto update: {}".format(
3535
datetime.utcfromtimestamp(time.time()).strftime(
36-
'%b %d %Y at %H:%M UTC'
36+
"%b %d %Y at %H:%M UTC"
3737
)
3838
),
3939
]
4040
)
4141
)
42-
print(subprocess.check_output(['git', 'push']))
42+
print(subprocess.check_output(["git", "push"]))
4343

4444

4545
parser.add_argument(
46-
'-f',
47-
action='store_true',
46+
"-f",
47+
action="store_true",
4848
default=False,
49-
help='Pull from GitHub before updating. (Warning: could overwrite this script.)',
49+
help="Pull from GitHub before updating. (Warning: could overwrite this script.)",
5050
)
5151
parser.add_argument(
52-
'-p', action='store_true', default=False, help='Push results to GitHub.'
52+
"-p", action="store_true", default=False, help="Push results to GitHub."
5353
)
5454

5555
if results.f:

lib/common.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22

33

44
def exit_immediately(s):
5-
print('\nERROR\n', s)
5+
print("\nERROR\n", s)
66
exit(1)
77

88

99
# Safely open dir/filename, creating dir if it doesn't exist
1010
def open_outfile(dir, filename, mode):
1111
if not dir.exists():
1212
os.makedirs(str(dir))
13-
return (dir / filename).open(mode, encoding='utf-8')
13+
return (dir / filename).open(mode, encoding="utf-8")
1414

1515

1616
def stream_validator(settings):
17-
if not hasattr(settings, 'included_streams'):
18-
exit_immediately('Please set included_streams.')
17+
if not hasattr(settings, "included_streams"):
18+
exit_immediately("Please set included_streams.")
1919

2020
if len(settings.included_streams) == 0:
2121
exit_immediately('Please add "*" to included_streams.')
2222

23-
if hasattr(settings, 'excluded_streams'):
23+
if hasattr(settings, "excluded_streams"):
2424
excluded_streams = set(settings.excluded_streams)
2525
else:
2626
excluded_streams = set()
@@ -31,7 +31,7 @@ def validator(stream):
3131
if stream in excluded_streams:
3232
return False
3333

34-
if '*' in included_streams:
34+
if "*" in included_streams:
3535
return True
3636

3737
return stream in included_streams

lib/date_helper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
# I don't love this format, feel free to change (I just
44
# extracted it from prior code).
55
def format_date1(ts):
6-
''' Nov 05 2019 at 02:51'''
7-
return datetime.utcfromtimestamp(ts).strftime('%b %d %Y at %H:%M')
6+
""" Nov 05 2019 at 02:51"""
7+
return datetime.utcfromtimestamp(ts).strftime("%b %d %Y at %H:%M")

0 commit comments

Comments
 (0)