Example #1
0
def is_locked(path):
    if os.path.isfile(path):
        return str(os.stat(path).st_uid) == show_config.get('publish_user:uid')
    else:
        if str(os.stat(path).st_uid) != show_config.get('publish_user:uid'):
            return False
        else:
            contents = os.listdir(path)
            for file_path in contents:
                content_path = os.path.join(path, file_path)
                if not is_locked(content_path):
                    return False
            return True
Example #2
0
def rmdir(path, *paths):
    sys.stdout.write(">>>>>>>>>>file_utils rmdir path %s\n" % path)
    sys.stdout.flush()

    cmd = [
        os.path.join(show_config.get("publish_user:bin", "/bin"), 'wm_rmdir'),
        path
    ] + list(paths)
    return subprocess.check_call(cmd)
Example #3
0
def ln(target, linkname):
    sys.stdout.write(">>>>>>>>>>file_utils ln target %s linkname %s\n" %
                     (target, linkname))
    sys.stdout.flush()

    cmd = [
        os.path.join(show_config.get("publish_user:bin", "/bin"), 'wm_ln'),
        '-sfn', target, linkname
    ]
    return subprocess.check_call(cmd)
Example #4
0
def mv(source, destination, isforce=True, noclobber=False):
    sys.stdout.write(">>>>file_utils mv source %s destination %s\n" %
                     (source, destination))
    sys.stdout.flush()

    cmd = [os.path.join(show_config.get("publish_user:bin", "/bin"), 'wm_mv')]
    if isforce: cmd.append("-f")
    if noclobber: cmd.append("-n")
    cmd += [source, destination]
    return subprocess.check_call(cmd)
Example #5
0
def rm_recursive(path, *paths):
    sys.stdout.write(">>>>>>>>>>file_utils rm_recursive paths %s\n" %
                     str([path] + list(paths)))
    sys.stdout.flush()

    cmd = [
        os.path.join(show_config.get("publish_user:bin", "/bin"), 'wm_rm'),
        '-rf', path
    ] + list(paths)
    return subprocess.check_call(cmd)
Example #6
0
def cp_file(sources, destination, preserveTime=False):
    sys.stdout.write(
        ">>>>>>>>>>file_utils cp_file source %s destination %s\n" %
        (sources, destination))
    sys.stdout.flush()

    cmd = [os.path.join(show_config.get("publish_user:bin", "/bin"), 'wm_cp')]
    if preserveTime: cmd.append("--preserve=timestamps")
    if isinstance(sources, (str, unicode)): sources = [sources]
    cmd += list(sources)
    cmd.append(destination)
    return subprocess.check_call(cmd)
Example #7
0
def cp_recursive(source, destination, preserveTime=False):
    sys.stdout.write(
        ">>>>>>>>>>file_utils cp_recursive source=%s destination=%s\n" %
        (source, destination))
    sys.stdout.flush()

    cmd = [
        os.path.join(show_config.get("publish_user:bin", "/bin"), 'wm_cp'),
        '-R'
    ]
    if preserveTime: cmd.append("--preserve=timestamps")
    cmd += [source, destination]
    return subprocess.check_call(cmd)
Example #8
0
def mkdir(path):
    sys.stdout.write(">>>>>>>>>>file_utils mkdir path %s\n" % path)
    sys.stdout.flush()

    mode = get_mode(path, new_dir=True)
    sys.stdout.write(">>>>>>>>>>file_utils mkdir mode %s path %s\n" %
                     (mode, path))
    sys.stdout.flush()
    cmd = [
        os.path.join(show_config.get("publish_user:bin", "/bin"), 'wm_mkdir'),
        '-m', mode, '-p', path
    ]
    return subprocess.check_call(cmd)
Example #9
0
def chmod_file(path, *paths):
    sys.stdout.write(">>>>>>>>>>file_utils chmod_file path %s\n" % path)
    sys.stdout.flush()
    #mode = get_mode(path)
    #sys.stdout.flush()

    # Get mode of each path and group them by each different mode
    assert not isinstance(path, (tuple, list))
    prog = os.path.join(show_config.get("publish_user:bin", "/bin"),
                        'wm_chmod')
    modes = [(get_mode(p), p) for p in [path] + list(paths)]
    modes.sort()
    for mode, pathgrp in itertools.groupby(modes, key=lambda x: x[0]):
        for chunk in _grouper(20, pathgrp):
            cmd = [prog, mode] + sorted([x[1] for x in chunk])
            subprocess.check_call(cmd)
    return 0
