Skip to content

Commit 55ce545

Browse files
rhttimabbott
authored andcommitted
Apply Black but skip string normalization.
1 parent b9a1583 commit 55ce545

File tree

11 files changed

+362
-222
lines changed

11 files changed

+362
-222
lines changed

archive.py

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,45 +28,42 @@
2828
#
2929

3030
import sys
31-
if sys.version_info < (3,6):
31+
32+
if sys.version_info < (3, 6):
3233
version_error = " Python version must be 3.6 or higher\n\
3334
Your current version of python is {}.{}\n\
34-
Please try again with python3.".format(sys.version_info.major,sys.version_info.minor)
35+
Please try again with python3.".format(
36+
sys.version_info.major, sys.version_info.minor
37+
)
3538
raise Exception(version_error)
3639
import argparse
3740
import configparser
3841
import os
3942
import zulip
4043

41-
from lib.common import (
42-
stream_validator,
43-
exit_immediately
44-
)
44+
from lib.common import stream_validator, exit_immediately
4545

4646
# Most of the heavy lifting is done by the following modules:
4747

48-
from lib.populate import (
49-
populate_all,
50-
populate_incremental
51-
)
48+
from lib.populate import populate_all, populate_incremental
5249

53-
from lib.website import (
54-
build_website
55-
)
50+
from lib.website import build_website
5651

5752
try:
5853
import settings
5954
except ModuleNotFoundError:
6055
# TODO: Add better instructions.
61-
exit_immediately('''
56+
exit_immediately(
57+
'''
6258
We can't find settings.py.
6359
6460
Please copy default_settings.py to settings.py
6561
and then edit the settings.py file to fit your use case.
6662
6763
For testing, you can often leave the default settings,
6864
but you will still want to review them first.
69-
''')
65+
'''
66+
)
7067

7168
NO_JSON_DIR_ERROR_WRITE = '''
7269
We cannot find a place to write JSON files.
@@ -93,6 +90,7 @@
9390
9491
mkdir {}'''
9592

93+
9694
def get_json_directory(for_writing):
9795
json_dir = settings.json_directory
9896

@@ -111,6 +109,7 @@ def get_json_directory(for_writing):
111109

112110
return settings.json_directory
113111

112+
114113
def get_html_directory():
115114
html_dir = settings.html_directory
116115

@@ -124,6 +123,7 @@ def get_html_directory():
124123

125124
return settings.html_directory
126125

126+
127127
def get_client_info():
128128
config_file = './zuliprc'
129129
client = zulip.Client(config_file=config_file)
@@ -137,11 +137,23 @@ def get_client_info():
137137

138138
return client, zulip_url
139139

140+
140141
def run():
141-
parser = argparse.ArgumentParser(description='Build an html archive of the Zulip chat.')
142-
parser.add_argument('-b', action='store_true', default=False, help='Build .md files')
143-
parser.add_argument('-t', action='store_true', default=False, help='Make a clean json archive')
144-
parser.add_argument('-i', action='store_true', default=False, help='Incrementally update the json archive')
142+
parser = argparse.ArgumentParser(
143+
description='Build an html archive of the Zulip chat.'
144+
)
145+
parser.add_argument(
146+
'-b', action='store_true', default=False, help='Build .md files'
147+
)
148+
parser.add_argument(
149+
'-t', action='store_true', default=False, help='Make a clean json archive'
150+
)
151+
parser.add_argument(
152+
'-i',
153+
action='store_true',
154+
default=False,
155+
help='Incrementally update the json archive',
156+
)
145157

146158
results = parser.parse_args()
147159

@@ -172,14 +184,14 @@ def run():
172184
client,
173185
json_root,
174186
is_valid_stream_name,
175-
)
187+
)
176188

177189
elif results.i:
178190
populate_incremental(
179191
client,
180192
json_root,
181193
is_valid_stream_name,
182-
)
194+
)
183195

184196
if results.b:
185197
build_website(
@@ -193,7 +205,8 @@ def run():
193205
repo_root,
194206
settings.page_head_html,
195207
settings.page_footer_html,
196-
)
208+
)
209+
197210

198211
if __name__ == '__main__':
199212
run()

default_settings.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,22 @@
8383
try:
8484
html_directory = Path(os.getenv("HTML_DIRECTORY", None))
8585
except TypeError:
86-
raise Exception('''
86+
raise Exception(
87+
'''
8788
You need to set html_directory for prod, and it
8889
should be a different location than DEBUG mode,
8990
since files will likely have different urls in
9091
anchor tags.
91-
''')
92+
'''
93+
)
9294

9395

9496
'''
9597
This is where you modify the <head> section of every page.
9698
'''
97-
page_head_html = '<html>\n<head><meta charset="utf-8"><title>Zulip Chat Archive</title></head>\n'
99+
page_head_html = (
100+
'<html>\n<head><meta charset="utf-8"><title>Zulip Chat Archive</title></head>\n'
101+
)
98102

