reverse nowrite option

This commit is contained in:
Ville Rantanen
2018-03-02 12:20:23 +02:00
parent 01cfd02679
commit 464a5cc9bb

View File

@@ -87,6 +87,10 @@ def list_folders(shares,config):
def add_share(shares, config, opts): def add_share(shares, config, opts):
# Make name and path safe:
opts.name = opts.name.decode('ascii','replace').replace(u'\uFFFD','_')
opts.path = opts.path.decode('ascii','replace').replace(u'\uFFFD','_')
# check for share name exists already # check for share name exists already
for share in shares: for share in shares:
if share['name'] == opts.name: if share['name'] == opts.name:
@@ -136,7 +140,7 @@ def add_share(shares, config, opts):
print("Add share: %s"%( opts.name, )) print("Add share: %s"%( opts.name, ))
check_login(share, config) check_login(share, config)
else: else:
print("Share not saved anywhere. Save with -w") print("Share not saved anywhere.")
@@ -165,6 +169,9 @@ def check_login(share, config):
def modify_share(shares, config, opts): def modify_share(shares, config, opts):
# Make name safe:
opts.name = opts.name.decode('ascii','replace').replace(u'\uFFFD','_')
print("Modifying share: %s"%( opts.name, )) print("Modifying share: %s"%( opts.name, ))
found = False found = False
for i,share in enumerate(shares): for i,share in enumerate(shares):
@@ -180,7 +187,7 @@ def modify_share(shares, config, opts):
print('no such share') print('no such share')
sys.exit(1) sys.exit(1)
if opts.path != None: if opts.path != None:
share['path'] = opts.path share['path'] = opts.path.decode('ascii','replace').replace(u'\uFFFD','_')
for attr in ('public','upload','direct_links','overwrite'): for attr in ('public','upload','direct_links','overwrite'):
if getattr(opts,attr) != None: if getattr(opts,attr) != None:
share[attr] = getattr(opts,attr) == 'true' share[attr] = getattr(opts,attr) == 'true'
@@ -241,8 +248,7 @@ def modify_share(shares, config, opts):
with open(shares_file,'wt') as fp: with open(shares_file,'wt') as fp:
json.dump(shares, fp, indent = 2, sort_keys = True) json.dump(shares, fp, indent = 2, sort_keys = True)
print("Wrote file %s"%(shares_file,)) print("Wrote file %s"%(shares_file,))
else:
print("Share not saved anywhere. Save with -w")
modified = [] modified = []
for key in share: for key in share:
if not key in orig_share: if not key in orig_share:
@@ -256,6 +262,8 @@ def modify_share(shares, config, opts):
modified.append(key) modified.append(key)
print("Modified values: %s"%(", ".join(modified))) print("Modified values: %s"%(", ".join(modified)))
print(json.dumps(share, indent = 2, sort_keys = True)) print(json.dumps(share, indent = 2, sort_keys = True))
if not opts.write:
print("Share not saved anywhere.")
def remove_share(shares,config,opts): def remove_share(shares,config,opts):
@@ -505,8 +513,8 @@ def parse_options():
parser_add.add_argument('-r','--recipient', action="store", dest="recipient", default = "", parser_add.add_argument('-r','--recipient', action="store", dest="recipient", default = "",
help= "Recipient for notifications (if enabled)" help= "Recipient for notifications (if enabled)"
) )
parser_add.add_argument('-w','--write', action="store_true", dest="write", default = False, parser_add.add_argument('--dry', action="store_false", dest="write", default = True,
help = "Write changes to the shares.json file" help = "Do not write changes to the shares.json file"
) )
## Modify ## Modify
parser_modify = subparsers.add_parser('modify', help = "Modify share") parser_modify = subparsers.add_parser('modify', help = "Modify share")
@@ -539,8 +547,8 @@ def parse_options():
parser_modify.add_argument('--remove-token', action="append", dest="remove_tokens", default = [], parser_modify.add_argument('--remove-token', action="append", dest="remove_tokens", default = [],
help= "Remove REST tokens, may be issued multiple times" help= "Remove REST tokens, may be issued multiple times"
) )
parser_modify.add_argument('-w','--write', action="store_true", dest="write", default = False, parser_modify.add_argument('--dry', action="store_false", dest="write", default = True,
help = "Write changes to the shares.json file" help = "Do not write changes to the shares.json file"
) )
## REST ## REST
parser_rest = subparsers.add_parser('rest', help = "Display REST API links") parser_rest = subparsers.add_parser('rest', help = "Display REST API links")