예제 #1
0
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()))
예제 #2
0
def write_package_file(json_dictionary):
    # make sure the pkgs.info directory exists
    if (not os.path.isdir(PACKAGE_INFO_DIR())):
        mkdirs(PACKAGE_INFO_DIR())

    # Remove 'temporary' key/value pairs
    for cats, depList in json_dictionary['dependencies'].items():
        for dep in depList:
            if ('depType' in dep):
                del dep['depType']

    # Sort the dictionary for consistent ordering in the physical file
    od = collections.OrderedDict(sorted(json_dictionary.items()))
    f = os.path.join(PACKAGE_INFO_DIR(), PACKAGE_FILE())
    data = json.dumps(od, indent=2)
    with open(f, "w+") as file:
        file.write(data)
예제 #3
0
def save_dirs_list_file(list_of_dirs,
                        path=PACKAGE_INFO_DIR(),
                        file=PKG_DIRS_FILE()):
    f = os.path.join(path, file)
    try:
        with open(f, 'w') as f:
            files = "\n".join(list_of_dirs)
            f.write(force_unix_dir_sep(files))
    except:
        sys.exit(f"WARNING: Failed to update the {f} with the directory list")
예제 #4
0
def cat_package_file(indent=2, path=PACKAGE_INFO_DIR(), file=PACKAGE_FILE()):
    f = os.path.join(path, file)

    try:
        with open(f) as f:
            json_dict = json.load(f)
            od = collections.OrderedDict(sorted(json_dict.items()))
            print(json.dumps(od, indent=indent))
            return json_dict
    except Exception as e:
        sys.exit(f"ERROR: Corrupt package file - {f} ({e})")
예제 #5
0
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>']}"
                )
예제 #6
0
def load_dirs_list_file(path=PACKAGE_INFO_DIR(), file=PKG_DIRS_FILE()):
    f = os.path.join(path, file)
    try:
        with open(f) as f:
            lines = f.readlines()
            result = []
            for l in lines:
                result.append(standardize_dir_sep(l.strip()))
            return result

    except Exception as e:
        print(e)
        return None
예제 #7
0
def load_package_file(
        path=PACKAGE_INFO_DIR(), file=PACKAGE_FILE(), does_file_exist=None):
    f = os.path.join(path, file)

    try:
        with open(f) as f:
            result = check_package_file(json.load(f))
            does_file_exist = True
            return result

    except Exception as e:
        does_file_exist = True
        return check_package_file({})
예제 #8
0
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]
예제 #9
0
def run(common_args, cmd_argv):
    args = docopt(__doc__, argv=cmd_argv)

    # Help on the publish sequence
    if (args['help']):
        print(help_text)
        sys.exit(0)

    # Get the package data
    json_dict = utils.load_package_file()

    # Edit in place
    if (args['--edit']):
        prev = utils.json_get_current_version(json_dict)
        v = utils.json_create_version_entry(args['<comments>'],
                                            args['<semver>'], prev['date'])
        utils.json_update_current_version(json_dict, v)

    # Edit a history entry
    elif (args['--edithist']):
        utils.json_update_history_version(json_dict, args['--edithist'],
                                          args['<comments>'], args['<semver>'])

    # Create new entry
    elif (args['<semver>']):
        v = utils.json_create_version_entry(args['<comments>'],
                                            args['<semver>'])
        utils.json_add_new_version(json_dict, v)

    # Important files...
    dirs_file = os.path.join(PACKAGE_INFO_DIR(), PKG_DIRS_FILE())
    ignore_file = os.path.join(PACKAGE_INFO_DIR(), IGNORE_DIRS_FILE())

    # Ensure the 'dirs list' is up to date
    if (not args['--nodirs'] and args['<semver>']):
        if (os.path.isfile(ignore_file)):
            owndirs = utils.get_owned_dirs(PACKAGE_ROOT())
            utils.save_dirs_list_file(owndirs)

    # display publish info
    p = utils.json_get_published(json_dict)
    print(json.dumps(p, indent=2))

    # Display warnings
    if (not args['-w']):
        warning = False
        if (not os.path.isfile(dirs_file)):
            print(
                f"Warning: NO {dirs_file} file has been created for the package.  See the 'orc dirs' command"
            )
            warning = True
        if (not os.path.isfile(ignore_file)):
            print(
                f"Warning: NO {ignore_file} file has been created for the package. Create using a text editor. The file has same semantics as a .gitignore file."
            )
            warning = True
        if (warning):
            print()
            print(
                f"The above warning(s) can be ignored if the package is NOT intended to be to be adopted as an 'overlay' package."
            )
예제 #10
0
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" )
예제 #11
0
def get_extra_dirs(src_package_root):
    package_path = os.path.join(src_package_root, PACKAGE_INFO_DIR())
    package_json = load_package_file(path=package_path)
    return json_get_package_extra_dirs(package_json)
예제 #12
0
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
예제 #13
0
def get_ignore_file(root):
    f = os.path.join(root, PACKAGE_INFO_DIR(), IGNORE_DIRS_FILE())
    if (os.path.isfile(f)):
        return f

    return None
예제 #14
0
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)