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)
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
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)
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)
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)
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)
def file_isfile(options, arguments): path = join_listlike({}, arguments) return os.path.isfile(path)
def file_exists(options, arguments): path = join_listlike({}, arguments) return py_exists(path)
def change_dir(options, arguments): path = join_listlike({}, arguments) os.chdir(path)