read_raw.py
1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import sys
import os
from configparser import ConfigParser
from argparse import ArgumentParser
help_raw = 'Bisa juga dari file atau stdin'
def get_module_object(name):
module_obj = __import__(name)
sub_obj = None
for sub in name.split('.')[1:]:
sub_obj = getattr(sub_obj or module_obj, sub)
return sub_obj
def get_option(argv):
parser = ArgumentParser()
parser.add_argument('conf')
parser.add_argument('--raw', help=help_raw)
return parser.parse_args(argv)
def main(argv=sys.argv[1:]):
option = get_option(argv)
conf_file = option.conf
conf = ConfigParser()
conf.read(conf_file)
if not option.raw:
lines = sys.stdin.readlines()
if not lines:
print('--raw harus diisi')
print(help_raw)
return
raw = lines[0].rstrip('\n')
raw = raw.encode('utf8')
elif os.path.exists(option.raw):
filename = option.raw
with open(filename, 'rb') as f:
raw = f.read()
raw = raw.rstrip(b'\n')
else:
raw = option.raw.encode('utf8')
module_name = conf.get('main', 'module')
module = get_module_object(module_name)
iso = module.doc.Doc(debug=True)
print([raw])
iso.setIsoContent(raw)