Skip to content

Commit 371fe06

Browse files
committed
[app.py] source file formatting updates
1 parent 75183b0 commit 371fe06

File tree

1 file changed

+62
-27
lines changed

1 file changed

+62
-27
lines changed

lib/fontv/app.py

Lines changed: 62 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ def main():
2929
c = Command()
3030

3131
if c.does_not_validate_missing_args():
32-
sys.stderr.write("[font-v] ERROR: Please include a subcommand and appropriate optional arguments in "
33-
"your command." + os.linesep)
32+
sys.stderr.write(
33+
"[font-v] ERROR: Please include a subcommand and appropriate optional arguments in "
34+
"your command." + os.linesep
35+
)
3436
sys.exit(1)
3537

3638
if c.is_help_request():
@@ -46,8 +48,10 @@ def main():
4648
if c.subcmd == "report":
4749
# argument test
4850
if c.argc < 2:
49-
sys.stderr.write("[font-v] ERROR: Command is missing necessary arguments. Check "
50-
"`font-v --help`." + os.linesep)
51+
sys.stderr.write(
52+
"[font-v] ERROR: Command is missing necessary arguments. Check "
53+
"`font-v --help`." + os.linesep
54+
)
5155
sys.exit(1)
5256

5357
for arg in c.argv[1:]:
@@ -57,7 +61,8 @@ def main():
5761
fv = FontVersion(font_path)
5862
print(os.linesep + fv.fontpath + ":")
5963
print("----- name.ID = 5:")
60-
if "--dev" in c.argv: # --dev switch report prints every version string in name records
64+
# --dev switch report prints every version string in name records
65+
if "--dev" in c.argv:
6166
for record, v_string in fv.name_ID5_dict.items():
6267
devstring = str(record) + ":" + os.linesep + str(v_string)
6368
print(devstring)
@@ -67,27 +72,36 @@ def main():
6772
head_fontrevision = fv.get_head_fontrevision_version_number()
6873
print("{:.3f}".format(head_fontrevision))
6974
else:
70-
sys.stderr.write("[font-v] ERROR: " + font_path + " does not appear to be a valid ttf "
71-
"or otf font file path." + os.linesep)
75+
sys.stderr.write(
76+
"[font-v] ERROR: "
77+
+ font_path
78+
+ " does not appear to be a valid ttf "
79+
"or otf font file path." + os.linesep
80+
)
7281
sys.exit(1)
7382
elif c.subcmd == "write":
7483
# argument test
7584
if c.argc < 2:
76-
sys.stderr.write("[font-v] ERROR: Command is missing necessary arguments. "
77-
"Check `font-v --help`." + os.linesep)
85+
sys.stderr.write(
86+
"[font-v] ERROR: Command is missing necessary arguments. "
87+
"Check `font-v --help`." + os.linesep
88+
)
7889
sys.exit(1)
7990

8091
# argument parsing flags
8192
add_sha1 = False
8293
add_release_string = False
8394
add_dev_string = False
8495
add_new_version = False
85-
fontpath_list = [] # list of font paths that user submits on command line
96+
fontpath_list = [] # list of font paths that user submits on command line
8697

8798
# test for mutually exclusive arguments
8899
# do not refactor this below the level of the argument tests that follow
89100
if "--rel" in c.argv and "--dev" in c.argv:
90-
sys.stderr.write("[font-v] ERROR: Please use either --dev or --rel argument, not both." + os.linesep)
101+
sys.stderr.write(
102+
"[font-v] ERROR: Please use either --dev or --rel argument, not both."
103+
+ os.linesep
104+
)
91105
sys.exit(1)
92106

93107
# Parse command line arguments to determine user request(s)
@@ -100,33 +114,49 @@ def main():
100114
add_dev_string = True
101115
elif arg[0:6] == "--ver=":
102116
add_new_version = True
103-
version_list = arg.split("=") # split on the = symbol and use second part as definition
117+
# split on the = symbol and use second part as definition
118+
version_list = arg.split("=")
104119
if len(version_list) < 2:
105-
sys.stderr.write("[font-v] ERROR: --ver=version argument does not have a valid definition"
106-
" in your command." + os.linesep)
120+
sys.stderr.write(
121+
"[font-v] ERROR: --ver=version argument does not have a valid definition"
122+
" in your command." + os.linesep
123+
)
107124
sys.exit(1)
108125
# use fonttools library to cast terminal input from user to fontTools.misc.py23.unicode type (imported)
109126
# this will be Python 3 str object and Python 2 unicode object
110127
# try to cast to this type and catch decoding exceptions, handle with error message to user.
111128
try:
112-
version_pre = tounicode(version_list[1], encoding='ascii')
129+
version_pre = tounicode(version_list[1], encoding="ascii")
113130
except UnicodeDecodeError as e:
114-
sys.stderr.write("[font-v] ERROR: You appear to have entered a non ASCII character in your"
115-
"version string. Please try again." + os.linesep)
131+
sys.stderr.write(
132+
"[font-v] ERROR: You appear to have entered a non ASCII character in your"
133+
"version string. Please try again." + os.linesep
134+
)
116135
sys.stderr.write("[fontTools library]: error message: " + str(e))
117136
sys.exit(1)
118137

119-
version_pre = version_pre.replace("-", ".") # specified on command line as 1-000
120-
version_final = version_pre.replace("_", ".") # or as 1_000
121-
elif len(arg) > 4 and (arg[-4:].lower() == ".ttf" or arg[-4:].lower() == ".otf"):
138+
version_pre = version_pre.replace(
139+
"-", "."
140+
) # specified on command line as 1-000
141+
version_final = version_pre.replace("_", ".") # or as 1_000
142+
elif len(arg) > 4 and (
143+
arg[-4:].lower() == ".ttf" or arg[-4:].lower() == ".otf"
144+
):
122145
if file_exists(arg):
123146
fontpath_list.append(arg)
124147
else:
125-
sys.stderr.write("[font-v] ERROR: " + arg + " does not appear to be a valid "
126-
"font file path." + os.linesep)
148+
sys.stderr.write(
149+
"[font-v] ERROR: " + arg + " does not appear to be a valid "
150+
"font file path." + os.linesep
151+
)
127152
sys.exit(1)
128153

129-
if add_sha1 is False and add_release_string is False and add_dev_string is False and add_new_version is False:
154+
if (
155+
add_sha1 is False
156+
and add_release_string is False
157+
and add_dev_string is False
158+
and add_new_version is False
159+
):
130160
print("[font-v] No changes specified. Nothing to do.")
131161
sys.exit(0)
132162

@@ -154,12 +184,17 @@ def main():
154184

155185
fv.write_version_string()
156186

157-
print("[✓] " + fontpath + " version string was successfully changed "
158-
"to:" + os.linesep + fv.get_name_id5_version_string() + os.linesep)
187+
print(
188+
"[✓] " + fontpath + " version string was successfully changed "
189+
"to:" + os.linesep + fv.get_name_id5_version_string() + os.linesep
190+
)
159191
else: # user did not enter an acceptable subcommand
160-
sys.stderr.write("[font-v] ERROR: Please enter a font-v subcommand with your request." + os.linesep)
192+
sys.stderr.write(
193+
"[font-v] ERROR: Please enter a font-v subcommand with your request."
194+
+ os.linesep
195+
)
161196
sys.exit(1)
162197

163198

164-
if __name__ == '__main__':
199+
if __name__ == "__main__":
165200
main()

0 commit comments

Comments
 (0)