예제 #1
0
def run(common_args, cmd_argv):
    args = docopt(__doc__, argv=cmd_argv)

    # -b option is not supported/needed
    if (args['-b'] != None):
        sys.exit(
            "The '-b' option is not supported/needed.  Use a 'remote-ref' as the <id> argument"
        )

    # Default Package name
    pkg = args['<repo>']
    if (args['-p']):
        pkg = args['-p']

    # Set directory for the subtree directory
    dst = os.path.join(args['<dst>'], pkg)
    dst = utils.force_unix_dir_sep(dst)
    utils.print_verbose(f"Location of the copy being updated: {dst}")

    # Update the 'subtree'
    cmd = f'git subtree pull --prefix {dst} {args["<origin>"]}/_git/{args["<repo>"]} {args["<id>"]} --squash'
    t = utils.run_shell(cmd, common_args['-v'])
    utils.check_results(
        t,
        "ERROR: Failed the update a subtree for the specified package/repository."
    )
예제 #2
0
def run(common_args, cmd_argv):
    args = docopt(scm.findroot.USAGE, argv=cmd_argv)

    # Update the 'subtree'
    cmd = f'git rev-parse --show-toplevel'
    t = utils.run_shell(cmd, common_args['-v'])
    utils.check_results(
        t,
        "ERROR: Failed find to find the root directory of local repository.")
    print(utils.standardize_dir_sep(t[1]))
예제 #3
0
def run(common_args, cmd_argv):
    args = docopt(scm.copy.USAGE, argv=cmd_argv)

    # Use the mount command so as to have consistent pre/post GIT behavior with adopting non-integrated packages
    if (not args['--force']):
        cmd_argv[0] = 'mount'
        cmd_argv.insert(1, '--noro')
        scm.git.mount.run(common_args, cmd_argv)

    # Do a brute force copy
    else:
        # -b option is not supported/needed
        if (args['-b'] != None):
            sys.exit(
                "The '-b' option is not supported/needed.  Use a 'remote-ref' as the <id> argument"
            )

        # Default Package name
        pkg = args['<repo>']
        if (args['-p']):
            pkg = args['-p']

        # Make sure the destination directory exists
        dst = os.path.join(os.getcwd(), args['<dst>'])
        utils.print_verbose(f"Destination for the copy: {dst}")
        utils.mkdirs(dst)

        # Create a clone of the repo
        # NOTE: I hate cloning the entire repo - but I have not found a way to get JUST a snapshot by a remote-ref
        cmd = f'git clone --branch {args["<id>"]} --depth=1 {args["<origin>"]}/_git/{args["<repo>"]} {pkg}'
        utils.push_dir(dst)
        t = utils.run_shell(cmd, common_args['-v'])
        utils.pop_dir()
        if (utils.is_error(t)):  # Clean-up dst dir if there was failure
            utils.remove_tree(dst)
        utils.check_results(
            t,
            f"ERROR: Failed the retreive/clone the specified package/repository. Note: the <id> ({args['<id>']}) MUST be a git TAG."
        )

        # Remove the .git directoy since this is a non-tracked copy
        gitdir = os.path.join(dst, pkg, ".git")
        utils.remove_tree(
            gitdir,
            warn_msg="Not able to remove the .git directory for local copy")
예제 #4
0
def run(common_args, cmd_argv):
    args = docopt(scm.mount.USAGE, argv=cmd_argv)

    # Success Msg
    if (args['get-success-msg']):
        print("Repo mounted and committed to your repo")
        return

    # Error Msg
    if (args['get-error-msg']):
        print("")  # No message
        return

    # Check if there are pending repo changes
    cmd = f'git diff-index HEAD --exit-code --quiet'
    t = utils.run_shell(cmd, False)
    cmd = f'git diff-index --cached HEAD --exit-code --quiet'
    t2 = utils.run_shell(cmd, False)
    utils.check_results(
        t,
        "ERROR: Your local repo has pending tree modification (i.e. need to do a commit/revert)."
    )
    utils.check_results(
        t2,
        "ERROR: Your local repo has pending index modification (i.e. need to do a commit/revert)."
    )

    # -b option is not supported/needed
    if (args['-b'] != None):
        sys.exit(
            "The '-b' option is not supported/needed.  Use a 'remote-ref' as the <id> argument"
        )

    # Default Package name
    pkg = args['<repo>']
    if (args['-p']):
        pkg = args['-p']

    # Make sure the Parent destination directory exists
    dst = args['<dst>']
    utils.mkdirs(dst)

    # Set directory for the subtree directory
    dst = os.path.join(dst, pkg)
    dst = utils.force_unix_dir_sep(dst)
    utils.print_verbose(f"Destination for the copy: {dst}")

    # Create a 'subtree'
    cmd = f'git subtree add --prefix {dst} {args["<origin>"]}/{args["<repo>"]}.git {args["<id>"]} --squash'
    t = utils.run_shell(cmd, common_args['-v'])
    if (utils.is_error(t)):  # Clean-up dst dir if there was failure
        utils.remove_tree(dst)
    utils.check_results(
        t,
        "ERROR: Failed to create a subtree for the specified package/repository."
    )
예제 #5
0
    """
    calculate ious between 2 sets of bboxes 
    args:
    - gt_bboxes [array]: Nx4 ground truth array
    - pred_bboxes [array]: Mx4 pred array
    returns:
    - iou [array]: NxM array of ious
    """
    ious = np.zeros((gt_bboxes.shape[0], pred_bboxes.shape[0]))
    for i, gt_bbox in enumerate(gt_bboxes):
        for j, pred_bbox in enumerate(pred_bboxes):
            ious[i, j] = calculate_iou(gt_bbox, pred_bbox)
    return ious


if __name__ == "__main__":
    ground_truth, predictions = get_data()
    # get bboxes array
    filename = 'segment-1231623110026745648_480_000_500_000_with_camera_labels_38.png'
    gt_bboxes = [
        g['boxes'] for g in ground_truth if g['filename'] == filename
    ][0]
    gt_bboxes = np.array(gt_bboxes)
    pred_bboxes = [
        p['boxes'] for p in predictions if p['filename'] == filename
    ][0]
    pred_boxes = np.array(pred_bboxes)

    ious = calculate_ious(gt_bboxes, pred_boxes)
    check_results(ious)
예제 #6
0

def channel_histogram(image_list):
    """
    calculate channel wise pixel value
    args:
    - image_list [list[str]]: list of image paths
    """
    red = []
    green = []
    blue = []
    for path in image_list:
        img = np.array(Image.open(path).convert('RGB'))
        R, G, B = img[..., 0], img[..., 1], img[..., 2]
        red.extend(R.flatten().tolist())
        green.extend(G.flatten().tolist())
        blue.extend(B.flatten().tolist())

    plt.figure()
    sns.kdeplot(red, color='r')
    sns.kdeplot(green, color='g')
    sns.kdeplot(blue, color='b')
    plt.show()


if __name__ == "__main__":
    image_list = glob.glob('../data/images/*')
    mean, std = calculate_mean_std(image_list)
    channel_histogram(image_list[:2])
    check_results(mean, std)
예제 #7
0
파일: rm.py 프로젝트: johnttaylor/Outcast
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"
        )
예제 #8
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" )