def get_inputs(self): """ Returns snapshots of the inputs as an array in the same order as specified on initialization. """ headers = self.get_headers() result = [] for h in headers: input_data = StringIO.StringIO(self.snapshot_requester.make_request(h)) input_sections = sectionize(input_data) result.append(input_sections["data"]) return result
def run(self): try: while True: message = io.StringIO(self.rep_socket.recv()) sections = sectionize(message) for header in sections.keys(): if re.match("PUT", header): self.put_resource(header, sections[header], self.header_file_map) elif re.match("GET", header): self.get_resource(header, sections[header], self.header_file_map) else: print(header) self.rep_socket.send_unicode("TODO: Handle %s" % header) except Exception as e: print("EXCEPTION: %s" % str(e)) self.rep_socket.send_unicode("ERROR: %s" % str(e))
def condition_data(self, jira_data, completed_jira): data = json.loads(jira_data) tasks = data['issues'] tracks = tasks.keys() output = StringIO.StringIO() # Load the completed tasks old_complete_tasks = {} completed_sections = sectionize(StringIO.StringIO(completed_jira)) if 'completed tasks' in completed_sections: completed_lines = completed_sections['completed tasks'].split("\n") for line in completed_lines: task = self.parse_completed_task(line) old_complete_tasks[task['key']] = task self.print_complete_tasks(old_complete_tasks, tasks, output) result = output.getvalue() output.close() return result
def get_report(self): """ Generates list (as a string) of PTO days by person. """ output = StringIO.StringIO() # Pull snapshot [cond_vac_data] = self.get_inputs() sections = sectionize(StringIO.StringIO(cond_vac_data)) # Extract sections [start, end] = sections["params"].split("\t") out_lines = sections["outdays"] # Expand dates dates = self.expand_dates(start, end) pto_by_person = self.get_pto_by_person(out_lines) # Print streams self.print_params(start, end, output) self.print_pto_counts(pto_by_person, output) result = output.getvalue() return result
def test_sectionize1(self): input = io.StringIO(happy_input1) result = sectionize.sectionize(input) self.assertEqual("ShortageChart Title", result['title']) return