def main(): db = _db.Database(fs.path("joblist.db")) data = [row for row in db.execute("SELECT device,Count(*) AS count\n" "FROM jobs\n" "GROUP BY device\n" "ORDER BY count")] io.info("Job list:") print(fmt.table(data, columns=("Device", "Jobs"))) print() jobs = [row for row in db.execute("SELECT * FROM jobs")] fs.mkdir("jobs") logs = { "monza": open("jobs/monza.txt", "w"), "whz5": open("jobs/whz5.txt", "w"), "monza": open("jobs/monza.txt", "w"), "cec": open("jobs/cec.txt", "w"), "florence": open("jobs/florence.txt", "w"), } for job in jobs: enum_job(logs, db, *job) lab.exit()
def parse_wc(input, output=stdout, match_pattern=None): match_re = compile(match_pattern) if match_pattern else None files = [] # State. infile = False file = None # Iterate over lines in the input. for line in input.readlines(): if infile: match = search(_WORDS_IN_TEXT_RE, line) if match: files.append((file, int(match.group(1)))) infile = False else: match = search(_FILE_RE, line) if match: file = sub(".tex$", "", match.group(1)) if match_re: if search(match_re, file): infile = True else: infile = True total = sum([x[1] for x in files]) files.append(("Total", total)) # Print word counts. print(fmt.table(files, justify="left"))
def main(): db = _db.Database(fs.path("joblist.db")) data = [ row for row in db.execute("SELECT device,Count(*) AS count\n" "FROM jobs\n" "GROUP BY device\n" "ORDER BY count") ] io.info("Job list:") print(fmt.table(data, columns=("Device", "Jobs"))) print() jobs = [row for row in db.execute("SELECT * FROM jobs")] fs.mkdir("jobs") logs = { "monza": open("jobs/monza.txt", "w"), "whz5": open("jobs/whz5.txt", "w"), "monza": open("jobs/monza.txt", "w"), "cec": open("jobs/cec.txt", "w"), "florence": open("jobs/florence.txt", "w"), } for job in jobs: enum_job(logs, db, *job) lab.exit()
def test_table_bad_rows(): with pytest.raises(fmt.Error): fmt.table((("foo", 1), ("bar", 2), ("car", )))
def test_table_bad_columns(): with pytest.raises(fmt.Error): fmt.table((("foo", 1), ("bar", 2)), columns=("type", "value", "too", "many", "values"))
def test_table_columns(): assert ((["type", "value", "foo", "1", "bar", "2"]) == fmt.table( (("foo", 1), ("bar", 2)), columns=("type", "value")).split())
def test_table(): assert (["foo", "1", "bar", "2"] == fmt.table( (("foo", 1), ("bar", 2))).split())
def test_table_bad_rows(self): with self.assertRaises(fmt.Error): fmt.table((("foo", 1), ("bar", 2), ("car",)))
def test_table_bad_columns(self): with self.assertRaises(fmt.Error): fmt.table((("foo", 1), ("bar", 2)), columns=("type", "value", "too", "many", "values"))
def test_table_columns(self): self._test((["type", "value", "foo", "1", "bar", "2"]), fmt.table((("foo", 1), ("bar", 2)), columns=("type", "value")).split())
def test_table(self): self._test(["foo","1", "bar", "2"], fmt.table((("foo", 1), ("bar", 2))).split())