def get_adopted_overlaid_dirs_list(list_of_dep_pkgs, dir_list_file_root=OVERLAY_PKGS_DIR()): result = [] try: for p in list_of_dep_pkgs: d = load_overlaid_dirs_list_file(p['pkgname'], dir_list_file_root) if (d != None): result.extend(d) except Exception as e: pass return result
def load_dependent_package_file(pkgobj, file=PACKAGE_FILE()): # OVERLAY package if (pkgobj['pkgtype'] == 'overlay'): return load_package_file( os.path.join(OVERLAY_PKGS_DIR(), pkgobj['pkgname'], PACKAGE_INFO_DIR())) # Readonly/Foreign Packages else: if (pkgobj['parentDir'] == None): sys.exit( f"ERROR: the {PACKAGE_FILE()} file is corrupt. There is no parent directory for the package: {pkgobj['pkgname']}" ) return load_package_file( os.path.join(pkgobj['parentDir'], pkgobj['pkgname'], PACKAGE_INFO_DIR()))
def get_owned_dirs(pkgroot, path_to_package_file=PACKAGE_INFO_DIR(), dir_list_file_root=OVERLAY_PKGS_DIR()): package_json = load_package_file(path_to_package_file) overlay_deps = json_get_list_adopted_overlay_deps(package_json) odirs = get_adopted_overlaid_dirs_list(overlay_deps, dir_list_file_root) dirsPrimary = json_get_package_primary_dirs(package_json) localdirs = [] ignorefile = get_ignore_file(pkgroot) if (dirsPrimary == None or len(dirsPrimary) == 0): sys.exit( "ERROR: NO 'primary' directories have been specified for the package" ) for d in dirsPrimary: l = walk_dir_filtered_by_ignored(d, ignorefile, pkgroot) localdirs.extend(l) # Remove overlaid directories return [x for x in localdirs if x not in odirs]
def run(common_args, cmd_argv): args = docopt(__doc__, argv=cmd_argv) # Display my package info if (not args['<adoptedpkg>']): utils.cat_package_file(int(args['--indent'])) # Display an adopted package else: # Check if the adopted package is actually adopted json_dict = utils.load_package_file() pkgobj, deptype, pkgidx = utils.json_find_dependency( json_dict, args['<adoptedpkg>']) if (pkgobj == None): sys.exit( f"ERROR: The package - {args['<adoptedpkg>']} is NOT an adopted package" ) # OVERLAY package if (pkgobj['pkgtype'] == 'overlay'): utils.cat_package_file(int(args['--indent']), path=os.path.join(OVERLAY_PKGS_DIR(), args['<adoptedpkg>'], PACKAGE_INFO_DIR())) # Readonly/Foreign Packages else: if (pkgobj['parentDir'] == None): sys.exit( f"ERROR: the {PACKAGE_FILE()} file is corrupt. There is no parent directory for the package: {args['<adoptedpkg>']}" ) json_dict = utils.cat_package_file(int(args['--indent']), path=os.path.join( pkgobj['parentDir'], args['<adoptedpkg>'], PACKAGE_INFO_DIR())) if (json_dict == None): sys.exit( f"ERROR: No package information is available for the Readonly/Foreign package: {args['<adoptedpkg>']}" )
def run(common_args, cmd_argv): args = docopt(__doc__, argv=cmd_argv) # Verbose option for subcommand vopt = ' -v ' if common_args['-v'] else '' # Look up the details of the package to be removed pkg = args['<adoptedpkg>'] json_dict = utils.load_package_file() pkgobj, deptype, pkgidx = utils.json_find_dependency(json_dict, pkg) if (pkgobj == None): sys.exit( f'Cannot find the package - {pkg} - in the list of adopted packages' ) # default branch option branch_opt = "" if (pkgobj['version']['branch'] != None): branch_opt = '-b ' + args['-b'] # READONLY Package if (pkgobj['pkgtype'] == 'readonly'): if (pkgobj['parentDir'] == None): sys.exit( f"ERROR: the {PACKAGE_FILE()} file is corrupt - there is no parent directory for the package" ) # Remove the package cmd = f"evie.py {vopt} --scm {pkgobj['repo']['type']} umount -p {pkgobj['pkgname']} {branch_opt} {pkgobj['parentDir']} {pkgobj['repo']['name']} {pkgobj['repo']['origin']} {pkgobj['version']['tag']}" t = utils.run_shell(cmd, common_args['-v']) utils.check_results( t, f"ERROR: Failed to umount the repo: {pkgobj['repo']['name']}, 'umount', 'get-error-msg', common_args['--scm']" ) # Remove the package from the deps list json_dict['dependencies'][deptype].pop(pkgidx) utils.write_package_file(json_dict) # Display parting message (if there is one) utils.display_scm_message('umount', 'get-success-msg', common_args['--scm']) # FOREIGN Package elif (pkgobj['pkgtype'] == 'foreign'): if (pkgobj['parentDir'] == None): sys.exit( f"ERROR: the {PACKAGE_FILE()} file is corrupt - there is no parent directory for the package" ) # Remove the package cmd = f"evie.py {vopt} --scm {pkgobj['repo']['type']} rm -p {pkgobj['pkgname']} {branch_opt} {pkgobj['parentDir']} {pkgobj['repo']['name']} {pkgobj['repo']['origin']} {pkgobj['version']['tag']}" t = utils.run_shell(cmd, common_args['-v']) utils.check_results( t, f"ERROR: Failed to remove the package: {pkgobj['repo']['name']}, 'rm', 'get-error-msg', common_args['--scm']" ) # Remove the package from the deps list json_dict['dependencies'][deptype].pop(pkgidx) utils.write_package_file(json_dict) # Display parting message (if there is one) utils.display_scm_message('rm', 'get-success-msg', common_args['--scm']) # OVERALY Package elif (pkgobj['pkgtype'] == 'overlay'): dstpkgpath = os.path.join(OVERLAY_PKGS_DIR(), pkg) if (not os.path.isdir(dstpkgpath)): sys.exit( f"ERROR: The {pkg} does not exist under the {OVERLAY_PKGS_DIR()}/ directory" ) # Remove the overlaid directories/files dirs = utils.load_overlaid_dirs_list_file(pkg) try: for d in dirs: utils.delete_directory_files(d) except: sys.exit("ERROR: Failed to remove overlaid directories") # Remove 'overlaid' directory utils.remove_tree(dstpkgpath) # Remove the package from the deps list json_dict['dependencies'][deptype].pop(pkgidx) utils.write_package_file(json_dict) # Remove the pkgs.overlaid dir if there are no more overlaid packages try: os.rmdir(OVERLAY_PKGS_DIR()) except: pass # Display parting message print(f"Overlay package - {pkg} - removed") # Unsupported package type else: sys.exit( f"ERROR: Unsupport package type: {pkgobj['pkgtype']}. The {PACKAGE_FILE()} file has been corrupted" )
def run( common_args, cmd_argv ): args = docopt(__doc__, argv=cmd_argv) # Verbose option for subcommand vopt = ' -v ' if common_args['-v'] else '' # Default Package name pkg = args['<repo>'] if ( args['-p'] ): pkg = args['-p'] # CLEAN-UP (for a failed overlay adoption) if ( args['clean'] ): tmpdst = os.path.join( PACKAGE_ROOT(), PACKAGE_INFO_DIR(), TEMP_DIR_NAME() ) utils.remove_tree( tmpdst, "error", "warn" ) sys.exit(0) # default branch option branch_opt = "" if ( args['-b'] ): branch_opt = '-b ' + args['-b'] # Get the current time dt_string = time.asctime(time.gmtime()) # check for already adopted json_dict = utils.load_package_file() pkgobj, deptype, pkgidx = utils.json_find_dependency( json_dict, pkg ) if ( pkgobj != None ): sys.exit( f'Package {pkg} already has been adopted as {deptype} dependency' ); # double check if the package has already been adopted (i.e. there was manual edits to the package.json file) if ( not args['overlay'] ): dstpkg = os.path.join( args['<dst>'], pkg) if ( os.path.exists( dstpkg ) ): sys.exit( f"ERROR: The destination - {dstpkg} - already exists" ) # # Adopt: Foreign # if ( args['foreign'] ): # Copy the FO package cmd = f"evie.py {vopt} --scm {common_args['--scm']} copy -p {pkg} {branch_opt} {args['<dst>']} {args['<repo>']} {args['<origin>']} {args['<id>']}" t = utils.run_shell( cmd, common_args['-v'] ) utils.check_results( t, f"ERROR: Failed to make a copy of the repo: {args['<repo>']}", 'copy', 'get-error-msg', common_args['--scm'] ) # update the package.json file dst_pkg_info = os.path.join( args['<dst>'], pkg, PACKAGE_INFO_DIR() ) incoming_semver = utils.get_adopted_semver( dst_pkg_info, args['--semver'], pkg, not args['--nowarn'] ) d = utils.json_create_dep_entry( pkg, "foreign", args['<dst>'], dt_string, incoming_semver, args['-b'], args['<id>'], args['<repo>'], common_args['--scm'], args['<origin>'] ) # Verify there is package file for package being adopted if ( check_for_package_file( d, args ) ): # Check for cyclical deps if ( check_cyclical_deps( json_dict, d, args) == False ): # Remove the package cmd = f"evie.py {vopt} --scm {d['repo']['type']} rm -p {d['pkgname']} {branch_opt} {d['parentDir']} {d['repo']['name']} {d['repo']['origin']} {d['version']['tag']}" t = utils.run_shell( cmd, common_args['-v'] ) utils.check_results( t, f"ERROR: Failed to remove the package: {d['repo']['name']}, 'rm', 'get-error-msg', common_args['--scm']" ) # Display parting message (if there is one) print("Adoption was 'reverted'") utils.display_scm_message( 'rm', 'get-success-msg', common_args['--scm'] ) sys.exit(1) # Save changes utils.json_update_package_file_with_new_dep_entry( json_dict, d, args['--weak'] ) # Display parting message (if there is one) utils.display_scm_message( 'copy', 'get-success-msg', common_args['--scm'] ) # # Adopt: ReadOnly # elif ( args['readonly'] ): # Mount the RO package cmd = f"evie.py {vopt} --scm {common_args['--scm']} mount -p {pkg} {branch_opt} {args['<dst>']} {args['<repo>']} {args['<origin>']} {args['<id>']}" t = utils.run_shell( cmd, common_args['-v'] ) utils.check_results( t, f"ERROR: Failed to mount the repo: {args['<repo>']}", 'mount', 'get-error-msg', common_args['--scm'] ) # update the package.json file dst_pkg_info = os.path.join( args['<dst>'], pkg, PACKAGE_INFO_DIR() ) incoming_semver = utils.get_adopted_semver( dst_pkg_info, args['--semver'], pkg, not args['--nowarn'] ) d = utils.json_create_dep_entry( pkg, "readonly", args['<dst>'], dt_string, incoming_semver, args['-b'], args['<id>'], args['<repo>'], common_args['--scm'], args['<origin>'] ) # Verify there is package file for package being adopted if ( check_for_package_file( d, args ) ): # Check for cyclical deps if ( check_cyclical_deps( json_dict, d, args) == False ): # Remove the package cmd = f"evie.py {vopt} --scm {d['repo']['type']} umount -p {d['pkgname']} {branch_opt} {d['parentDir']} {d['repo']['name']} {d['repo']['origin']} {d['version']['tag']}" t = utils.run_shell( cmd, common_args['-v'] ) utils.check_results( t, f"ERROR: Failed to umount the repo: {d['repo']['name']}, 'umount', 'get-error-msg', common_args['--scm']" ) # Display parting message (if there is one) print("Adoption was 'reverted'") utils.display_scm_message( 'umount', 'get-success-msg', common_args['--scm'] ) sys.exit(1) # Save changes utils.json_update_package_file_with_new_dep_entry( json_dict, d, args['--weak'] ) # Mark files as readonly utils.set_tree_readonly( dstpkg ) # Display parting message (if there is one) utils.display_scm_message( 'mount', 'get-success-msg', common_args['--scm'] ) # # Adopt: overlay # else: # Get a temporary copy of the OV package tmpdst = os.path.join( PACKAGE_INFO_DIR(), TEMP_DIR_NAME() ) cmd = f"evie.py {vopt} --scm {common_args['--scm']} copy --force -p {pkg} {branch_opt} {tmpdst} {args['<repo>']} {args['<origin>']} {args['<id>']}" t = utils.run_shell( cmd, common_args['-v'] ) utils.check_results( t, f"ERROR: Failed to make a copy of the repo: {args['<repo>']}", 'copy', 'get-error-msg', common_args['--scm'] ) # Fail if missing outcast info src_pkg = os.path.join( tmpdst, pkg ) dst_pkg = os.path.join( OVERLAY_PKGS_DIR(), pkg ) dst_pkg_info = os.path.join( dst_pkg, PACKAGE_INFO_DIR() ) src_pkg_info = os.path.join( src_pkg, PACKAGE_INFO_DIR() ) if ( not os.path.isfile( os.path.join(src_pkg_info, PACKAGE_FILE() ) ) ): utils.remove_tree(tmpdst) sys.exit( f"ERROR: Package - {pkg} - does NOT have {PACKAGE_FILE()} file") if ( not os.path.isfile( os.path.join(src_pkg_info, PKG_DIRS_FILE() ) )): utils.remove_tree(tmpdst) sys.exit( f"ERROR: Package - {pkg} - does NOT have {PKG_DIRS_FILE()} file") if ( not os.path.isfile( os.path.join(src_pkg_info, IGNORE_DIRS_FILE() ) )): utils.remove_tree(tmpdst) sys.exit( f"ERROR: Package - {pkg} - does NOT have {IGNORE_DIRS_FILE()} file") # Copy the adoptee's package info directory utils.copy_pkg_info_dir( dst_pkg_info, src_pkg_info ) # Create the dependency entry for the adopted package incoming_semver = utils.get_adopted_semver( dst_pkg_info, args['--semver'], pkg, not args['--nowarn'] ) d = utils.json_create_dep_entry( pkg, "overlay", args['<dst>'], dt_string, incoming_semver, args['-b'], args['<id>'], args['<repo>'], common_args['--scm'], args['<origin>'] ) # Check for cyclical deps if ( check_cyclical_deps( json_dict, d, args) == False ): # Remove the the package from the overlaid directory utils.remove_tree( dst_pkg ) sys.exit("Adoption was 'reverted'") # Copy the adoptee's extra info directories utils.copy_extra_dirs( dst_pkg, src_pkg ) # Get list of directories to copy/overlay dirs = utils.get_adoptee_owned_dirs( os.path.join( tmpdst, pkg, PACKAGE_INFO_DIR()), tmpdst ) if ( dirs != None ): for dir in dirs: src = os.path.join( src_pkg, dir ) dst = os.path.join( PACKAGE_ROOT(), dir ) utils.copy_files( src, dst ) # Clean-up utils.remove_tree( tmpdst ) # Save changes utils.json_update_package_file_with_new_dep_entry( json_dict, d, args['--weak'] ) print( f"Package - {pkg} - adopted as an OVERLAY package. Remember to add the new files to your SCM" )
def get_adoptee_owned_dirs(path_to_package_file=PACKAGE_INFO_DIR(), dir_list_file_root=OVERLAY_PKGS_DIR()): package_json = load_package_file(path_to_package_file) dirs = load_overlaid_dirs_list_file(json_get_package_name(package_json), dir_list_file_root) return dirs
def load_overlaid_dirs_list_file(adopted_pkg_name, dir_list_file_root=OVERLAY_PKGS_DIR()): if (adopted_pkg_name == None): return None p = os.path.join(dir_list_file_root, adopted_pkg_name, PACKAGE_INFO_DIR()) return load_dirs_list_file(path=p)