Exemple #1
0
def remove_rf(options, arguments):
    
    path = join_listlike({}, arguments)

    if file_isdir({}, args(path)):
        os.rmdir(path)
    else:
        os.remove(path)
def file_listdir(options, arguments):
    
    if len(arguments) == 0:
        path = "."
    else:
        path = join_listlike({}, arguments)
    
    return os.listdir(path)
Exemple #3
0
def remove_rf(options, arguments):

    path = join_listlike({}, arguments)

    if file_isdir({}, args(path)):
        os.rmdir(path)
    else:
        os.remove(path)
def file_stat(options, arguments):
    
    path = join_listlike({}, arguments)
    stat_res = os.stat(path)

    if 'size' in options and options['size']:
        return stat_res[stat.ST_SIZE]

    return stat_res
Exemple #5
0
def save_file(options, arguments):

    mode = options.get('mode', 'wb')
    path = join_listlike({}, arguments[:-1])

    try:

        with open(path, mode) as file:
            file.write(arguments[-1])

    except Exception, e:
        raise SHException(e.message)
Exemple #6
0
def load_file(options, arguments):

    mode = options.get('mode', 'rb')
    path = join_listlike({}, arguments)

    try:

        with open(path, mode) as file:
            return file.read()

    except Exception, e:
        raise SHException(e.message)
Exemple #7
0
def save_file(options, arguments):

    mode = options.get('mode', 'wb')
    path = join_listlike({}, arguments[:-1])
    
    try:

        with open(path, mode) as file:
            file.write(arguments[-1])

    except Exception, e:
        raise SHException(e.message)
Exemple #8
0
def load_file(options, arguments):
    
    mode = options.get('mode', 'rb')
    path = join_listlike({}, arguments)
    
    try:

        with open(path, mode) as file:
            return file.read()

    except Exception, e:
        raise SHException(e.message)
Exemple #9
0
def make_dir_p(options, arguments):
    #print "arguments: ", arguments
    if 'parents' in options and options['parents']:
        
        whole = ""

        for part in join_listlike({"as_list": True}, arguments):
            #print "part, ", part, ", whole, ", whole
            if whole == "" and part[1] == ':':
                whole = part
            else:
                whole += "/%s" % part
            
            if not py_exists(whole):
                os.mkdir(whole)
            if not py_isdir(whole):
                raise SHException("File exists at %s" % whole)
    else:
        
        path = join_listlike({},arguments)
        try:
            os.mkdir(path)
        except Exception, e:
            raise SHException(e.message)
Exemple #10
0
def make_dir_p(options, arguments):
    #print "arguments: ", arguments
    if 'parents' in options and options['parents']:

        whole = ""

        for part in join_listlike({"as_list": True}, arguments):
            #print "part, ", part, ", whole, ", whole
            if whole == "" and part[1] == ':':
                whole = part
            else:
                whole += "/%s" % part

            if not py_exists(whole):
                os.mkdir(whole)
            if not py_isdir(whole):
                raise SHException("File exists at %s" % whole)
    else:

        path = join_listlike({}, arguments)
        try:
            os.mkdir(path)
        except Exception, e:
            raise SHException(e.message)
Exemple #11
0
def file_isfile(options, arguments):

    path = join_listlike({}, arguments)
    return os.path.isfile(path)
Exemple #12
0
def file_exists(options, arguments):
    
    path = join_listlike({}, arguments)
    return py_exists(path)
Exemple #13
0
def change_dir(options, arguments):    
    
    path = join_listlike({}, arguments)
    os.chdir(path)
Exemple #14
0
def change_dir(options, arguments):

    path = join_listlike({}, arguments)
    os.chdir(path)