def json_command(regulation_files, from_notices=[], check_terms=False, skip_diffs=False): """ Generate JSON from RegML files """ # If the "file" is a directory, assume we want to operate on all the # files in that directory in listing order if os.path.isdir(find_file(regulation_files[0])): regulation_dir = find_file(regulation_files[0]) regulation_files = [os.path.join(regulation_dir, f) for f in os.listdir(regulation_dir)] # Generate JSON for each version versions = {} reg_number = None for file in regulation_files: print("Building JSON for {}".format(file)) reg_number, notice, reg_xml_tree = generate_json( file, check_terms=check_terms) versions[notice] = reg_xml_tree # Generate diff JSON between each version # now build diffs - include "empty" diffs comparing a version to itself if not skip_diffs: print(colored("\nBuilding inter-version diffs.", attrs=['bold'])) print(colored("WARNING: This may take an extended period of time.", 'red', attrs=['bold'])) print("To skip diff creation, use the --skip_diffs command line argument.\n") for left_version, left_tree in versions.items(): for right_version, right_tree in versions.items(): diff = generate_diff(left_tree, right_tree) write_layer(diff, reg_number, right_version, 'diff', diff_notice=left_version)
def json_command(regulation_files, from_notices=[], check_terms=False): """ Generate JSON from RegML files """ # If the "file" is a directory, assume we want to operate on all the # files in that directory in listing order if os.path.isdir(find_file(regulation_files[0])): regulation_dir = find_file(regulation_files[0]) regulation_files = [os.path.join(regulation_dir, f) for f in os.listdir(regulation_dir)] # Generate JSON for each version versions = {} reg_number = None for file in regulation_files: reg_number, notice, reg_xml_tree = generate_json( file, check_terms=check_terms) versions[notice] = reg_xml_tree # Generate diff JSON between each version # now build diffs - include "empty" diffs comparing a version to itself for left_version, left_tree in versions.items(): for right_version, right_tree in versions.items(): diff = generate_diff(left_tree, right_tree) write_layer(diff, reg_number, right_version, 'diff', diff_notice=left_version)
def test_generate_diff_modified(self): left_xml = etree.fromstring(""" <regulation xmlns="eregs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="eregs ../../eregs.xsd"> <fdsys> <title>TEST CASE RUNNING ACT</title> </fdsys> <preamble> <cfr> <section>1234</section> </cfr> </preamble> <part label="1234"> <content> <subpart> <content> <section label="1234-1" sectionNum="1"> <subject>§ 1234.1 Changing a paragraph</subject> <paragraph label="1234-1-a" marker="(a)"> <title type="keyterm">Existing.</title> <content>An existing paragraph</content> </paragraph> </section> </content> </subpart> </content> </part> </regulation>""") right_xml = etree.fromstring(""" <regulation xmlns="eregs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="eregs ../../eregs.xsd"> <fdsys> <title>TEST CASE RUNNING ACT</title> </fdsys> <preamble> <cfr> <section>1234</section> </cfr> </preamble> <part label="1234"> <content> <subpart> <content> <section label="1234-1" sectionNum="1"> <subject>§ 1234.1 Changing a paragraph</subject> <paragraph label="1234-1-a" marker="(a)"> <title type="keyterm">Modified.</title> <content>A modified paragraph</content> </paragraph> </section> </content> </subpart> </content> </part> </regulation>""") diff = generate_diff(left_xml, right_xml) self.assertEqual(len(diff.keys()), 1) self.assertTrue('1234-1-a' in diff) self.assertEqual(diff['1234-1-a']['op'], 'modified')