@@ -256,7 +256,7 @@ def get_files_from_index(indexfile: str, silent=False) -> dict:
256256# helper class for the default values of extra fields in apps and appversions
257257class AppFields :
258258 # XXX TODO: preserve doi, new "origin" field?
259- # XXX somewhat obscure behavior: owner/group/citation are app level,
259+ # XXX somewhat obscure behavior: owner/group/citation/public are app level,
260260 # not appversion, and can't be changed on update (see import_file())
261261 # This should either be ajusted to that all fields can be edited (impacting
262262 # GET requests), or made more explicit in command-line args.
@@ -265,6 +265,7 @@ class AppFields:
265265 owner = None
266266 groups = []
267267 citation = ""
268+ public = False
268269 resources = []
269270 tags = []
270271 settings = {}
@@ -288,6 +289,8 @@ def __init__(self, app=None, args=None):
288289 if args != None :
289290 if args .owner != None :
290291 self .owner = None if args .owner == "" else args .owner
292+ if args .public != None :
293+ self .public = args .public
291294 if args .groups != None :
292295 self .groups = [] if args .groups == "" else args .groups .split ("," )
293296 if args .resources != None :
@@ -297,13 +300,13 @@ def __init__(self, app=None, args=None):
297300
298301# import an app from a descriptor file to a VIP-portal instance
299302# file is assumed already loaded and checked, VIP-portal will re-check anyways
300- def import_file (file , fields , is_overwrite = False , dry_run = True ):
303+ def import_file (file , fields , is_overwrite = False , dry_run = True , verbose = False ):
301304 init_api ()
302305 # create app and appVersion objects for the /rest/admin API
303306 appname = file ["descriptor" ]["name" ]
304307 version = file ["descriptor" ]["tool-version" ]
305308 descriptor = file ["rawtext" ]
306- app = {"name" :appname ,"applicationGroups" :fields .groups ,"owner" :fields .owner ,"citation" :fields .citation }
309+ app = {"name" :appname ,"applicationGroups" :fields .groups ,"owner" :fields .owner ,"citation" :fields .citation , "public" : fields . public }
307310 app_url = "admin/applications/" + urllib .parse .quote (appname )
308311 appver = {"applicationName" :appname ,"version" :version ,"descriptor" :descriptor ,"visible" :fields .is_visible ,"resources" :fields .resources ,"tags" :fields .tags ,"settings" :fields .settings }
309312 appver_url = "admin/appVersions/" + urllib .parse .quote (appname ) + "/" + urllib .parse .quote (version )
@@ -317,20 +320,19 @@ def import_file(file, fields, is_overwrite=False, dry_run=True):
317320 # fields on GET (see Appfields())
318321 can_put_app = not is_overwrite
319322 print ("importing app %s %s%s" % (appname , version , msg ))
320- if debug :
321- print ("descriptor string:" , descriptor )
322- if dry_run :
323- if can_put_app :
323+ if can_put_app :
324+ if verbose :
324325 print ("PUT %s %s" % (app_url , app ))
326+ if not dry_run :
327+ r = vip .generic_put (app_url , app )
328+ if verbose :
329+ print ("app updated:" , r )
330+ if verbose :
325331 print ("PUT %s %s" % (appver_url , appver ))
326- return
327- if can_put_app :
328- r = vip .generic_put (app_url , app )
329- if debug :
330- print ("app updated:" , r )
331- r = vip .generic_put (appver_url , appver )
332- if debug :
333- print ("appVersion updated:" , r )
332+ if not dry_run :
333+ r = vip .generic_put (appver_url , appver )
334+ if verbose :
335+ print ("appVersion updated:" , r )
334336
335337# recursive ordering of nested list/dict structures
336338# it transforms any dict into a list of 2-tuples to make lists of dicts sortable
@@ -385,24 +387,25 @@ def compare_descriptors(d1, d2) -> bool:
385387 return ordered (clean_descriptor (d1 ))== ordered (clean_descriptor (d2 ))
386388
387389# import helpers
388- def import_existing_app (app , file , args = None ,
389- show_unchanged = True , is_overwrite = False ,
390- dry_run = True , force_update = False ):
390+ def import_existing_app (app , file , args = None , is_overwrite = False ,
391+ dry_run = True , verbose = False , force_update = False ):
391392 identifier = app ["identifier" ]
392393 fields = AppFields (app = app , args = args )
393394 # XXX here we could also compare non-descriptor fields?
394395 if compare_descriptors (app , file ) and not force_update :
395- if show_unchanged :
396+ if verbose :
396397 print ("%s: unchanged" % identifier )
397398 elif not is_overwrite :
398399 print ("%s: changes detected, but overwrite is false" % identifier )
399400 else : # import with overwrite
400401 print ("%s: changes detected, overwriting" % identifier )
401- import_file (file , fields , is_overwrite = True , dry_run = dry_run )
402+ import_file (file , fields , is_overwrite = True ,
403+ dry_run = dry_run , verbose = verbose )
402404
403- def import_new_app (file , fields , dry_run = True ):
405+ def import_new_app (file , fields , dry_run = True , verbose = False ):
404406 print ("%s: new app" % file ["identifier" ])
405- import_file (file , fields , is_overwrite = False , dry_run = dry_run )
407+ import_file (file , fields , is_overwrite = False ,
408+ dry_run = dry_run , verbose = verbose )
406409
407410# sync a list of descriptors with a list of apps (from a VIP instance)
408411def perform_sync (args , apps , files ):
@@ -429,9 +432,8 @@ def perform_sync(args, apps, files):
429432 if app != None and file != None :
430433 # app identifiers match: compare descriptors and import if changed
431434 import_existing_app (app , file , args = args ,
432- show_unchanged = args .show_unchanged ,
433435 is_overwrite = args .overwrite ,
434- dry_run = args .dry_run ,
436+ dry_run = args .dry_run , verbose = args . verbose ,
435437 force_update = args .force_update )
436438 i += 1
437439 j += 1
@@ -440,7 +442,8 @@ def perform_sync(args, apps, files):
440442 print ("%s: orphan app with no descriptor" % app ["identifier" ])
441443 i += 1
442444 elif file != None : # import new app
443- import_new_app (file , AppFields (args = args ), dry_run = args .dry_run )
445+ import_new_app (file , AppFields (args = args ),
446+ dry_run = args .dry_run , verbose = args .verbose )
444447 j += 1
445448
446449# helper for list_* commands
@@ -500,12 +503,13 @@ def cmd_import_file(args):
500503 version = file ["descriptor" ]["tool-version" ]
501504 app = get_app (file ["identifier" ])
502505 if app != None : # app already exists
503- import_existing_app (app , file , args = args , show_unchanged = True ,
506+ import_existing_app (app , file , args = args ,
504507 is_overwrite = args .overwrite ,
505- dry_run = args .dry_run ,
508+ dry_run = args .dry_run , verbose = args . verbose ,
506509 force_update = args .force_update )
507510 else : # new app
508- import_new_app (file , AppFields (args = args ), dry_run = args .dry_run )
511+ import_new_app (file , AppFields (args = args ),
512+ dry_run = args .dry_run , verbose = args .verbose )
509513
510514# check a single descriptor file
511515def cmd_check_file (args ):
@@ -548,6 +552,7 @@ def cmd_show_index(args):
548552def add_subcommand (subparsers , name , func , help = None ):
549553 cmd = subparsers .add_parser (name , help = help )
550554 cmd .add_argument ("--silent" , action = "store_true" , help = "no warnings" )
555+ cmd .add_argument ("--verbose" , action = "store_true" , help = "show more detail" )
551556 cmd .set_defaults (func = func )
552557 return cmd
553558
@@ -572,13 +577,13 @@ def add_import_options(cmd):
572577 cmd .add_argument ("--force-update" , action = "store_true" , help = "force update even if descriptor didn't change" )
573578 cmd .add_argument ("--owner" , type = str , help = "set owner for new apps" )
574579 cmd .add_argument ("--groups" , type = str , help = "set groups for new apps" )
580+ cmd .add_argument ("--public" , type = parse_bool , help = "set is_public for new apps" )
575581 cmd .add_argument ("--resources" , type = str , help = "set resources for new or update apps" )
576582 cmd .add_argument ("--visible" , type = parse_bool , help = "set visibility for new or update apps" )
577583
578584def add_sync_options (cmd ):
579585 add_import_options (cmd )
580586 cmd .add_argument ("--show-orphans" , action = "store_true" , help = "show apps in VIP-portal with no descriptor in source" )
581- cmd .add_argument ("--show-unchanged" , action = "store_true" , help = "show VIP-portal apps which match their descriptor" )
582587
583588### main
584589def main ():
0 commit comments