Skip to content

Commit 1c9d1b1

Browse files
committed
code beautification with black --line-length 150
1 parent d1003c5 commit 1c9d1b1

4 files changed

Lines changed: 367 additions & 237 deletions

File tree

jdata/__init__.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,25 @@
3636
from .jfile import load, save, show, loadt, savet, loadb, saveb, jext
3737
from .jdata import encode, decode, jdtype, jsonfilter
3838

39-
__version__ = '0.4.4'
40-
__all__ = ['load','save','show','loadt', 'savet', 'loadb', 'saveb','encode', 'decode', 'jdtype','jsonfilter','jext']
39+
__version__ = "0.4.4"
40+
__all__ = [
41+
"load",
42+
"save",
43+
"show",
44+
"loadt",
45+
"savet",
46+
"loadb",
47+
"saveb",
48+
"encode",
49+
"decode",
50+
"jdtype",
51+
"jsonfilter",
52+
"jext",
53+
]
4154
__license__ = """Apache license 2.0, Copyright (c) 2019-2022 Qianqian Fang"""
4255

4356

44-
if __name__ == '__main__':
57+
if __name__ == "__main__":
4558
import cmd
59+
4660
cmd.main()

jdata/__main__.py

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,61 +21,77 @@ def main():
2121
# get arguments and invoke the conversion routines
2222
#
2323

24-
parser = argparse.ArgumentParser(
25-
description='Convert a text JSON/JData file to a binary JSON/JData file and vice versa.')
24+
parser = argparse.ArgumentParser(description="Convert a text JSON/JData file to a binary JSON/JData file and vice versa.")
2625

2726
parser.add_argument(
28-
'file', nargs='+',
29-
help='path to a text-JData (json/jdt/jnii/jmsh/jnirs) file or a binary JData (bjd/jdb/bnii/bmsh/bnirs) file')
27+
"file",
28+
nargs="+",
29+
help="path to a text-JData (json/jdt/jnii/jmsh/jnirs) file or a binary JData (bjd/jdb/bnii/bmsh/bnirs) file",
30+
)
3031
parser.add_argument(
31-
'-f', '--force', action='store_const', const=True,
32-
default=False, help='overwrite existing files when converting')
32+
"-f",
33+
"--force",
34+
action="store_const",
35+
const=True,
36+
default=False,
37+
help="overwrite existing files when converting",
38+
)
3339
parser.add_argument(
34-
'-r', '--remove_input', action='store_const', const=True,
35-
default=False, help='delete the input file name after conversion')
40+
"-r",
41+
"--remove_input",
42+
action="store_const",
43+
const=True,
44+
default=False,
45+
help="delete the input file name after conversion",
46+
)
3647
parser.add_argument(
37-
'-c', '--compression', default="", help='set compression method (zlib,gzip,lzma,lz4)')
48+
"-c",
49+
"--compression",
50+
default="",
51+
help="set compression method (zlib,gzip,lzma,lz4)",
52+
)
3853

3954
args = parser.parse_args()
4055

4156
for path in args.file:
4257
spl = os.path.splitext(path)
4358
ext = spl[1].lower()
4459

45-
if(ext in jext['t']):
46-
dest = spl[0] + '.jdb'
60+
if ext in jext["t"]:
61+
dest = spl[0] + ".jdb"
4762
try:
4863
if os.path.exists(dest) and not args.force:
49-
raise Exception('File {} already exists.'.format(dest))
64+
raise Exception("File {} already exists.".format(dest))
5065
data = load(path)
51-
if(len(args.compression)>0):
52-
save(data,dest,{'compression':args.compression})
66+
if len(args.compression) > 0:
67+
save(data, dest, {"compression": args.compression})
5368
else:
54-
save(data,dest)
69+
save(data, dest)
5570
if args.remove_input:
5671
os.remove(path)
5772
except Exception as e:
58-
print('Error: {}'.format(e))
73+
print("Error: {}".format(e))
5974
sys.exit(1)
6075

61-
elif(ext in jext['b']):
62-
dest = spl[0] + '.json'
76+
elif ext in jext["b"]:
77+
dest = spl[0] + ".json"
6378
try:
6479
if os.path.exists(dest) and not args.force:
65-
raise Exception('File {} already exists.'.format(dest))
80+
raise Exception("File {} already exists.".format(dest))
6681
data = load(path)
67-
if(len(args.compression)>0):
68-
save(data,dest,{'compression':args.compression})
82+
if len(args.compression) > 0:
83+
save(data, dest, {"compression": args.compression})
6984
else:
70-
save(data,dest)
85+
save(data, dest)
7186
if args.remove_input:
7287
os.remove(path)
7388
except RuntimeError as e:
74-
print('Error: {}'.format(e))
89+
print("Error: {}".format(e))
7590
sys.exit(1)
7691
else:
77-
print('Unsupported file extension on file: {}'.format(path))
92+
print("Unsupported file extension on file: {}".format(path))
7893
sys.exit(1)
7994

80-
if __name__ == '__main__':
95+
96+
if __name__ == "__main__":
8197
main()

0 commit comments

Comments
 (0)