insert to existing conf
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
import hashlib,argparse,json,sys
|
||||
from datetime import datetime
|
||||
from shutil import copyfile
|
||||
|
||||
parser = argparse.ArgumentParser(description='Flees share template generator')
|
||||
|
||||
parser.add_argument('-n','--name', action="store", dest="name", required = True)
|
||||
@@ -10,6 +12,10 @@ parser.add_argument('-u','--upload', action="store_true", dest="upload", default
|
||||
parser.add_argument('--pass-plain', action="store", dest="plain", default = False)
|
||||
parser.add_argument('--pass-hashed', action="store", dest="hashed", default = False)
|
||||
parser.add_argument('-e','--expire', action="store", dest="expire", default = False, help = "expire date in format 2018-12-24 21:00")
|
||||
parser.add_argument('-s','--shares', action="store", dest="shares", default = False,
|
||||
help = "Your current shares.json file")
|
||||
parser.add_argument('-i','--insert', action="store_true", dest="insert", default = False,
|
||||
help = "If 'shares' defined, insert new share directly in the shares.json file")
|
||||
|
||||
opts = parser.parse_args()
|
||||
|
||||
@@ -37,7 +43,18 @@ if opts.expire:
|
||||
'expire': opts.expire
|
||||
})
|
||||
|
||||
|
||||
print(json.dumps(share, indent = 2))
|
||||
if opts.shares:
|
||||
shares = json.load(open(opts.shares,'rt'))
|
||||
shares.append(share)
|
||||
if opts.insert:
|
||||
print("creating backup %s"%(opts.shares+".bkp",))
|
||||
copyfile(opts.shares,opts.shares+".bkp")
|
||||
with open(opts.shares,'wt') as fp:
|
||||
json.dump(shares, fp, indent = 2, sort_keys = True)
|
||||
print("Wrote file %s"%(opts.shares,))
|
||||
else:
|
||||
print(json.dumps(shares, indent = 2, sort_keys = True))
|
||||
else:
|
||||
print(json.dumps(share, indent = 2, sort_keys = True))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user