def licenseok(request): try: os.rename(Paths().tmp_license_file, Paths().license_file) sendLicenseToControllers() return HttpResponse('success') except Exception as e: logger.error(traceback.format_exc()) return HttpResponse('fail')
def uploadLicense(request): try: file = request.FILES.get('file') _license_dir = Paths().license_dir if not os.path.exists(_license_dir): os.makedirs(_license_dir, 0755) fd = open(Paths().tmp_license_file, 'wb') for chunk in file.chunks(): fd.write(chunk) fd.close() except Exception as e: logger.error(traceback.format_exc()) return HttpResponse(getTmpLicenseInfo())
def __init__(self): self.p = Printer(1) self.param = Params() self.m = Math() self.am = AudioManager() self.paths = Paths() self.trainingDesc, self.testingDesc = self.scanForAudioFiles()
def startUpgrade(): db = database() # 查出所有sql文件 sqlpath = Paths().src_dir + '/utils/db/upgrades/' sqlfiles = os.listdir(sqlpath) # 遍历sql文件,过滤出在升级记录表不存在的sql文件 hist = [ s['sqlfile'] for s in db.select_fetchall("select sqlfile from db_upgrade_hist") ] to_up = [] for s in sqlfiles: if s not in hist: to_up.append(s) # 按顺序执行sql文件,每执行成功一个,记录到升级记录表 if to_up: to_up.sort() upgrade_time = time.strftime("%Y-%m-%d %H:%M:%S") for f in to_up: of = open(sqlpath + f, 'r') sql = '' for line in of.readlines(): arr = line.split() if not arr or arr[0].startswith('--'): continue sql += line if arr[-1].endswith(';'): db.execute(sql) sql = '' histsql = "insert into db_upgrade_hist(sqlfile,upgrade_date) values('%s','%s')" % ( f, upgrade_time) db.execute(histsql)
def __init__(self): self.paths = Paths(); self.param = Params(); self.pc = PrintConfig(); self.p = Printer(1); self.am = AudioManager(); self.m = Math(); self.pickle = Pickle(self.paths.pickle, lTag=self.paths.tag1, sTag=self.paths.tag2); self.data = self.pickle.LoadData();
def __init__(self): self.paths = Paths() self.param = Params() self.pc = PrintConfig() self.data = SpeachData() self.p = Printer(1) self.am = AudioManager() self.m = Math() self.pickle = Pickle(self.paths.pickle, sTag=self.paths.tag1) self.data.raw = self.am.readAudio(self.paths.file)
def getTmpLicenseInfo(): try: file_name2 = ctypes.create_string_buffer(4096) file_name2.value = Paths().tmp_license_file license_info = ctypes.create_string_buffer(4096) buffer_len2 = ctypes.c_int(4096) result = LIBMCOSLBASER.get_license_info(file_name2, license_info, buffer_len2) return pickLicenseInfo(license_info.value) except Exception as e: logger.error(traceback.format_exc()) return ''
def __init__(self): self.paths = Paths() self.param = Params() self.pc = PrintConfig() self.am = AudioManager() self.p = Printer(1) self.S = Synthesizer() self.pickle = Pickle(self.paths.pickle) self.decoded, self.original, self.coded = self.loadAll() self.cP, self.cG, self.cLpc = self.organize() self.cSn = self.SynthAll()
def __init__(self): self.paths = Paths() self.param = Params() self.pc = PrintConfig() self.p = Printer(1) self.am = AudioManager() self.m = Math() self.pickle = Pickle(self.paths.pickle, lTag=self.paths.tag4, sTag=self.paths.tag5) self.cc = CodeConfig() self.cu = CodingUtils() self.encoded = self.pickle.LoadEncoded()
def readLicense(): try: license_info = ctypes.create_string_buffer(4096) license_path = Paths().license_file res = '' if os.path.exists(license_path): # 存在授权文件 file_name2 = ctypes.create_string_buffer(4096) file_name2.value = license_path buffer_len2 = ctypes.c_int(4096) LIBMCOSLBASER.get_license_info(file_name2, license_info, buffer_len2) return license_info.value except Exception as e: logger.error(traceback.format_exc()) return ''
def sendLicenseToControllers(): try: localpath1 = Paths().license_date_file end_date_str = getLicenseEndDate() with open(localpath1, 'w') as f: f.write(base64.b64encode(end_date_str)) (user_name, passwd) = getNodeLoginInfo() if os.path.exists(localpath1) and user_name and passwd: for ip in getControllers(): try: trans = paramiko.Transport((ip, 22)) trans.connect(username=user_name, password=passwd) sftp = paramiko.SFTPClient.from_transport(trans) remotepath1 = '/usr/local/license_date' sftp.put(localpath1, remotepath1) except Exception as ee: logger.error(traceback.format_exc()) except Exception as e: logger.error(traceback.format_exc())