def cleanoldjobs(self): ldir = [x[0] for x in os.walk(self.yamldir)] for l in ldir: All_files = glob.glob("%s/output_*.yaml" % l) if len(All_files) == 0: continue process = l print process, l if self.process != '' and self.process not in l: continue print 'process from the input directory ', process for f in All_files: if not os.path.isfile(f): print 'file does not exists... %s' % f continue with open(f, 'r') as stream: try: tmpf = yaml.load(stream) if tmpf['processing']['status'] == 'sending': if ut.gettimestamp( ) - tmpf['processing']['timestamp'] > 18000: print 'job %s is running since too long %i , will delete the yaml' % ( f, ut.gettimestamp() - tmpf['processing']['timestamp']) cmd = "rm %s" % (f) print cmd os.system(cmd) except yaml.YAMLError as exc: print(exc) except IOError as e: print(e)
def __getbase_params(self): base_params = { "Format": "json", "Version": "2015-01-09", "AccessKeyId": self.access_id, "TimeStamp": utils.gettimestamp(), "SignatureMethod": "HMAC-SHA1", "SignatureNonce": uuid.uuid4(), "SignatureVersion": "1.0", } return base_params
def format_texture(profile, unMetaData=False, BetterData=False): data_skin = textures.select().where(textures.textureid == profile.skin) data_cape = textures.select().where(textures.textureid == profile.cape) #print(type(data.time)) if BetterData: if not [True, False][getskintype_profile(profile) == "SKIN" and getskinmodel_profile(profile) == "ALEX"]: unMetaData = False else: unMetaData = True IReturn = { "timestamp": utils.gettimestamp(profile.create_time), 'profileId': profile.profile_id, 'profileName': profile.name, 'textures': {} } if data_skin: IReturn['textures'].update({ i.type: { "url": config.HostUrl + "/texture/" + i.hash, "metadata": { 'model': { "STEVE": 'default', "ALEX": 'slim' }[i.model] } } for i in data_skin }) if data_cape: IReturn['textures'].update({ i.type: { "url": config.HostUrl + "/texture/" + i.hash, "metadata": {} } for i in data_cape }) if unMetaData: for i in IReturn['textures'].keys(): del IReturn['textures'][i]["metadata"] return IReturn
def makeyaml(outdir, uid): if not ut.dir_exist(outdir): os.system("mkdir %s"%outdir) if outdir[-1]!='/': outdir+='/' outfile='%soutput_%s.yaml'%(outdir,uid) print '========================================== ',outfile if ut.file_exist(outfile): return False data = { 'processing' : { 'status' : 'sending', 'timestamp':ut.gettimestamp(), } } with open(outfile, 'w') as outyaml: yaml.dump(data, outyaml, default_flow_style=False) return True
#!/bin/python import sys sys.path.append("../src") import utils # start testing print("-- start testing utils.py") # test get local public ip local_public_ip = utils.getlocal_public_ip() assert local_public_ip != None print("getlocal_public_ip => " + local_public_ip) # test get remote resolved ip remote_resolved_ip = utils.getremote_resolved_ip('yiend.com', '') assert remote_resolved_ip != None print("getremote_resolved_ip => " + remote_resolved_ip) # test get timestamp now = utils.gettimestamp() assert now != None print("gettimestamp => " + now) # stop testing print("-- stop testing utils.py")