def initialize_coll_data(src_data_dir, tgt_coll): """ Initialize data in the specified target collection using definitions in the specified source directory. This is used for copying installable data collections from the Annalist installed software into the site data area. returns list of error messages; an empty list indicates success. """ tgt_data_dir, data_file = tgt_coll._dir_path() log.info("Copy Annalist collection data from %s to %s" % (src_data_dir, tgt_data_dir)) for sdir in layout.DATA_VOCAB_DIRS: # Don't copy user permissions expand_sdir = os.path.join(src_data_dir, sdir) if os.path.isdir(expand_sdir): log.info("- %s -> %s" % (sdir, tgt_data_dir)) Site.replace_site_data_dir(tgt_coll, sdir, src_data_dir) # Copy entity data to target collection. # # @TODO: This is hacky: it would be cleaner if the source directory were just # an exact copy of what ends up in the target collection directory. # Currently, a directory "entitydata" in the source data tree is used # for all user data directories and entities. # (cf. data/Annalist_schema) # expand_sdir = os.path.join(src_data_dir, "entitydata") expand_tdir = os.path.join( tgt_data_dir, layout.META_COLL_REF + layout.COLL_ENTITYDATA_PATH) if os.path.isdir(expand_sdir): log.info("- %s -> %s" % (sdir, expand_tdir)) replacetree(expand_sdir, expand_tdir) # Generate initial JSON-LD context data tgt_coll.generate_coll_jsonld_context() return []
def initialize_coll_data(src_data_dir, tgt_coll): """ Initialize data in the specified target collection using definitions in the specified source directory. This is used for copying installable data collections from the Annalist installed software into the site data area. returns list of error messages; an empty list indicates success. """ tgt_data_dir, data_file = tgt_coll._dir_path() log.info("Copy Annalist collection data from %s to %s"%(src_data_dir, tgt_data_dir)) for sdir in layout.DATA_VOCAB_DIRS: # Don't copy user permissions if os.path.isdir(os.path.join(src_data_dir, sdir)): log.info("- %s -> %s"%(sdir, tgt_data_dir)) Site.replace_site_data_dir(tgt_coll, sdir, src_data_dir) # Copy entity data to target collection. expand_entitydata = os.path.join(src_data_dir, "entitydata" ) if os.path.isdir(expand_entitydata): log.info("- Copy entitydata/...") for edir in os.listdir(expand_entitydata): if os.path.isdir(os.path.join(expand_entitydata, edir)): log.info("- %s -> %s"%(edir, tgt_data_dir)) Site.replace_site_data_dir(tgt_coll, edir, expand_entitydata) # Generate initial JSON-LD context data tgt_coll.flush_all_caches() tgt_coll.generate_coll_jsonld_context() return []
def initialize_coll_data(src_data_dir, tgt_coll): """ Initialize data in the specified target collection using definitions in the specified source directory. This is used for copying installable data collections from the Annalist installed software into the site data area. returns list of error messages; an empty list indicates success. """ tgt_data_dir, data_file = tgt_coll._dir_path() log.info("Copy Annalist collection data from %s to %s"%(src_data_dir, tgt_data_dir)) for sdir in layout.DATA_VOCAB_DIRS: # Don't copy user permissions expand_sdir = os.path.join(src_data_dir, sdir) if os.path.isdir(expand_sdir): log.info("- %s -> %s"%(sdir, tgt_data_dir)) Site.replace_site_data_dir(tgt_coll, sdir, src_data_dir) # Copy entity data to target collection. # # @TODO: This is hacky: it would be cleaner if the source directory were just # an exact copy of what ends up in the target collection directory. # Currently, a directory "entitydata" in the source data tree is used # for all user data directories and entities. # (cf. data/Annalist_schema) # expand_sdir = os.path.join(src_data_dir, "entitydata" ) expand_tdir = os.path.join( tgt_data_dir, layout.META_COLL_REF+layout.COLL_ENTITYDATA_PATH ) if os.path.isdir(expand_sdir): log.info("- %s -> %s"%(sdir, expand_tdir)) replacetree(expand_sdir, expand_tdir) # Generate initial JSON-LD context data tgt_coll.generate_coll_jsonld_context() return []
def initialize_coll_data(src_data_dir, tgt_coll): """ Initialize data in the specified target collection using definitions in the specified source directory. This is used for copying installable data collections from the Annalist installed software into the site data area. returns list of error messages; an empty list indicates success. """ tgt_data_dir, data_file = tgt_coll._dir_path() log.info("Copy Annalist collection data from %s to %s"%(src_data_dir, tgt_data_dir)) for sdir in layout.DATA_VOCAB_DIRS: # Don't copy user permissions if os.path.isdir(os.path.join(src_data_dir, sdir)): log.info("- %s -> %s"%(sdir, tgt_data_dir)) Site.replace_site_data_dir(tgt_coll, sdir, src_data_dir) # Copy entity data to target collection. expand_entitydata = os.path.join(src_data_dir, "entitydata" ) if os.path.isdir(expand_entitydata): log.info("- Copy entitydata/...") for edir in os.listdir(expand_entitydata): if os.path.isdir(os.path.join(expand_entitydata, edir)): log.info("- %s -> %s"%(edir, tgt_data_dir)) Site.replace_site_data_dir(tgt_coll, edir, expand_entitydata) # Generate initial JSON-LD context data tgt_coll.flush_all_caches() tgt_coll.generate_coll_jsonld_context() return []
def am_createsite(annroot, userhome, options): """ Create Annalist empty site data. annroot is the root directory for the Annalist software installation. userhome is the home directory for the host system user issuing the command. options contains options parsed from the command line. returns 0 if all is well, or a non-zero status code. This value is intended to be used as an exit status code for the calling program. """ status = am_errors.AM_SUCCESS sitesettings = am_get_site_settings(annroot, userhome, options) if not sitesettings: print("Settings not found (%s)"%(options.configuration), file=sys.stderr) return am_errors.AM_NOSETTINGS if len(options.args) > 0: print( "Unexpected arguments for %s: (%s)"% (options.command, " ".join(options.args)), file=sys.stderr ) return am_errors.AM_UNEXPECTEDARGS site_layout = layout.Layout(sitesettings.BASE_DATA_DIR) sitebasedir = site_layout.SITE_PATH sitebaseurl = "/annalist/" # @@TODO: figure more robust way to define this # --- If old site exists and --force option given, remove it if os.path.exists(os.path.join(sitebasedir, site_layout.SITEDATA_DIR)): if options.force: print("Removing old Annalist site at %s"%(sitebasedir)) log.info("rmtree: %s"%(sitebasedir)) removetree(sitebasedir) else: print( "Old data already exists at %s (use --force or -f to overwrite)"% (sitebasedir), file=sys.stderr ) return am_errors.AM_EXISTS # --- Initialize empty site data in target directory print("Initializing Annalist site in %s"%(sitebasedir)) site = Site.create_empty_site_data( sitebaseurl, sitebasedir, label="Annalist site (%s configuration)"%options.configuration, description="Annalist %s site metadata and site-wide values."%options.configuration ) sitedata = site.site_data_collection() Site.create_site_readme(site) site_data_src = os.path.join(annroot, "annalist/data/sitedata") # @@TODO: more robust definition site_data_tgt, site_data_file = sitedata._dir_path() print("Copy Annalist site data") print("from %s"%site_data_src) for sdir in layout.COLL_DIRS: print("- %s -> %s"%(sdir, site_data_tgt)) Site.replace_site_data_dir(sitedata, sdir, site_data_src) print("Generating %s"%(site_layout.SITEDATA_CONTEXT_DIR)) sitedata.generate_coll_jsonld_context() print("Now run 'annalist-manager initialize' to create site admin database") return status
def am_createsite(annroot, userhome, options): """ Create Annalist empty site data. annroot is the root directory for the Annalist software installation. userhome is the home directory for the host system user issuing the command. options contains options parsed from the command line. returns 0 if all is well, or a non-zero status code. This value is intended to be used as an exit status code for the calling program. """ status = am_errors.AM_SUCCESS sitesettings = am_get_site_settings(annroot, userhome, options) if not sitesettings: print("Settings not found (%s)"%(options.configuration), file=sys.stderr) return am_errors.AM_NOSETTINGS if len(options.args) > 0: print( "Unexpected arguments for %s: (%s)"% (options.command, " ".join(options.args)), file=sys.stderr ) return am_errors.AM_UNEXPECTEDARGS site_layout = layout.Layout(sitesettings.BASE_DATA_DIR, sitesettings.SITE_DIR_NAME) sitebasedir = site_layout.SITE_PATH #@@@@@ sitebaseurl = "/annalist/" # @@TODO: figure more robust way to define this sitebaseurl = sitesettings.STATIC_URL # --- If old site exists and --force option given, remove it if os.path.exists(os.path.join(sitebasedir, site_layout.SITEDATA_DIR)): if options.force: print("Removing old Annalist site at %s"%(sitebasedir)) log.info("rmtree: %s"%(sitebasedir)) removetree(sitebasedir) else: print( "Old data already exists at %s (use '--force' or '-f' to overwrite)."% (sitebasedir), file=sys.stderr ) print( "NOTE: using '--force' or '-f' "+ "removes old site user permissions and namespace data "+ "and requires re-initialization of Django database with local usernames; "+ "consider using 'annalist-manager updatesite'." ) return am_errors.AM_EXISTS # --- Initialize empty site data in target directory print("Initializing Annalist site in %s"%(sitebasedir)) site = Site.create_site_metadata( sitebaseurl, sitebasedir, label="Annalist site (%s configuration)"%options.configuration, description="Annalist %s site metadata and site-wide values."%options.configuration ) sitedata = site.site_data_collection() Site.create_site_readme(site) site_data_src = os.path.join(annroot, "annalist/data/sitedata") # @@TODO: more robust definition site_data_tgt, site_data_file = sitedata._dir_path() print("Copy Annalist site data") print("from %s"%site_data_src) for sdir in layout.COLL_DIRS: print("- %s -> %s"%(sdir, site_data_tgt)) Site.replace_site_data_dir(sitedata, sdir, site_data_src) # @@TODO: filename logic copied from EntityRoot and Collection - create separate method for getting this (sitedata_dir, sitedata_file) = sitedata._dir_path() context_dir = os.path.join(sitedata_dir, layout.META_COLL_BASE_REF) context_file = os.path.join(context_dir, layout.COLL_CONTEXT_FILE) #@@ print("Generating %s"%(context_file)) sitedata.generate_coll_jsonld_context() # --- Copy provider data to site config provider directory provider_dir_src = os.path.join(annroot, "annalist/data/identity_providers") provider_dir_tgt = os.path.join(sitesettings.CONFIG_BASE, "providers") print("Copy identity provider data:") print("- from: %s"%(provider_dir_src,)) print("- to: %s"%(provider_dir_tgt,)) ensure_dir(provider_dir_tgt) updatetree(provider_dir_src, provider_dir_tgt) # --- Copy sample system configuration files to config directory config_dir_src = os.path.join(annroot, "annalist/data/config_examples") config_dir_tgt = os.path.join(sitesettings.CONFIG_BASE, "config") print("Copy system configuration sample files:") print("- from: %s"%(config_dir_src,)) print("- to: %s"%(config_dir_tgt,)) ensure_dir(config_dir_tgt) updatetree(config_dir_src, config_dir_tgt) # --- Created print("Now run 'annalist-manager initialize' to create site admin database") return status
def am_updatesite(annroot, userhome, options): """ Update site data, leaving user data alone annroot is the root directory for the Annalist software installation. userhome is the home directory for the host system user issuing the command. options contains options parsed from the command line. returns 0 if all is well, or a non-zero status code. This value is intended to be used as an exit status code for the calling program. """ status = am_errors.AM_SUCCESS sitesettings = am_get_site_settings(annroot, userhome, options) if not sitesettings: print("Settings not found (%s)"%(options.configuration), file=sys.stderr) return am_errors.AM_NOSETTINGS if len(options.args) > 0: print( "Unexpected arguments for %s: (%s)"% (options.command, " ".join(options.args)), file=sys.stderr ) return am_errors.AM_UNEXPECTEDARGS site_layout = layout.Layout(sitesettings.BASE_DATA_DIR, sitesettings.SITE_DIR_NAME) sitebasedir = site_layout.SITE_PATH sitebaseurl = "/annalist/" # @@TODO: figure more robust way to define this site = Site(sitebaseurl, site_layout.SITE_PATH) sitedata = site.site_data_collection(test_exists=False) if sitedata is None: print("Initializing Annalist site metadata in %s (migrating to new layout)"%(sitebasedir)) site = Site.create_site_metadata( sitebaseurl, sitebasedir, label="Annalist site (%s configuration)"%options.configuration, description="Annalist %s site metadata and site-wide values."%options.configuration ) sitedata = site.site_data_collection() site_data_src = os.path.join(annroot, "annalist/data/sitedata") # @@TODO: more robust definition site_data_tgt, site_data_file = sitedata._dir_path() # --- Migrate old site data to new site directory # _annalist_site/ site_data_old1 = os.path.join(sitebasedir, site_layout.SITEDATA_OLD_DIR1) old_site_metadata = os.path.join(site_data_old1, site_layout.SITE_META_FILE) old_site_database = os.path.join(site_data_old1, site_layout.SITE_DATABASE_FILE) old_users1 = os.path.join(site_data_old1, layout.USER_DIR_PREV) old_vocabs1 = os.path.join(site_data_old1, layout.VOCAB_DIR_PREV) if os.path.isfile(old_site_metadata): print("Move old site metadata: %s -> %s"%(old_site_metadata, sitebasedir)) new_site_metadata = os.path.join(sitebasedir, site_layout.SITE_META_FILE) os.rename(old_site_metadata, new_site_metadata) if os.path.isfile(old_site_database): print("Move old site database: %s -> %s"%(old_site_database, sitebasedir)) new_site_database = os.path.join(sitebasedir, site_layout.SITE_DATABASE_FILE) os.rename(old_site_database, new_site_database) if os.path.isdir(old_users1) or os.path.isdir(old_vocabs1): print("Copy Annalist old user and/or vocab data from %s"%site_data_old1) migrate_old_data(site_data_old1, layout.USER_DIR_PREV, site_data_tgt, layout.USER_DIR ) migrate_old_data(site_data_old1, layout.VOCAB_DIR_PREV, site_data_tgt, layout.VOCAB_DIR) # c/_annalist_site/_annalist_collection/ - using new dir names site_data_old2 = os.path.join(sitebasedir, site_layout.SITEDATA_OLD_DIR2) old_users2 = os.path.join(site_data_old2, layout.USER_DIR) old_vocabs2 = os.path.join(site_data_old2, layout.VOCAB_DIR) if os.path.isdir(old_users2) or os.path.isdir(old_vocabs2): print("Copy Annalist old user and/or vocab data from %s"%site_data_old2) migrate_old_data(site_data_old2, layout.USER_DIR_PREV, site_data_tgt, layout.USER_DIR ) migrate_old_data(site_data_old2, layout.VOCAB_DIR_PREV, site_data_tgt, layout.VOCAB_DIR) # --- Archive old site data so it's not visible next time if os.path.isdir(site_data_old1): archive_old_data(site_data_old1, "") if os.path.isdir(site_data_old2): archive_old_data(site_data_old2, "") # --- Copy latest site data to target directory print("Copy Annalist site data") print("from %s"%site_data_src) for sdir in layout.DATA_DIRS: print("- %s -> %s"%(sdir, site_data_tgt)) Site.replace_site_data_dir(sitedata, sdir, site_data_src) for sdir in (layout.USER_DIR, layout.VOCAB_DIR): print("- %s +> %s"%(sdir, site_data_tgt)) Site.update_site_data_dir(sitedata, sdir, site_data_src) for sdir in (layout.INFO_DIR,): print("- %s ~> %s"%(sdir, site_data_tgt)) Site.expand_site_data_dir(sitedata, sdir, site_data_src) for sdir in layout.COLL_DIRS_PREV: remove_old_data(site_data_tgt, sdir) print("Generating context for site data") sitedata.generate_coll_jsonld_context() # --- Copy provider data to site config provider directory provider_dir_src = os.path.join(annroot, "annalist/data/identity_providers") provider_dir_tgt = os.path.join(sitesettings.CONFIG_BASE, "providers") print("Copy identity provider data:") print("- from: %s"%(provider_dir_src,)) print("- to: %s"%(provider_dir_tgt,)) ensure_dir(provider_dir_tgt) updatetree(provider_dir_src, provider_dir_tgt) # --- Copy sample system configuration files to config directory config_dir_src = os.path.join(annroot, "annalist/data/config_examples") config_dir_tgt = os.path.join(sitesettings.CONFIG_BASE, "config") print("Copy system configuration sample files:") print("- from: %s"%(config_dir_src,)) print("- to: %s"%(config_dir_tgt,)) ensure_dir(config_dir_tgt) updatetree(config_dir_src, provider_dir_tgt) return status
def am_createsite(annroot, userhome, options): """ Create Annalist empty site data. annroot is the root directory for the Annalist software installation. userhome is the home directory for the host system user issuing the command. options contains options parsed from the command line. returns 0 if all is well, or a non-zero status code. This value is intended to be used as an exit status code for the calling program. """ status = am_errors.AM_SUCCESS sitesettings = am_get_site_settings(annroot, userhome, options) if not sitesettings: print("Settings not found (%s)" % (options.configuration), file=sys.stderr) return am_errors.AM_NOSETTINGS if len(options.args) > 0: print("Unexpected arguments for %s: (%s)" % (options.command, " ".join(options.args)), file=sys.stderr) return am_errors.AM_UNEXPECTEDARGS site_layout = layout.Layout(sitesettings.BASE_DATA_DIR) sitebasedir = site_layout.SITE_PATH sitebaseurl = "/annalist/" # @@TODO: figure more robust way to define this # --- If old site exists and --force option given, remove it if os.path.exists(os.path.join(sitebasedir, site_layout.SITEDATA_DIR)): if options.force: print("Removing old Annalist site at %s" % (sitebasedir)) log.info("rmtree: %s" % (sitebasedir)) removetree(sitebasedir) else: print( "Old data already exists at %s (use --force or -f to overwrite)" % (sitebasedir), file=sys.stderr) return am_errors.AM_EXISTS # --- Initialize empty site data in target directory print("Initializing Annalist site in %s" % (sitebasedir)) site = Site.create_empty_site_data( sitebaseurl, sitebasedir, label="Annalist site (%s configuration)" % options.configuration, description="Annalist %s site metadata and site-wide values." % options.configuration) sitedata = site.site_data_collection() Site.create_site_readme(site) site_data_src = os.path.join( annroot, "annalist/data/sitedata") # @@TODO: more robust definition site_data_tgt, site_data_file = sitedata._dir_path() print("Copy Annalist site data") print("from %s" % site_data_src) for sdir in layout.COLL_DIRS: print("- %s -> %s" % (sdir, site_data_tgt)) Site.replace_site_data_dir(sitedata, sdir, site_data_src) print("Generating %s" % (site_layout.SITEDATA_CONTEXT_DIR)) sitedata.generate_coll_jsonld_context() print( "Now run 'annalist-manager initialize' to create site admin database") return status
def am_updatesite(annroot, userhome, options): """ Update site data, leaving user data alone annroot is the root directory for the Annalist software installation. userhome is the home directory for the host system user issuing the command. options contains options parsed from the command line. returns 0 if all is well, or a non-zero status code. This value is intended to be used as an exit status code for the calling program. """ status = am_errors.AM_SUCCESS sitesettings = am_get_site_settings(annroot, userhome, options) if not sitesettings: print("Settings not found (%s)" % (options.configuration), file=sys.stderr) return am_errors.AM_NOSETTINGS if len(options.args) > 0: print("Unexpected arguments for %s: (%s)" % (options.command, " ".join(options.args)), file=sys.stderr) return am_errors.AM_UNEXPECTEDARGS site_layout = layout.Layout(sitesettings.BASE_DATA_DIR) sitebasedir = site_layout.SITE_PATH sitebaseurl = "/annalist/" # @@TODO: figure more robust way to define this site = Site(sitebaseurl, site_layout.SITE_PATH) sitedata = site.site_data_collection(test_exists=False) if sitedata is None: print( "Initializing Annalist site metadata in %s (migrating to new layout)" % (sitebasedir)) site = Site.create_empty_site_data( sitebaseurl, sitebasedir, label="Annalist site (%s configuration)" % options.configuration, description="Annalist %s site metadata and site-wide values." % options.configuration) sitedata = site.site_data_collection() site_data_src = os.path.join( annroot, "annalist/data/sitedata") # @@TODO: more robust definition site_data_tgt, site_data_file = sitedata._dir_path() # --- Migrate old site data to new site directory site_data_old = os.path.join(sitebasedir, site_layout.SITEDATA_OLD_DIR) old_users = os.path.join(site_data_old, layout.USER_DIR_PREV) old_vocabs = os.path.join(site_data_old, layout.VOCAB_DIR_PREV) if os.path.isdir(old_users) or os.path.isdir(old_vocabs): print("Copy Annalist old user and/or vocab data from %s" % site_data_old) migrate_old_data(site_data_old, layout.USER_DIR_PREV, site_data_tgt, layout.USER_DIR) migrate_old_data(site_data_old, layout.VOCAB_DIR_PREV, site_data_tgt, layout.VOCAB_DIR) #@@ # if os.path.isdir(old_users) or os.path.isdir(old_vocabs): # print("Copy Annalist old user and/or vocab data from %s"%site_data_old) # for sdir in ("users", "vocabs"): # s = os.path.join(site_data_old, sdir) # old_s = os.path.join(site_data_old, "old_"+sdir) # d = os.path.join(site_data_tgt, sdir) # if os.path.isdir(s): # print("- %s +> %s (migrating)"%(sdir, d)) # updatetree(s, d) # print("- %s >> %s (rename)"%(sdir, old_s)) # os.rename(s, old_s) #@@ # --- Copy latest site data to target directory print("Copy Annalist site data") print("from %s" % site_data_src) for sdir in layout.DATA_DIRS: print("- %s -> %s" % (sdir, site_data_tgt)) Site.replace_site_data_dir(sitedata, sdir, site_data_src) for sdir in (layout.USER_DIR, layout.VOCAB_DIR): print("- %s +> %s" % (sdir, site_data_tgt)) Site.update_site_data_dir(sitedata, sdir, site_data_src) for sdir in layout.COLL_DIRS_PREV: remove_old_data(site_data_tgt, sdir) print("Generating %s" % (site_layout.SITEDATA_CONTEXT_DIR)) sitedata.generate_coll_jsonld_context() # --- Copy provider data to site config provider directory provider_dir_tgt = os.path.join(sitesettings.CONFIG_BASE, "providers") provider_dir_src = os.path.join(annroot, "annalist/data/identity_providers") print("Copy identity provider data:") print("- from: %s" % (provider_dir_src, )) print("- to: %s" % (provider_dir_tgt, )) updatetree(provider_dir_src, provider_dir_tgt) return status
def am_createsite(annroot, userhome, options): """ Create Annalist empty site data. annroot is the root directory for the Annalist software installation. userhome is the home directory for the host system user issuing the command. options contains options parsed from the command line. returns 0 if all is well, or a non-zero status code. This value is intended to be used as an exit status code for the calling program. """ status = am_errors.AM_SUCCESS sitesettings = am_get_site_settings(annroot, userhome, options) if not sitesettings: print("Settings not found (%s)" % (options.configuration), file=sys.stderr) return am_errors.AM_NOSETTINGS if len(options.args) > 0: print("Unexpected arguments for %s: (%s)" % (options.command, " ".join(options.args)), file=sys.stderr) return am_errors.AM_UNEXPECTEDARGS site_layout = layout.Layout(sitesettings.BASE_DATA_DIR) sitebasedir = site_layout.SITE_PATH sitebaseurl = "/annalist/" # @@TODO: figure more robust way to define this # --- If old site exists and --force option given, remove it if os.path.exists(os.path.join(sitebasedir, site_layout.SITEDATA_DIR)): if options.force: print("Removing old Annalist site at %s" % (sitebasedir)) log.info("rmtree: %s" % (sitebasedir)) removetree(sitebasedir) else: print( "Old data already exists at %s (use '--force' or '-f' to overwrite)." % (sitebasedir), file=sys.stderr) print( "NOTE: using '--force' or '-f' " + "removes old site user permissions and namespace data " + "and requires re-initialization of Django database with local usernames; " + "consider using 'annalist-manager updatesite'.") return am_errors.AM_EXISTS # --- Initialize empty site data in target directory print("Initializing Annalist site in %s" % (sitebasedir)) site = Site.create_site_metadata( sitebaseurl, sitebasedir, label="Annalist site (%s configuration)" % options.configuration, description="Annalist %s site metadata and site-wide values." % options.configuration) sitedata = site.site_data_collection() Site.create_site_readme(site) site_data_src = os.path.join( annroot, "annalist/data/sitedata") # @@TODO: more robust definition site_data_tgt, site_data_file = sitedata._dir_path() print("Copy Annalist site data") print("from %s" % site_data_src) for sdir in layout.COLL_DIRS: print("- %s -> %s" % (sdir, site_data_tgt)) Site.replace_site_data_dir(sitedata, sdir, site_data_src) # @@TODO: filename logic copied from EntityRoot and Collection - create separate method for getting this (sitedata_dir, sitedata_file) = sitedata._dir_path() context_dir = os.path.join(sitedata_dir, layout.META_COLL_BASE_REF) context_file = os.path.join(context_dir, layout.COLL_CONTEXT_FILE) #@@ print("Generating %s" % (context_file)) sitedata.generate_coll_jsonld_context() # --- Copy provider data to site config provider directory provider_dir_src = os.path.join(annroot, "annalist/data/identity_providers") provider_dir_tgt = os.path.join(sitesettings.CONFIG_BASE, "providers") print("Copy identity provider data:") print("- from: %s" % (provider_dir_src, )) print("- to: %s" % (provider_dir_tgt, )) ensure_dir(provider_dir_tgt) updatetree(provider_dir_src, provider_dir_tgt) # --- Created print( "Now run 'annalist-manager initialize' to create site admin database") return status
def am_updatesite(annroot, userhome, options): """ Update site data, leaving user data alone annroot is the root directory for the Annalist software installation. userhome is the home directory for the host system user issuing the command. options contains options parsed from the command line. returns 0 if all is well, or a non-zero status code. This value is intended to be used as an exit status code for the calling program. """ status = am_errors.AM_SUCCESS sitesettings = am_get_site_settings(annroot, userhome, options) if not sitesettings: print("Settings not found (%s)"%(options.configuration), file=sys.stderr) return am_errors.AM_NOSETTINGS if len(options.args) > 0: print( "Unexpected arguments for %s: (%s)"% (options.command, " ".join(options.args)), file=sys.stderr ) return am_errors.AM_UNEXPECTEDARGS site_layout = layout.Layout(sitesettings.BASE_DATA_DIR) sitebasedir = site_layout.SITE_PATH sitebaseurl = "/annalist/" # @@TODO: figure more robust way to define this site = Site(sitebaseurl, site_layout.SITE_PATH) sitedata = site.site_data_collection(test_exists=False) if sitedata is None: print("Initializing Annalist site metadata in %s (migrating to new layout)"%(sitebasedir)) site = Site.create_empty_site_data( sitebaseurl, sitebasedir, label="Annalist site (%s configuration)"%options.configuration, description="Annalist %s site metadata and site-wide values."%options.configuration ) sitedata = site.site_data_collection() site_data_src = os.path.join(annroot, "annalist/data/sitedata") # @@TODO: more robust definition site_data_tgt, site_data_file = sitedata._dir_path() # --- Migrate old site data to new site directory site_data_old = os.path.join(sitebasedir, site_layout.SITEDATA_OLD_DIR) old_users = os.path.join(site_data_old, layout.USER_DIR_PREV) old_vocabs = os.path.join(site_data_old, layout.VOCAB_DIR_PREV) if os.path.isdir(old_users) or os.path.isdir(old_vocabs): print("Copy Annalist old user and/or vocab data from %s"%site_data_old) migrate_old_data(site_data_old, layout.USER_DIR_PREV, site_data_tgt, layout.USER_DIR ) migrate_old_data(site_data_old, layout.VOCAB_DIR_PREV, site_data_tgt, layout.VOCAB_DIR) #@@ # if os.path.isdir(old_users) or os.path.isdir(old_vocabs): # print("Copy Annalist old user and/or vocab data from %s"%site_data_old) # for sdir in ("users", "vocabs"): # s = os.path.join(site_data_old, sdir) # old_s = os.path.join(site_data_old, "old_"+sdir) # d = os.path.join(site_data_tgt, sdir) # if os.path.isdir(s): # print("- %s +> %s (migrating)"%(sdir, d)) # updatetree(s, d) # print("- %s >> %s (rename)"%(sdir, old_s)) # os.rename(s, old_s) #@@ # --- Copy latest site data to target directory print("Copy Annalist site data") print("from %s"%site_data_src) for sdir in layout.DATA_DIRS: print("- %s -> %s"%(sdir, site_data_tgt)) Site.replace_site_data_dir(sitedata, sdir, site_data_src) for sdir in (layout.USER_DIR, layout.VOCAB_DIR): print("- %s +> %s"%(sdir, site_data_tgt)) Site.update_site_data_dir(sitedata, sdir, site_data_src) for sdir in layout.COLL_DIRS_PREV: remove_old_data(site_data_tgt, sdir) print("Generating %s"%(site_layout.SITEDATA_CONTEXT_DIR)) sitedata.generate_coll_jsonld_context() # --- Copy provider data to site config provider directory provider_dir_tgt = os.path.join(sitesettings.CONFIG_BASE, "providers") provider_dir_src = os.path.join(annroot, "annalist/data/identity_providers") print("Copy identity provider data:") print("- from: %s"%(provider_dir_src,)) print("- to: %s"%(provider_dir_tgt,)) updatetree(provider_dir_src, provider_dir_tgt) return status