def cp(filename, pwd, folder, user): ''' 复制文件 ''' if pwd == '/': print("不能将文件复制到根目录") return folderList = pwd.split("/") oldFolder = folder newname = folderList.pop(-1) # 最后一个默认是新文件名 if not len(newname): print("目标文件名不能为空") return if not len(folderList): # 当前文件夹下 # 判断重名 for each in folder.fileList: if each.name == newname: print("文件重名") return # 找到要复制的文件 for each in oldFolder.fileList: if each.name == filename: # 新建文件 file = File(newname) file.content = each.content folder.fileList.append(file) break else: print("文件不存在") return # 其他情况, # 先切换到目标目录 pwd = pwd[:pwd.rfind(newname) - 1] if not len(pwd): # 此时说明在根目录下 print("不能将文件复制到根目录下") return folder = cd(pwd, folder, user) # 再复制文件 # 判断重名 for each in folder.fileList: if each.name == newname: print("文件重名") return # 找到要复制的文件 for each in oldFolder.fileList: if each.name == filename: # 新建文件 file = File(newname) file.content = each.content folder.fileList.append(file) break else: print("文件不存在") return
def touch(filename, folder): ''' 创建文件 ''' if len(filename): file = File(filename) folder.fileList.append(file) else: print("文件名为空")
def delete_job(self, name): self.logger.debug("Supervisord: delete job %s Stop_job --> remove_process_group --> delete_config_file --> reload_config"%(name)) filee = File() conf_dir = SUPERVISORD["CONF_DIR"] + "/" + name + SUPERVISORD["CONF_EXTENSION"] filee.delete(conf_dir) time.sleep(1) self.sa.stop_process(name) self.sa.remove_process_group(name) return 0
def __init__(self, data_file, word_len=1, is_open_stream=False): """ Initializes the compressor object and sets up everything, for compressing the file. The data_file is the path to the file, except if is_open_stream is True, in which case it is treated as a readable binary stream.""" self.file = File(data_file, word_len, is_open_stream) self.data_length = len(self.file) self.initialize() self.word_len = word_len
def set_supervisord_schedule(self,host=None, jid=None, name=None, ip=None): if not (host and jid and name and ip): print 'Missing options: host=%s, jid=%d, name=%s, ip=%s'%(host, jid, name, ip) self.logger.warning('Missing options: host=%s, jid=%d, name=%s, ip=%s'%(host, jid, name, ip)) supervisord_config = self.create_config_file(host=host, jid=jid, name=name, ip=ip) full_dir = SUPERVISORD["CONF_DIR"] + '/' + name + SUPERVISORD["CONF_EXTENSION"] filee = File() print filee.write(dir = full_dir, text = supervisord_config) self.logger.info("config file: %s, content: %s"%(full_dir, supervisord_config)) return 0
def create_supervisord_config(ip, name, jid, thomson_host): file = File() supervisord_config_template = file.read_template() base_dir = os.path.abspath(os.path.dirname(sys.argv[0])) supervisord_config = supervisord_config_template.replace('{name}', name) supervisord_config = supervisord_config.replace('{ip}', ip) supervisord_config = supervisord_config.replace('{jid}', str(jid)) supervisord_config = supervisord_config.replace('{host}', thomson_host) supervisord_config = supervisord_config.replace('{base_dir}', base_dir) full_dir = SUPERVISORD["CONF_DIR"] + '/' + name + SUPERVISORD["CONF_EXTENSION"] file.write_conf_file(dir = full_dir, text = supervisord_config) logger.info("config file: %s, content: %s"%(full_dir, supervisord_config)) return 0
def create_config_file(self,host=None, jid=None, name=None, ip=None): try: filee = File() supervisord_config_template = filee.read(SUPERVISORD["CONF_TEMPLATE_DIR"]) except Exception as e: self.logger.error(str(e)) base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) supervisord_config = supervisord_config_template.replace('{name}', name) supervisord_config = supervisord_config.replace('{base_dir}', base_dir) supervisord_config = supervisord_config.replace('{host}', host) supervisord_config = supervisord_config.replace('{jid}', str(jid)) supervisord_config = supervisord_config.replace('{ip}', ip) return supervisord_config
def __init__(self, data_file, is_open_stream = False): """Extracts meta data. If is_open_stream is True data_file is treated as a readable binary stream.""" self.data_stream = File(data_file, is_open_stream) magic_number = self.data_stream.read(len(MAGIC_NUMBER)) if magic_number != MAGIC_NUMBER.encode("utf-8"): raise NotCorrectMagicNumber("Compressed file should start with\ {}".format(MAGIC_NUMBER)) meta = self._get_meta(self.data_stream) self.orig_length = meta["orig_length"] self.word_length = meta["word_length"] self.encode_dict = meta["encode_dict"] self.data_index = meta["data_index"]
def _load_file(self): self.file = File(self.__path) self.file.load()