def __main__(*args): jobs = RepositoryUtils.GetJobs(True) for job in jobs: # Skip out if not within the last 24 hours if DateTime.Compare(job.JobSubmitDateTime, last24) < 0: print("Skipped by date") continue # Skip if the status isn't right if not (job.JobStatus == 'Active' or job.JobStatus == 'Failed'): print("Skipped by status") continue print('Job: {0} ({1})'.format(job.JobName, job.JobId))
def getFilesYoungerThan(dir, younger_than=0): if exists(dir): files = Directory.GetFiles(dir) date_to_check = DateTime.Parse( DateTime.Now.AddDays(-younger_than).ToString("yyyy.MM.dd")) files_of_age = [] for file in files: file = FileInfo(file) print file result = DateTime.Compare(file.CreationTime, date_to_check) if result < 0: relationship = "is earlier than %s" % date_to_check elif result == 0: relationship = "is the same time as %s" % date_to_check files_of_age.append(file) else: relationship = "is later than %s" % date_to_check files_of_age.append(file) print relationship return files_of_age
def delete_jobs(self): current_time = DateTime.Now hours = self.delete_days * 24 jobs = list(RepositoryUtils.GetJobs(True)) self.log_verbose("Found {0} jobs. Scanning...".format(len(jobs))) older_than = current_time.Subtract(TimeSpan(hours, 0, 0)) for job in jobs: submitted = job.JobSubmitDateTime if submitted == DateTime.MinValue: continue if DateTime.Compare(submitted, older_than) < 0: if not self.dry_run: self.log_verbose( "Removing job {1} - {0}. Submitted on {2}.".format( job.JobName, job.JobId, submitted)) RepositoryUtils.ArchiveJob(job, True, None) else: self.log_verbose( "Would have removed job {1} - {0}. Submitted on {2}.". format(job.JobName, job.JobId, submitted)) print("Older than {0}".format(older_than))
def determine_status(self): if self.statusSet: return # PMM CHECKS checks_sql = "SELECT TOP 20 * FROM [BackgroundChecks] WHERE [PeopleId] = @p1 AND " \ "DATEDIFF(DAY, DATEADD(YEAR, -10, GETDATE()), [Updated]) > 0 ORDER BY [Updated] DESC". \ format(self.person.PeopleId) for check in q.QuerySql(checks_sql, self.person.PeopleId): check_status = 0 if check.StatusID >= 2: # Check has begun check_status = check_status | self.Statuses['CHECK_STARTED'] if check.StatusID == 3: # Check is complete check_status = check_status | self.Statuses[ 'CHECK_COMPLETE'] if check.IssueCount == 0: check_status = check_status | self.Statuses[ 'REVIEW_COMPLETE'] | self.Statuses['PASSED'] else: check_status = check_status | self.Statuses[ 'REVIEW_COMPLETE'] # TODO: establish a means for checks to pass with issues. if check.ServiceCode == "" and check.ReportLabelID == 1: # PA Employee self.statusHis[ 'paEmp'] = self.statusHis['paEmp'] | check_status if DateTime.Compare(check.Updated, self.Renewals['paEmp']) > 0: self.statusExp[ 'paEmp'] = self.statusExp['paEmp'] | check_status if DateTime.Compare(check.Updated, self.Expirations['paEmp']) > 0: self.statusCur[ 'paEmp'] = self.statusCur['paEmp'] | check_status if check.ServiceCode == "ComboPS": # PA Volunteer self.statusHis[ 'paVol'] = self.statusHis['paVol'] | check_status if DateTime.Compare(check.Updated, self.Renewals['paVol']) > 0: self.statusExp[ 'paVol'] = self.statusExp['paVol'] | check_status if DateTime.Compare(check.Updated, self.Expirations['paVol']) > 0: self.statusCur[ 'paVol'] = self.statusCur['paVol'] | check_status if check.ServiceCode == "Combo" or check.ServiceCode == "ComboPS" or check.ServiceCode == "": # Basic self.statusHis[ 'basic'] = self.statusHis['basic'] | check_status if DateTime.Compare(check.Updated, self.Renewals['basic']) > 0: self.statusExp[ 'basic'] = self.statusExp['basic'] | check_status if DateTime.Compare(check.Updated, self.Expirations['basic']) > 0: self.statusCur[ 'basic'] = self.statusCur['basic'] | check_status # MINOR'S WAIVER if self.person.BirthYear is not None and self.person.BirthDate > self.Expirations[ 'isMin']: self.statusCur['isMin'] = self.Statuses['CHECK_STARTED'] | self.Statuses['CHECK_COMPLETE'] | \ self.Statuses['REVIEW_COMPLETE'] | self.Statuses['PASSED'] if self.person.BirthYear is not None and self.person.BirthDate > self.Renewals[ 'isMin']: self.statusExp['isMin'] = self.Statuses['CHECK_STARTED'] | self.Statuses['CHECK_COMPLETE'] | \ self.Statuses['REVIEW_COMPLETE'] | self.Statuses['PASSED'] # FBI Fingerprinting for doc in self.person.VolunteerForms: rx = Regex( "(?<docType>\w+)\s+(?<date>[0-9]{1,2}/[0-9]{1,2}/[0-9]{4})", RegexOptions.Compiled | RegexOptions.IgnoreCase) rm = rx.Match(doc.Name) if not rm.Success: continue if rm.Groups['docType'].Value.ToLower() == "fbi": dt = Convert.ToDateTime(rm.Groups['date'].Value) # TODO impose some form of verification here. check_status = self.Statuses['CHECK_STARTED'] | self.Statuses['CHECK_COMPLETE'] | \ self.Statuses['REVIEW_COMPLETE'] | self.Statuses['PASSED'] self.statusHis[ 'fingr'] = self.statusHis['fingr'] | check_status if DateTime.Compare(dt, self.Renewals['fingr']) > 0: self.statusExp[ 'fingr'] = self.statusExp['fingr'] | check_status if DateTime.Compare(dt, self.Expirations['fingr']) > 0: self.statusCur[ 'fingr'] = self.statusCur['fingr'] | check_status self.statusSet = True
def merge(left, right, key, order): # init return list ret = [] # init position in left and right lists leftPos = 0 rightPos = 0 # get the length of the two lists lenLeft = len(left) lenRight = len(right) # merge the lists if (order == None or order == "0"): while (leftPos < lenLeft and rightPos < lenRight): if (String.Compare(key, "SubmitDateTime", True) != 0): # Normal String Compare if (left[leftPos] == None): leftPos += 1 elif (right[rightPos] == None): rightPos += 1 elif (String.Compare(left[leftPos][key], right[rightPos][key], True) <= 0): ret.append(left[leftPos]) leftPos += 1 else: ret.append(right[rightPos]) rightPos += 1 else: # Compare Dates if (left[leftPos] == None): leftPos += 1 elif (right[rightPos] == None): rightPos += 1 else: try: if (DateTime.Compare( DateTime.Parse(left[leftPos][key]), DateTime.Parse(right[rightPos][key])) >= 0): ret.append(left[leftPos]) leftPos += 1 else: ret.append(right[rightPos]) rightPos += 1 except: leftPos += 1 else: while (leftPos < lenLeft and rightPos < lenRight): if (String.Compare(key, "SubmitDateTime", True) != 0): # Normal String Compare if (left[leftPos] == None): leftPos += 1 elif (right[rightPos] == None): rightPos += 1 elif (String.Compare(left[leftPos][key], right[rightPos][key], True) >= 0): ret.append(left[leftPos]) leftPos += 1 else: ret.append(right[rightPos]) rightPos += 1 else: # Compare Dates if (left[leftPos] == None): leftPos += 1 elif (right[rightPos] == None): rightPos += 1 else: try: if (DateTime.Compare( DateTime.Parse(left[leftPos][key]), DateTime.Parse(right[rightPos][key])) <= 0): ret.append(left[leftPos]) leftPos += 1 else: ret.append(right[rightPos]) rightPos += 1 except: leftPos += 1 # extend ret with the remaining list if (leftPos < lenLeft): while (leftPos < lenLeft): if (left[leftPos] == None): leftPos += 1 else: ret.append(left[leftPos]) leftPos += 1 else: while (rightPos < lenRight): if (right[rightPos] == None): rightPos += 1 else: ret.append(right[rightPos]) rightPos += 1 return ret
def __main__(dlArgs, qsArgs): returnVal = "" sb = StringBuilder() # Get the args egosort = qsArgs["ego"] if "ego" in qsArgs else None primarysort = qsArgs["psort"] if "psort" in qsArgs else None primarysortorder = qsArgs["psord"] if "psord" in qsArgs else None secondarysort = qsArgs["ssort"] if "ssort" in qsArgs else None secondarysortorder = qsArgs["ssord"] if "ssord" in qsArgs else None pulseaddress = qsArgs["pulse"] if "pulse" in qsArgs else None lastupdate = qsArgs["update"] if "update" in qsArgs else None nonplist = qsArgs["plist"] if "plist" in qsArgs else None # parse the last update if (lastupdate != None): lastupdate = fromPlatformIndDateTime( lastupdate ) #BUG possibility when starting the app for the first time - unable to reproduce # check if plist is wanted or not if (nonplist != None): usePlist = False else: usePlist = True plugins = {} users = {} statuses = {} groups = {} pools = {} thisAddress = ClientUtils.GetMacAddress() jobs = WebServiceUtils.GetJobs() # do the sorts if (secondarysort != None): jobs = SortDictArrayByKey(jobs, secondarysort, secondarysortorder) if (primarysort != None): jobs = SortDictArrayByKey(jobs, primarysort, primarysortorder) if (egosort != None): jobs = EgoSortDictArray(jobs, egosort) if (usePlist == False): sb.AppendLine("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>") sb.AppendLine("<jobList>") # add each job for job in jobs: if (job != None and job["Status"] != "Deleted"): try: lastJobUpdate = DateTime.Parse(job["LastWriteTime"]) except: lastJobUpdate = None # if there was no update time given, or the update time is before this jobs last update if (lastupdate == None or pulseaddress != thisAddress or DateTime.Compare(lastupdate, lastJobUpdate) < 0): sb.AppendLine("\t<job>") sb.AppendLine("\t\t<name>" + SecurityElement.Escape(job["Name"]) + "</name>") sb.AppendLine("\t\t<comment>" + SecurityElement.Escape(job["Comment"]) + "</comment>") sb.AppendLine("\t\t<plugin>" + job["PluginName"] + "</plugin>") sb.AppendLine("\t\t<uname>" + job["UserName"] + "</uname>") sb.AppendLine("\t\t<status>" + job["Status"] + "</status>") sb.AppendLine("\t\t<jobid>" + job["JobId"] + "</jobid>") sb.AppendLine("\t\t<taskcount>" + job["TaskCount"] + "</taskcount>") sb.AppendLine("\t\t<completed>" + job["CompletedChunks"] + "</completed>") sb.AppendLine("\t\t<errors>" + job["ErrorReports"] + "</errors>") sb.AppendLine("\t\t<group>" + job["Group"] + "</group>") sb.AppendLine("\t\t<pool>" + job["Pool"] + "</pool>") sb.AppendLine("\t</job>") # if the job is up to date, just print it's id to retrieve its data else: sb.AppendLine("\t<string>" + job["JobId"] + "</string>") plugins[job["PluginName"]] = True users[job["UserName"]] = True statuses[job["Status"]] = True groups[job["Group"]] = True pools[job["Pool"]] = True # meta dictionary sb.AppendLine("\t<meta>") # add each section listKeys("plugin", plugins, sb, False) listKeys("uname", users, sb, False) listKeys("status", statuses, sb, False) listKeys("group", groups, sb, False) listKeys("pool", pools, sb, False) # add the new update time sb.AppendLine("\t\t<update>" + toPlatformIndDateTime(DateTime.Now) + "</update>") # add Pulse's mac address sb.AppendLine("\t\t<pulse>" + thisAddress + "</pulse>") sb.AppendLine("\t</meta>") sb.AppendLine("</jobList>") returnVal = sb.ToString() else: sb.AppendLine("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>") sb.AppendLine( "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">" ) sb.AppendLine("<plist version=\"1.0\">") sb.AppendLine("<dict>") # jobs array sb.AppendLine("\t<key>jobs</key>") sb.AppendLine("\t<array>") # add each job for job in jobs: if (job != None and job["Status"] != "Deleted"): try: lastJobUpdate = DateTime.Parse(job["LastWriteTime"]) except: lastJobUpdate = None # if there was no update time given, or the update time is before this jobs last update if (lastupdate == None or pulseaddress != thisAddress or DateTime.Compare(lastupdate, lastJobUpdate) < 0): sb.AppendLine("\t\t<dict>") sb.AppendLine("\t\t\t<key>name</key><string>" + SecurityElement.Escape(job["Name"]) + "</string>") sb.AppendLine("\t\t\t<key>comment</key><string>" + SecurityElement.Escape(job["Comment"]) + "</string>") sb.AppendLine("\t\t\t<key>plugin</key><string>" + job["PluginName"] + "</string>") sb.AppendLine("\t\t\t<key>uname</key><string>" + job["UserName"] + "</string>") sb.AppendLine("\t\t\t<key>status</key><string>" + job["Status"] + "</string>") sb.AppendLine("\t\t\t<key>jobid</key><string>" + job["JobId"] + "</string>") sb.AppendLine("\t\t\t<key>taskcount</key><string>" + job["TaskCount"] + "</string>") sb.AppendLine("\t\t\t<key>completed</key><string>" + job["CompletedChunks"] + "</string>") sb.AppendLine("\t\t\t<key>errors</key><string>" + job["ErrorReports"] + "</string>") sb.AppendLine("\t\t\t<key>group</key><string>" + job["Group"] + "</string>") sb.AppendLine("\t\t\t<key>pool</key><string>" + job["Pool"] + "</string>") sb.AppendLine("\t\t</dict>") # if the job is up to date, just print it's id to retrieve its data else: sb.AppendLine("\t\t<string>" + job["JobId"] + "</string>") plugins[job["PluginName"]] = True users[job["UserName"]] = True statuses[job["Status"]] = True groups[job["Group"]] = True pools[job["Pool"]] = True sb.AppendLine("\t</array>") # meta dictionary sb.AppendLine("\t<key>meta</key>") sb.AppendLine("\t<dict>") # add each section listKeys("plugin", plugins, sb, True) listKeys("uname", users, sb, True) listKeys("status", statuses, sb, True) listKeys("group", groups, sb, True) listKeys("pool", pools, sb, True) # add the new update time sb.AppendLine("\t\t<key>update</key>") sb.AppendLine("\t\t<string>" + toPlatformIndDateTime(DateTime.Now) + "</string>") # add Pulse's mac address sb.AppendLine("\t\t<key>pulse</key>") sb.AppendLine("\t\t<string>" + thisAddress + "</string>") sb.AppendLine("\t</dict>") sb.AppendLine("</dict>") sb.AppendLine("</plist>") returnVal = sb.ToString() return returnVal