99103
'''
100104
This is where you modify the <footer> section of every page.
@@ -143,7 +147,9 @@
143147
with open("streams.yaml") as f:
144148
streams = yaml.load(f, Loader=yaml.BaseLoader)
145149
if "included" not in streams or not streams["included"]:
146-
raise Exception("Please specify the streams to be included under `included` section in streams.yaml file")
150+
raise Exception(
151+
"Please specify the streams to be included under `included` section in streams.yaml file"
152+
)
147153
included_streams = streams["included"]
148154

149155
excluded_streams = []

github.py

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,40 @@
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']))
22+
2223

2324
# commits changes in archive/ and pushes the current repository to origin/master
2425
def github_push():
25-
print(subprocess.check_output(['git','add','archive/*']))
26-
print(subprocess.check_output(['git','add','_includes/archive_update.html']))
27-
print(subprocess.check_output(['git','commit','-m','auto update: {}'.format(datetime.utcfromtimestamp(time.time()).strftime('%b %d %Y at %H:%M UTC'))]))
28-
print(subprocess.check_output(['git','push']))
29-
30-
parser.add_argument('-f', action='store_true', default=False, help='Pull from GitHub before updating. (Warning: could overwrite this script.)')
31-
parser.add_argument('-p', action='store_true', default=False, help='Push results to GitHub.')
26+
print(subprocess.check_output(['git', 'add', 'archive/*']))
27+
print(subprocess.check_output(['git', 'add', '_includes/archive_update.html']))
28+
print(
29+
subprocess.check_output(
30+
[
31+
'git',
32+
'commit',
33+
'-m',
34+
'auto update: {}'.format(
35+
datetime.utcfromtimestamp(time.time()).strftime(
36+
'%b %d %Y at %H:%M UTC'
37+
)
38+
),
39+
]
40+
)
41+
)
42+
print(subprocess.check_output(['git', 'push']))
43+
44+
45+
parser.add_argument(
46+
'-f',
47+
action='store_true',
48+
default=False,
49+
help='Pull from GitHub before updating. (Warning: could overwrite this script.)',
50+
)
51+
parser.add_argument(
52+
'-p', action='store_true', default=False, help='Push results to GitHub.'
53+
)
3254

3355
if results.f:
3456
github_pull()

lib/common.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import os
22

3+
34
def exit_immediately(s):
45
print('\nERROR\n', s)
56
exit(1)
67

8+
79
# Safely open dir/filename, creating dir if it doesn't exist
810
def open_outfile(dir, filename, mode):
911
if not dir.exists():
1012
os.makedirs(str(dir))
1113
return (dir / filename).open(mode, encoding='utf-8')
1214

15+
1316
def stream_validator(settings):
1417
if not hasattr(settings, 'included_streams'):
1518
exit_immediately('Please set included_streams.')

lib/files.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,47 +62,51 @@
6262

6363
from .common import open_outfile
6464

65+
6566
def read_zulip_stream_info(json_root):
66-
'''
67+
"""
6768
stream_index.json
6869
6970
This JSON goes two levels deep, showing every stream, and
7071
then within each stream, a bit of info for every topic in
7172
the stream. To get actual messages within a topic, you go
7273
to other files deeper in the directory structure.
73-
'''
74+
"""
7475
f = (json_root / Path('stream_index.json')).open('r', encoding='utf-8')
7576
stream_info = json.load(f, encoding='utf-8')
7677
f.close()
7778
return stream_info
7879

80+
7981
def read_zulip_messages_for_topic(
80-
json_root,
81-
sanitized_stream_name,
82-
sanitized_topic_name
83-
):
84-
'''
82+
json_root, sanitized_stream_name, sanitized_topic_name
83+
):
84+
"""
8585
<stream>/<topic>.json
8686
8787
This JSON has info for all the messags in a topic.
88-
'''
89-
json_path = json_root / Path(sanitized_stream_name) / Path (sanitized_topic_name + '.json')
88+
"""
89+
json_path = (
90+
json_root / Path(sanitized_stream_name) / Path(sanitized_topic_name + '.json')
91+
)
9092
f = json_path.open('r', encoding='utf-8')
9193
messages = json.load(f)
9294
f.close()
9395
return messages
9496

97+
9598
def open_main_page(md_root):
9699
outfile = open_outfile(md_root, Path('index.html'), 'w+')
97100
return outfile
98101

102+
99103
def open_stream_topics_page(md_root, sanitized_stream_name):
100-
directory = md_root / Path('stream/'+sanitized_stream_name)
104+
directory = md_root / Path('stream/' + sanitized_stream_name)
101105
outfile = open_outfile(directory, Path('index.html'), 'w+')
102106
return outfile
103107

108+
104109
def open_topic_messages_page(md_root, sanitized_stream_name, sanitized_topic_name):
105-
directory = md_root / Path('stream/'+sanitized_stream_name+'/topic')
110+
directory = md_root / Path('stream/' + sanitized_stream_name + '/topic')
106111
outfile = open_outfile(directory, Path(sanitized_topic_name + '.html'), 'w+')
107112
return outfile
108-

0 commit comments

Comments
 (0)