def check(self, name, file, inputCr): text = self.load(file, inputCr) shouldFail = name[0:4] == "fail" try: data = hjson.loads(text) self.assertFalse(shouldFail, file) text1 = hjson.dumpsJSON(data) hjson1 = hjson.dumps(data, ensure_ascii=False); result = hjson.loads(self.load(name + "_result.json", inputCr)) text2 = hjson.dumpsJSON(result) hjson2 = self.load(name + "_result.hjson", False) # dbg # with open(name + "_dbg1.txt", "w") as tmp: tmp.write(hjson1.encode("utf-8")) # with open(name + "_dbg2.txt", "w") as tmp: tmp.write(hjson2.encode("utf-8")) # with codecs.open(name + "_dbg3.txt", 'w', 'utf-8') as tmp: hjson.dump(data, tmp) if self.verma>2 or self.vermi>6: # final check fails on py2.6 because of string formatting issues self.assertEqual(text2, text1, file) self.assertEqual(hjson2, hjson1, file) except hjson.HjsonDecodeError as e: if not shouldFail: self.fail("raised error on parsing %s: %r" % (file, e))
def check(self, name, file, inputCr): text = self.load(file, inputCr) shouldFail = name[0:4] == "fail" try: data = hjson.loads(text) self.assertFalse(shouldFail) text1 = hjson.dumpsJSON(data) hjson1 = hjson.dumps(data, ensure_ascii=False); result = hjson.loads(self.load(name + "_result.json", inputCr)) text2 = hjson.dumpsJSON(result) hjson2 = self.load(name + "_result.hjson", False) if self.verma>2 or self.vermi>6: # final check fails on py2.6 because of string formatting issues self.assertEqual(text2, text1) self.assertEqual(hjson2, hjson1) # dbg # with open(name + "_dbg1.txt", "w") as tmp: tmp.write(hjson1.encode("utf-8")) # with open(name + "_dbg2.txt", "w") as tmp: tmp.write(hjson2.encode("utf-8")) except hjson.HjsonDecodeError as e: self.assertTrue(shouldFail)
def fill_bug(config, nags, rrajsondoc): bcfg = config['bugzilla'] # If no API key has been specified, just skip this if len(bcfg['api_key']) == 0: return b = bugzilla.Bugzilla(url=bcfg['url'], api_key=bcfg['api_key']) #Did we already report this? terms = [{'product': bcfg['product']}, {'component': bcfg['component']}, {'creator': bcfg['creator']}, {'whiteboard': 'autoentry'}, {'resolution': ''},{'status': 'NEW'}, {'status': 'ASSIGNED'}, {'status': 'REOPENED'}, {'status': 'UNCONFIRMED'}, {'whiteboard': 'rra2json={}'.format(rrajsondoc.source)} ] bugs = b.search_bugs(terms)['bugs'] try: bugzilla.DotDict(bugs[-1]) debug("bug for {} is already present, not re-filling".format(rrajsondoc.source)) return except IndexError: pass #If not, report now bug = bugzilla.DotDict() bug.product = bcfg['product'] bug.component = bcfg['component'] bug.summary = "There are {} issues with an RRA".format(len(nags)) bug.description = json.dumps(nags) bug.whiteboard = 'autoentry rra2json={}'.format(rrajsondoc.source) if 'analyst' in rrajsondoc.details.metadata: bug.assigned_to = rrajsondoc.details.metadata.analyst try: ret = b.post_bug(bug) debug("Filled bug {} {}".format(rrajsondoc.source, ret)) except Exception as e: # Code 51 = assigned_to user does not exist, just assign to default then url, estr, ecode, edict = e.args if edict['code'] == 51: del bug.assigned_to try: ret = b.post_bug(bug) debug("Filled bug {} {}".format(rrajsondoc.source, ret)) except Exception as e1: debug("Filling bug failed: {}".format(e1)) else: debug("Filling bug failed: {}".format(e))
def fill_bug(config, nags, source): bcfg = config['bugzilla'] # If no API key has been specified, just skip this if len(bcfg['api_key']) == 0: return b = bugzilla.Bugzilla(url=bcfg['url'], api_key=bcfg['api_key']) #Did we already report this? terms = [{'product': bcfg['product']}, {'component': bcfg['component']}, {'creator': bcfg['creator']}, {'whiteboard': 'autoentry'}, {'resolution': ''},{'status': 'NEW'}, {'status': 'ASSIGNED'}, {'status': 'REOPENED'}, {'status': 'UNCONFIRMED'}, {'whiteboard': 'rra2json={}'.format(source)} ] bugs = b.search_bugs(terms)['bugs'] try: bugzilla.DotDict(bugs[-1]) debug("bug for {} is already present, not re-filling".format(source)) return except IndexError: pass #If not, report now bug = bugzilla.DotDict() bug.product = bcfg['product'] bug.component = bcfg['component'] bug.summary = "There are {} issues with an RRA".format(len(nags)) bug.description = json.dumps(nags) bug.whiteboard = 'autoentry rra2json={}'.format(source) try: ret = b.post_bug(bug) except e: debug("Filling bug failed: {}".format(e)) debug("Filled bug {} {}".format(source, ret))
def _json_clone(self, j): return hjson.loads(hjson.dumps(j))
def dict_to_cfg(data_dict): data_h = hjson.dumps(data_dict) text = re.sub('\}', '};', re.sub('\]', ');', re.sub('\[', '(', data_h))) text = text[:-2].lstrip('{') return text