Example #10
0
def chmod_recursive(path):
    prod_root = "%s/prod" % os.environ['NCO_PROJECT_PATH']
    if path.find(prod_root) == 0:
        lock_prod = True
    else:
        lock_prod = False

    prog = os.path.join(show_config.get("publish_user:bin", "/bin"),
                        'wm_chmod')
    mode = get_mode(path, lock_prod=lock_prod)
    if os.path.isdir(path):
        sys.stdout.write(">>file_utils chmod_recursive dir %s mode %s\n" %
                         (path, mode))
        sys.stdout.flush()

        cmd = [prog, mode, path]
        result = subprocess.check_call(cmd)
        for root, dirs, files in os.walk(path):
            for d in dirs:
                this_dir = os.path.join(root, d)
                mode = get_mode(this_dir, lock_prod=lock_prod)
                sys.stdout.write(
                    ">>>>file_utils chmod_recursive dir %s mode %s\n" %
                    (this_dir, mode))
                sys.stdout.flush()
                cmd = [prog, mode, this_dir]
                subprocess.check_call(cmd)
            for f in files:
                this_file = os.path.join(root, f)
                if os.path.islink(this_file):
                    continue
                mode = get_mode(this_file, lock_prod=lock_prod)
                sys.stdout.write(
                    ">>>>>file_utils chmod_recursive file %s mode %s\n" %
                    (this_file, mode))
                sys.stdout.flush()
                cmd = [prog, mode, this_file]
                subprocess.check_call(cmd)
    else:
        sys.stdout.write(">>file_utils chmod_recursive file %s mode %s\n" %
                         (path, mode))
        sys.stdout.flush()
        cmd = [prog, mode, path]
        result = subprocess.check_call(cmd)
    return 0
Example #11
0
def get_mode(path, new_dir=False, lock_prod=False):
    '''
    get mode for LOCKING directories and initial creation of directories
    (eg making shot dir or making asset dirs)
        
    in prod tree:
        down to $NCO_PROJECT_PATH/prod/shots/<SEQUENCE>/<SHOT>/<DEPT> 0755. 
        these will always be directories
        down to $NCO_PROJECT_PATH/prod/assets/<ASSET_TYPE>/<ASSET_NAME>/
                                 <DEPT> 0755. these will always be directories

        initial creation:
            $NCO_PROJECT_PATH/prod/shots/<SEQUENCE>/<SHOT>/<DEPT>/common
                           and below 0775 (directories) and 0664 (files)
            $NCO_PROJECT_PATH/prod/assets/<ASSET_TYPE>/<ASSET_NAME>
                /<DEPT>/common and below 0775 (directories) and 0664 (files)
        in place publishing:
            $NCO_PROJECT_PATH/prod/shots/<SEQUENCE>/<SHOT>/<DEPT>/common
                          and below 0755 (directories) and 0644 (files)
            $NCO_PROJECT_PATH/prod/assets/<ASSET_TYPE>/<ASSET_NAME>
            /<DEPT>/common and below 0755 (directories) and 0644 (files)

        except pikit library:
            $NCO_PROJECT_PATH/prod/assets/pikit and below 0755 (directories)
                  and 0644 (files)

    in publish tree:
        down to $NCO_PROJECT_PATH/publish/shots/<SEQUENCE> 0755. these
                              will always be directories
        down to $NCO_PROJECT_PATH/publish/assets/<ASSET_TYPE> 0755.
                                           these will always be directories

        from $NCO_PROJECT_PATH/publish/shots/<SEQUENCE>/<SHOT> 1775
                                          (directories) and 0644 (files)
        from $NCO_PROJECT_PATH/publish/assets/<ASSET_TYPE>/<ASSET_NAME> 1775
                                             (directories) and 0644 (files)

    will return -1 if not in prod or publish tree of currently set project
    '''

    path = clean_path(path)

    is_dir = os.path.isdir(path) or new_dir

    publish_root = "%s/publish" % os.environ['NCO_PROJECT_PATH']
    prod_root = "%s/prod" % os.environ['NCO_PROJECT_PATH']

    prodlink_root = show_config.get("publish_user:prodlink_root")
    if prodlink_root:
        prodlink_root = os.path.join(prodlink_root, os.environ['NCO_PROJECT'],
                                     "prod")

    pikit_root = "%s" % show_config.get("pikit:library", expandpath=True)
    if pikit_root[-1:] == '/':
        pikit_root = pikit_root[0:-1]

    if path.find(pikit_root) == 0:
        if is_dir:
            mode = "0755"
        else:
            mode = "0644"
    elif path.find(prod_root) == 0:
        if len(path.split('/')) < 10:
            mode = "0755"
        else:
            if lock_prod:
                if is_dir:
                    mode = "0755"
                else:
                    mode = "0644"
            else:
                if is_dir:
                    mode = "0775"
                else:
                    mode = "0664"
    elif path.find(publish_root) == 0:
        if len(path.split('/')) < 8:
            mode = "0755"
        else:
            if is_dir:
                mode = "1775"
            else:
                mode = "0644"
    elif prodlink_root and path.find(prodlink_root) == 0:
        if len(path.split('/')) < 12:
            mode = "0755"
        else:
            mode = "0775"
    else:
        raise FileUtilsErr(
            errno.ENOSYS,
            "can't determine mode because path is outside prod and publish tree",
            path)
        #sys.stdout.write("ERROR: can't determine mode as path %s not in prod or publish or prodlink tree\n" %path)
        #return "-1"
    return mode