4 HCE project, Python bindings, DC service utility 5 Batch from json preparation utility. 9 @author bgv <developers.hce@gmail.com> 10 @link: http://hierarchical-cluster-engine.com/ 11 @copyright: Copyright © 2015 IOIX Ukraine 12 @license: http://hierarchical-cluster-engine.com/license/ 24 pr = Profiler.Profiler()
25 if pr
and pr.status > 0:
32 from cement.core
import foundation
38 exit_code = APP_CONSTS.EXIT_FAILURE
40 if __name__ ==
"__main__":
43 app = foundation.CementApp(
'myapp')
45 app.args.add_argument(
'-t',
'--txt', action=
'store', dest=
'txt', help=
'the text file one URL per line')
46 app.args.add_argument(
'-j',
'--json', action=
'store', dest=
'json', help=
'the json file used as the Batch template, if omitted - read stdin')
47 app.args.add_argument(
'-o',
'--out', action=
'store', dest=
'out', help=
'the output json file, if omitted write stdout')
51 with open(app.pargs.txt,
'r') as f: 52 urlsList = f.read().splitlines() 55 with open(app.pargs.json,
'r') as f: 56 batchDict = json.loads(f.read()) 58 batchDict = json.loads(sys.stdin.read())
64 item = copy.deepcopy(batchDict[
'items'][0])
65 item[
'urlObj'][
'url'] = url
66 item[
'urlObj'][
'urlMd5'] = hashlib.md5(url).hexdigest()
67 item[
'urlId'] = item[
'urlObj'][
'urlMd5']
70 batchDict[
'items'] = items
73 with open(out,
'w')
as f:
74 f.write(json.dumps(batchDict))
76 print json.dumps(batchDict)
78 sys.stderr.write(
'Required text file with URLs not provided, use with -h to see required arguments.')
82 except Exception
as err:
83 sys.stderr.write(str(err) +
'\n')
84 exit_code = APP_CONSTS.EXIT_FAILURE
86 exit_code = APP_CONSTS.EXIT_FAILURE