def upload(self): JenkinsJobDir = "%s/%s" % (self.JenkinsWorkSpaceDir, self.JenkinsJobName) if os.path.isdir("%s/target" % (JenkinsJobDir)): self.JenkinsTargetDir = "%s/target" % (JenkinsJobDir) else: self.JenkinsTargetDir = "%s/%s/target" % (JenkinsJobDir, self.ProjectName) # 判断包是jar还是war for JW in os.listdir(self.JenkinsTargetDir): if ".war" in JW: self.SourceProjectPackageName = JW self.TargetProjectPackageName = "%s.war" % (self.ProjectName) break # 将包上传至目标服务器 Source = "%s/%s" % (self.JenkinsTargetDir, self.SourceProjectPackageName) Target = "%s/%s" % (self.ProjectDir, self.TargetProjectPackageName) logs.log( "Upload: 目标主机: %s 源目录: %s 目标目录: %s\n" % (self.Host, Source, Target), self.ProjectName) print("Upload: 目标主机: %s 源目录: %s 目标目录: %s\n" % (self.Host, Source, Target)) UploadFile = "scp -P %s %s %s:%s" % (self.Port, Source, self.Host, Target) self.toolsCmd(UploadFile)
async def send(message, *args, **kwargs): global next_slot if next_slot > time.time(): async with message.channel.typing(): await asyncio.sleep(next_slot - time.time()) next_slot += 1 else: next_slot = time.time() + 1 if "embed" in kwargs: kwargs["embed"].set_footer( text=f"Requested by {message.author.display_name}") reply = await message.channel.send( *args, **{a: kwargs[a] for a in kwargs if a != "reaction"}) if "reaction" in kwargs: if type(kwargs["reaction"]) == list: reaction_list = kwargs["reaction"] elif kwargs["reaction"] == "": reaction_list = [] else: reaction_list = [kwargs["reaction"]] else: reaction_list = ["check"] for reaction in reaction_list: try: await message.add_reaction( emoji(emoji_shorthand.get(reaction, reaction))) except: log(f"Failed to add emoji {reaction}", "ERROR") return reply
def npmCode(self): self.JenkinsJobDir = "%s/%s" % (self.JenkinsWorkSpaceDir, self.JenkinsJobName) # 删除上次的文件目录 RmDirCmd = "rm -rf %s/%s" % (self.JenkinsJobDir,self.ProjectName) self.toolsCmd(RmDirCmd) ExecNpmCmd = "echo 未匹配;exit 1" if self.ProjectName == "iov-web-01": ExecNpmCmd = "cd %s && sudo npm install && npm run build:dev" % (self.JenkinsJobDir) elif self.ProjectName == "iov-web": if self.Env == "test": ExecNpmCmd = "cd %s && sudo npm install && npm run build:test" % (self.JenkinsJobDir) elif self.Env == "grey": ExecNpmCmd = "cd %s && sudo npm install && npm run build:grey" % (self.JenkinsJobDir) else: ExecNpmCmd = "cd %s && sudo npm install && npm run build" % (self.JenkinsJobDir) elif self.ProjectName == "iov-web-02": ExecNpmCmd = "cd %s && sudo npm install && npm run build:test2" % (self.JenkinsJobDir) elif self.ProjectName == "iov-web-03": ExecNpmCmd = "cd %s && sudo npm install && npm run build:test3" % (self.JenkinsJobDir) elif self.ProjectName == "demo-iov-web": ExecNpmCmd = "cd %s && sudo npm install && npm run build:demo" % (self.JenkinsJobDir) self.toolsCmd(ExecNpmCmd) self.DistFile = "%s/dist" % (self.JenkinsJobDir) if os.path.isdir(self.DistFile) == False: logs.log("NpmCode: %s文件不存在" % (self.DistFile),self.ProjectName) print("NpmCode: %s文件不存在" % (self.DistFile), self.ProjectName) sys.exit(1)
def npmCode(self): self.JenkinsJobDir = "%s/%s" % (self.JenkinsWorkSpaceDir, self.JenkinsJobName) # 删除上次的文件目录 RmDirCmd = "rm -rf %s/%s" % (self.JenkinsJobDir, self.ProjectName) self.toolsCmd(RmDirCmd) if self.ProjectName == "admin-front": if self.Env != "prd": ExecNpmCmd = "cd %s && sudo npm install && npm run build:stage" % ( self.JenkinsJobDir) else: ExecNpmCmd = "cd %s && sudo npm install && npm run build:prod" % ( self.JenkinsJobDir) else: ExecNpmCmd = "cd %s && sudo npm install && npm run build" % ( self.JenkinsJobDir) self.toolsCmd(ExecNpmCmd) if self.ProjectName == "empApp": self.DistFile = "%s/dist_admin" % (self.JenkinsJobDir) if os.path.isdir(self.DistFile) == False: logs.log("NpmCode: %s文件不存在" % (self.DistFile), self.ProjectName) print("NpmCode: %s文件不存在" % (self.DistFile), self.ProjectName) sys.exit(1) else: self.DistFile = "%s/dist" % (self.JenkinsJobDir) if os.path.isdir(self.DistFile) == False: logs.log("NpmCode: %s文件不存在" % (self.DistFile), self.ProjectName) print("NpmCode: %s文件不存在" % (self.DistFile), self.ProjectName) sys.exit(1)
def comp_asset(db_cur, job_id, arg1, arg2): db_cur.execute('SELECT local_path FROM storage WHERE asset_id = "' + str(arg1) + '"') row = db_cur.fetchone() log_str = 'COMP ' + str(arg1) + ' ' + str(arg2) if row is not None: f1 = row[0] db_cur.execute('SELECT local_path FROM storage WHERE asset_id = "' + str(arg2) + '"') row2 = db_cur.fetchone() if row2 is not None: f2 = row2[0] # check for asset type db_cur.execute('SELECT type FROM assets WHERE id = "' + str(arg1) + '"') ret1 = db_cur.fetchone() db_cur.execute('SELECT type FROM assets WHERE id = "' + str(arg2) + '"') ret2 = db_cur.fetchone() score = 0.0 print f1, f2 if ret1 is not None and ret2 is not None and ret1[0] == ret2[0]: if ret1[0] == 'video': # files are not .flv, but .blk (fn1, ext1) = os.path.splitext(f1) (fn2, ext2) = os.path.splitext(f2) print fn1, fn2 score = comp_video.get_video_similarity(fn1 + '.blk', fn2 + '.blk') elif ret2[0] == 'image': score = sift_runner.get_sift_match(f1, f2) add_similarity(db_cur, job_id, arg1, arg2, score) log_str += ' SUCC score = ' log_str += str(score) logs.log(job_id, 0, log_str) return True return False
def ssh(self, *args): ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(self.Host, self.Port, self.UserName, self.Password) ProjectName = args[-1] for i in range(0, len(args) - 1): Cmd = args[i] logs.log("SSH执行命令: Host: %s Cmd: \n\"%s\"\n" % (self.Host, Cmd), ProjectName) stdin, stdout, stderr = ssh.exec_command(Cmd) out, err = stdout.read(), stderr.read() outmsg, errmsg = out.decode().strip(), err.decode().strip() if errmsg != "": if 'WARNING' in errmsg: logs.log("SSH警告: WARNING: \n%s\n" % errmsg, ProjectName) print("SSH警告: WARNING: \n%s\n" % errmsg) else: logs.log("SSH报错: ERROR: \n%s\n" % errmsg, ProjectName) print("SSH报错: ERROR: \n%s\n" % errmsg) return 1 if outmsg != "": if "请联系运维" in outmsg: logs.log("SSH报错: ERROR: \n%s\n" % outmsg, ProjectName) print("SSH报错: ERROR: \n%s\n" % outmsg) return 1 logs.log("SSH输出: OUTPUT: \n%s\n" % outmsg, ProjectName) print("SSH输出: OUTPUT: \n%s\n" % outmsg) ssh.close()
def ConnDB(self, *args): self.data = {} ProjectName = args[-1] # 同时执行的参数不得是多条sql if len(args) > 2: return 1 for i in range(0, len(args) - 1): # for i in range(0,len(args)): connDB = pymysql.connect(host=self.DBHost, user=self.DBUserName, passwd=self.DBPassWord, port=self.DBPort, db=self.DBDBName) cursor = connDB.cursor() logs.log("DB执行SQL: %s\n" % (args[i]), ProjectName) print("DB执行SQL: %s\n" % (args[i])) cursor.execute(args[i]) connDB.commit() Out = cursor.fetchone() cursor.close() connDB.close() if "select" in args[i]: sqlNum = args[i].split(" ")[1] if "*" in sqlNum: self.data = Out elif "," in sqlNum: sqlNum = sqlNum.split(",") for t in range(0, len(sqlNum)): self.data[sqlNum[t]] = Out[t] else: self.data[sqlNum] = Out[0]
def register(): if 'username' not in session: if request.method == "POST": log("sys", "POST REQUEST RECEIVED AT /register") username = request.form['username'] password = request.form['password'] counselor = request.form['guidanceCounselor'] homeroom = request.form['homeroomA'] + request.form['homeroomB'] firstName = request.form['firstName'] lastName = request.form['lastName'] log("sys", "all form data received") if (request.form['password2'] != password): log(username, "passwords didn't match") return render_template("login.html", err="Error, passwords are not the same") else: #print username + " " + password #addedUser = utils.addUser(username, password) #boolean if user could be added log("sys", "account creation initialized") account = createAccount(username, password, counselor, homeroom, firstName, lastName) if (account == "Email in use" ): #user already existed in the database. log(username, "email in use") return render_template("login.html", err="Email already in use") return redirect(url_for('verify')) else: return render_template("login.html") else: return redirect(url_for('user'))
def update(self, t_now): todel = [] #remove possible duplicates (shouldn't happen) for i in range(0, len(self.segs) - 1): j = 0 for s in self.segs: if self.segs[i].t_start == s.t_start: j += 1 if (j > 1): if s.t_arrival < self.segs[i].t_arrival: self.segs.remove(s) else: self.segs.remove(self.segs[i]) #calculate length for i in range(0, len(self.segs)): s = self.segs[i] if (s.t_start + s.duration < t_now): todel.append(s) for s in todel: self.segs.remove(s) tmp_dur = self.get_duration(t_now) if 0 > tmp_dur: log('BUFFER UNDERFLOW', -1) elif tmp_dur > self.size_segs * seg_duration: log('BUFFER OVERFLOW', -1) return tmp_dur
def invite_friend(self, sender_id, message_text): # Confirm that <friend> has been added to <poll> active_poll = model.get_selected_poll(sender_id) if active_poll is None: self.write_no_poll_selected(sender_id) return parts = message_text.split() if len(parts) < 2: send_message(sender_id, "Please add your friend's name: 'invite <friend>'.", buttons=self.get_friend_invite_buttons( sender_id, active_poll)) return friend = " ".join(parts[1:]) if not model.is_admin_of_poll(sender_id, active_poll): send_message( sender_id, "I'm sorry, but I will only add participants if the admin asks me." ) return error = model.invite_friend(sender_id, active_poll, friend) if error is not None: log(error) send_message( sender_id, "I couldn't add your friend, please check it's not an imaginary friend of yours ;)" ) return send_message(sender_id, "I added your friend to the poll!")
def suggest_song(self, user_id, poll_id, song_id): """adds the song to poll as a suggestion from user user_id. Returns None on success or a string with an error message when something goes wrong. """ poll = self.polls.find_one({"poll_name": poll_id}) if poll is None: return "Error - No such poll found" log("Finding song {} in {}".format(song_id, poll['songs'])) if song_id in map(lambda x: x['song_id'], poll['songs']): return "Error - Song already in the poll" artist, title, uri = spotify.track_name.get_metadata(song_id) self.polls.update({"poll_name": poll_id}, { "$push": { "songs": { "song_id": song_id, "title": title, "artist": artist, "uri": uri, "votes": dict(), "suggested_by": user_id } } }) return None
def send_poll_help(self, sender_id, poll_name): if model.is_admin_of_poll(sender_id, poll_name): log(model.get_active_friends(sender_id)) log(model.get_poll_participants(sender_id, poll_name)) send_message( sender_id, "You can invite friends to this poll by sending me 'invite <friend_name>'. " "Note that you can only invite friends which have talked to me before.", buttons=self.get_friend_invite_buttons(sender_id, poll_name)) send_message( sender_id, "You can show all participants in this poll by sending me 'show participants'. " "You can ask me to send a song that you can vote for by sending 'show song'. " "You can see the ranking by sending me 'show ranking'.", buttons=[ { "type": "postback", "title": "Show participants", "payload": json.dumps({"action": Edi.ACTION_SHOW_POLL_PARTICIPANTS}) }, self.get_show_song_button(), self.get_ranking_button(sender_id, poll_name=poll_name), ]) send_message( sender_id, "You can suggest a new song for this poll by sending me 'suggest <song>', where " "song can be a Spotify song ID, URI or a search string.")
def BackupService(self): CheckFileStatus = self.CheckFile() if CheckFileStatus == 'CheckFileEmpty': return 0 DatetimeNowTime = datetime.datetime.now().strftime( '%Y-%m-%d-%H:%M:%S.bak') cmd = 'mv /data/%s/%s /data/backup/%s.%s' % ( self.ServiceName, self.PackageName, self.PackageName, DatetimeNowTime) self.RemoteCommandRun(cmd) cmd2 = 'ls -l /data/backup/%s.%s' % (self.PackageName, DatetimeNowTime) BackupServiceStatus = self.RemoteCommandRun(cmd2) #print('cmd',cmd) #print('cmd2',cmd2) #Process the \\n returned by the command BackupPackageName = "/data/backup/%s.%s\\n']" % (self.PackageName, DatetimeNowTime) #print('1:',str(BackupServiceStatus).split()[-1]) #print('2:',BackupPackageName) if str(BackupServiceStatus).split()[-1] == BackupPackageName: print('%s Backup success ' % BackupPackageName) logs.log('%s Backup success ' % BackupPackageName) else: print('%s Backup Failed' % BackupPackageName) logs.log('%s Backup Failed' % BackupPackageName)
def upload(self): if self.ProjectName == "car-app": Source = "%s/hybrid/html" % (self.JenkinsJobDir) Target = "%s" % (self.ProjectDir) UploadFile = "scp -P %s -r %s %s:%s" % (self.Port, Source, self.Host, Target) self.toolsCmd(UploadFile) else: if os.path.isdir(self.DistFile): MoveFileNameCmd = "mv %s %s/%s && cd %s/%s && tar zcf %s.tar.gz *" % ( self.DistFile, self.JenkinsJobDir, self.ProjectName, self.JenkinsJobDir, self.ProjectName, self.ProjectName) self.toolsCmd(MoveFileNameCmd) self.SourceProjectPackageName = "%s.tar.gz" % (self.ProjectName) self.TargetProjectPackageName = "%s.tar.gz" % (self.ProjectName) # 将包上传至目标服务器 Source = "%s/%s/%s" % (self.JenkinsJobDir, self.ProjectName, self.SourceProjectPackageName) Target = "%s/%s" % (self.ProjectDir, self.TargetProjectPackageName) logs.log("Upload: 源目录: %s 目标目录: %s\n" % (Source, Target), self.ProjectName) print("Upload: 源目录: %s 目标目录: %s\n" % (Source, Target)) UploadFile = "scp -P %s %s %s:%s" % (self.Port, Source, self.Host, Target) self.toolsCmd(UploadFile)
def construct_filename(name_in, rep): if rep == 0: return name_in + '_720p_1800k.mp4' elif rep == 2: return name_in + '_240p_400k.mp4' else: log('Unknown representation ' + rep, -1)
def fetch_image(db_cur, job_id, asset_id, tweet_id, uri): (path, ext) = os.path.splitext(uri) fname = TMP_DIR + str(tweet_id) + ext log_str = 'FETCHING ' + uri + ' ' f = open(fname, 'wb') succ = True try: f.write(urllib2.urlopen(uri, timeout=5).read()) except socket.timeout: log_str += 'FAILED (timeout)' succ = False except urllib2.URLError as e: log_str += 'FAILED (URLError) ' log_str += str(e) succ = False f.close() if succ == True: log_str += 'SUCC' add_local_storage(db_cur, job_id, asset_id, fname) logs.log(job_id, 0, log_str) else: os.remove(fname) logs.log(job_id, 1, log_str) return None return fname
def predict(self, image): image = resize_image(image) image_embedding = img_to_encoding(np.array([image]), facenet) start = time.time() label = self.model.predict(image_embedding) # predict方法返回值是array of shape [n_samples],因此下面要用label[0]从array中取得数值,https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html#sklearn.neighbors.KNeighborsClassifier.predict log("Predicting one face using svm model took {} seconds.".format(time.time() - start)) return label[0]
def Frontend(): HostIp = sys.argv[1] PackageName = sys.argv[2] ServiceName = PackageName.split(".")[0] UserName = '******' PassWord = '******' for i in HostIp.split(":"): #print(i) HostIP = i print(HostIP, PackageName, ServiceName, UserName) FrontendUat = main.Release(HostIP, PackageName, ServiceName, UserName, PassWord) DatetimeNowTime = datetime.datetime.now().strftime( '%Y-%m-%d-%H:%M:%S.bak') cmd = 'mv /data/%s /data/backup/%s_%s' % (ServiceName, ServiceName, DatetimeNowTime) FrontendUat.RemoteCommandRun(cmd) logs.log('%s %s run success' % (HostIP, cmd)) print('%s %s run success' % (HostIP, cmd)) cmd2 = 'mkdir -p /data/%s' % ServiceName FrontendUat.RemoteCommandRun(cmd2) logs.log('%s %s run success' % (HostIP, cmd2)) print('%s %s run success' % (HostIP, cmd2)) FrontendUat.FilesTransport() cmd3 = 'cd /data/%s && tar -xzvf %s && rm -rf /data/%s/%s' % ( ServiceName, PackageName, ServiceName, PackageName) #print(cmd3) FrontendUat.RemoteCommandRun(cmd3) logs.log('%s %s run success' % (HostIP, cmd3)) logs.log('Frontend Info:%s %s %s %s %s ' % (HostIP, PackageName, ServiceName, UserName, PassWord)) print('%s %s run success' % (HostIP, cmd3)) else: logs.log("Frontend release done")
def rollback(self): self.ProjectBackupDir = "%s/%s/%s" % (self.BackupDir, self.Host, self.ProjectName) self.ProjectDir = "%s/%s/%s" % (self.RootDir, self.Host, self.ProjectName) logs.log("Rollback: Source: %s" % (os.listdir(self.ProjectBackupDir))) print("回滚源:") SourceName = os.listdir(self.ProjectBackupDir) SourceName.sort() for S in range(0, len(SourceName)): print(SourceName[S]) RollbackName = input("请输入上面回滚源名称:") Source = "%s/%s" % (self.ProjectBackupDir, RollbackName) Target = "%s/%s.%s" % (self.ProjectDir, self.ProjectName, self.Type) logs.log( "Rollback: 目标主机: %s 源目录: %s 目标目录: %s\n" % (self.Host, Source, Target), self.ProjectName) print("Rollback: 目标主机: %s 源目录: %s 目标目录: %s\n" % (self.Host, Source, Target)) if self.RegisterEureka == "0": if Env == "prd": self.putEurekaStatusDown() self.backup() UploadFile = "scp -P %s %s %s:%s" % (self.Port, Source, self.Host, Target) self.toolsCmd(UploadFile)
def getserviceinip(self): GetServerIPCmd = "cat /etc/hosts|grep %s|awk NR==1|awk '{print $1}'" % (self.Host) SystemOutput = os.popen(GetServerIPCmd) res = SystemOutput.read() SplitOut = res.splitlines() self.IP = SplitOut[0] logs.log("获取IP地址: Host: %s IP: %s" % (self.Host,self.IP), self.ProjectName) print("获取IP地址: Host: %s IP: %s" % (self.Host,self.IP))
def open_url(url, query_str=None, post_body=None): # print url, query_str, post_body _url = url if query_str is not None: _url = '%s?%s' % (url, urlencode(query_str)) log(_url) html = urllib2.urlopen(_url) return BeautifulSoup(html, "html.parser")
def recvString(comsock): print("recieving string") try: bytestring = comsock.recv(settings["buffersize"]) string = bytestring.decode() return string except socket.error as e: logs.log("The following socket error was passed over - {}".format(e))
def putEurekaStatusUP(self): # 执行前先从eureka取消注册 UPUrl = "http://%s/eureka/apps/%s/%s:%s:%s/status?value=UP" % ( self.EurekaAddress, self.ProjectName.upper(), self.IP, self.ProjectName, self.ProjectPort) # 向eureka发送服务DOWN状态,并等待15秒 logs.log("向eureka发送服务UP状态: url: %s" % (UPUrl), self.ProjectName) print("向eureka发送服务UP状态: url: %s" % (UPUrl)) requests.put(UPUrl)
def SourceMd5Sum(self, filename): filename = '%s%s' % (self.PackageDir, filename) with open(filename, 'rb') as f: md5obj = hashlib.md5() md5obj.update(f.read()) hash = md5obj.hexdigest() #print(hash) logs.log('SourceMd5Sum %s md5Code %s' % (filename, hash)) return hash
def GetConf(self): ConfigReadlines = self.Config.readlines() Group = {} for i in ConfigReadlines: if '#' in i.split()[0]: continue Group[i.split('#')[0]] = i.split('#')[1:] logs.log('Get All Url Conf') return Group
def ServiceCheck(self): UrlCheck1 = UrlCheckMain.UrlCheck( 'http://uat-eureka1.dr-elephant.net:8861/eureka/apps', self.ServiceName, self.HostIP) UrlCheck1Done = UrlCheck1.UrlCheckMain() if '%sUrlCheckSuccess' % self.ServiceName == UrlCheck1Done: pass else: logs.log('%s %s' % (self.ServiceName, UrlCheck1Done)) sys.exit()
def OffLineService(self): Url = self.GetConf() ServiceUrl = Url.get(self.ServiceName) request = urllib2.Request(ServiceUrl) request.get_method = lambda: 'DELETE' response = urllib2.urlopen(request) print('%s Service ShutDown' % (ServiceUrl)) logs.log('%s ServiceShutDown And Url %s' % (self.ServiceName, ServiceUrl)) return 'ServiceShutDown'
def try_remove_files(filenames): home_folder = os.path.expanduser("~") for filename in filenames: filename = filename.replace("~", home_folder) try: os.remove(filename) except FileNotFoundError: logs.log(f"[OK] File not found {filename}")
def putEurekaStatusDown(self): # 执行前先从eureka取消注册 DownUrl = "http://%s/eureka/apps/%s/%s:%s:%s/status?value=DOWN" % ( self.EurekaAddress, self.ProjectName.upper(), self.IP, self.ProjectName, self.ProjectPort) # 向eureka发送服务DOWN状态,并等待15秒 logs.log("向eureka发送服务DOWN状态: url: %s" % (DownUrl), self.ProjectName) print("向eureka发送服务DOWN状态: url: %s" % (DownUrl)) requests.put(DownUrl) time.sleep(15)
def main(self): self.StopService() #self.BackupService() self.FilesTransport() self.PackageMd5Sum() self.StartService() print('Info:', self.HostIP, self.ServiceName, self.PackageName, self.UserName) logs.log('One Release Info:%s , %s, %s, %s, %s' % (self.HostIP, self.ServiceName, self.PackageName, self.UserName, self.PassWord))
def login(self): login_usr = self.login_usr.text() login_pwd = self.login_pwd.text() if login_usr == '123' and login_pwd == '123': log(file_path, '登录成功') # self.log_text.append('登录成功') # self.log_text.setText('登录成功') else: log(file_path, '登录失败,请检查用户、密码') # self.log_text.append('登录失败,请检查用户、密码') # self.log_text.setText('登录失败,请检查用户、密码') self.print_logs()
def anal_image(db_cur, job_id, asset_id): db_cur.execute('SELECT local_path FROM storage WHERE asset_id = "' + str(asset_id) + '"') row = db_cur.fetchone() log_str = 'ANAL ' + str(asset_id) + ' ' if row is not None: local_path = row[0] sift_runner.extract_sift_feature(local_path) log_str += local_path log_str += ' SUCC' logs.log(job_id, 0, log_str) return True return False
def RemoteCommandRun(self, cmd): ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(hostname=self.HostIP, port=self.SSHPort, username=self.UserName, password=self.PassWord) stdin, stdout, stderr = ssh.exec_command(cmd) done = stdout.readlines() #print(done) logs.log('command run done %s and result %s' % (cmd, done)) return (done)
def fetch_video(db_cur, job_id, asset_id, tweet_id, uri): (path, ext) = os.path.splitext(uri) fname = TMP_DIR + str(tweet_id) + '.flv' log_str = 'FETCHING ' + uri + ' ' log_str += fname # we gave 2 mins for each video downloading task (retcode, value) = video.timed_download(uri, fname, 120) if retcode == 0: log_str += 'SUCC' add_local_storage(db_cur, job_id, asset_id, fname) logs.log(job_id, 0, log_str) else: log_str += 'FAILED (retcode = ' + str(retcode) + ')' logs.log(job_id, 1, log_str) return value
def anal_video(db_cur, job_id, asset_id): import anal_video db_cur.execute('SELECT local_path FROM storage WHERE asset_id = "' + str(asset_id) + '"') row = db_cur.fetchone() log_str = 'ANAL ' + str(asset_id) + ' ' if row is not None: local_path = row[0] (title, ext) = os.path.splitext(local_path) try: log_str += local_path anal_video.affective(local_path, title) log_str += ' SUCC' except Exception, e: log_str += ' FAILED' logs.log(job_id, 0, log_str) return True
def __init__(self): self.dic = { 'umask': 022, 'user': None, 'procname': os.path.split(os.path.realpath(__file__))[0].split('/')[-2] } dlog = log() self.logger = dlog.logers('default') self.workpath = '/'.join((os.path.split(os.path.realpath(__file__))[0].split('/')[:-1])) self.pidfile = os.path.join(self.workpath + '/tmp', self.dic['procname'] + ".pid") self.dic['pidfile'] = self.pidfile
def authenticate(username, password): try: user = db.users.find({"name": username}) check = verify(password,user[0]["hash"]) if check: log(username,"logged in") else: log(username,"failed login was attempted") except: log(username, "an unknown user authentication error occurred") return False
def createAccount(username, password, counselor, homeroom, firstName, lastName): if checkUsername(username,password): log(username, "attempted account creation") return "Email in use" else: if addUser(username, password, counselor, homeroom, firstName, lastName): log(username, "account created") return "Account creation successful" else: log("sys","an unknown error accured during account creation") return "Account creation failed"
def __init__(self): self.__logger = logs.log().logers('default')
import glob import os from logs import logs as log logs=log() def qparse(questionlist): '''Goes through questions in a really ugly way. It works though and is somehow fairly fast''' def checkdicts(checkvar, plugin): '''I have no excuses for having this''' plugvals=plugin.values()[0] for plugdict in plugvals: logs.write("Checking dictionary {0}".format(plugdict),'trying') if plugdict.keys()[0]==checkvar: logs.write("Found {0} dictionary".format(checkvar), 'success') checkval=plugdict.values()[0] return checkval #Sees which plugins have the highest priority for question words. This means that you can define which plugins you'd like to answer the question if possible. If they can't it goes to the next. logs.write("Parsing possible plugins", 'trying') priority=open('priority.txt').read().split('\n') prioritized=[] for plugin in questionlist: plugname=plugin.keys()[0] logs.write("Checking plugin {0}".format(plugname), 'working') logs.write("Checking to see if the plugin is in the priority list", 'working') plugname=plugin.keys()[0] for line in priority: name=line.split(':')[1] status=line.split(':')[0] logs.write('Item {0} in priority list is {1}'.format(status, name), 'working') if plugname.lower()==name.lower(): logs.write("Plugin name and priority list item match", 'success') prioritized.append({status:plugin})
for gp in setings['gpio']: readings[str(gp)] = dict() humidity, temperature = dht.read_retry(sensors[setings['type']], gp) print ("GPIO{}".format(gp)) if humidity is not None and temperature is not None: print ('Temperature: {0:0.1f}\nHumidity: {1:0.1f}'.format(temperature, humidity)) readings[str(gp)]['temp'] = float('{0:0.1f}'.format(temperature)) readings[str(gp)]['humid'] = float('{0:0.1f}'.format(humidity)) readings[str(gp)]['timestamp'] = datetime.now() else: print ("Failed to get reading") readings[str(gp)]['temp'] = None readings[str(gp)]['humid'] = None readings[str(gp)]['timestamp'] = datetime.now() print ("") logs.log(readings) """Checks if data values are normal. If not, sends emails""" needToSendEmail = False # Need to send email? for key,value in readings.items(): if minTemp <= value['temp'] <= maxTemp or minHum <= value['humid'] <= maxHum or value['temp'] == None or value['humid'] == None: needToSendEmail = True if needToSendEmail: sendEmail(readings, setings['email']) pass makeStrinng(readings)
def __init__(self, dic): self.dic = dic self.msg = MIMEMultipart() self.logger = log().logers('default')
def update_job_status(db_cur, job_id, status): db_cur.execute('UPDATE jobs SET status="' + status + '" WHERE id = "' +str(job_id) + '"') logs.log(job_id, 0, 'job ' + str(job_id) + ' state changed to ' + status)
#coding=utf-8 #author='Shichao-Dong' import time from appium import webdriver from selenium.common.exceptions import WebDriverException import readConfig import GetDevices from StartAppiumServer import Sp from logs import log log = log() conf = readConfig.Readconfig() cmd = GetDevices.devices() deviceName = cmd.get_deviceName() platformVersion = cmd.get_platformVersion().encode('ascii') platformName = conf.getConfigValue('platformName') appPackage = conf.getConfigValue('appPackage').encode('ascii') appActivity = conf.getConfigValue('appActivity').encode('ascii') s = Sp(deviceName) appium_port = s.main() def mydriver(): desired_caps = { 'platformName':platformName,'deviceName':deviceName, 'platformVersion':platformVersion, 'appPackage':appPackage,'appActivity':appActivity, 'unicodeKeyboard':True,'resetKeyboard':True,'noReset':True,