def test_deleted(self): Port.mark_deleted({'categoryA/port-A1': {'port-A1'}}) port_status_subport = Port.objects.get(name='port-A1-subport').active port_status_mainport = Port.objects.get(name='port-A1').active self.assertEquals(port_status_mainport, True) self.assertEquals(port_status_subport, False)
def test_added_back(self): Port.mark_deleted({ 'categoryA/port-A1': { 'port-A1' } }) Port.update([ { "variants": ["universal"], "portdir": "categoryA\/port-A1", "depends_fetch": ["bin:port-A4:port-A4"], "description": "This is port A1 of categoryA", "homepage": "http:\/\/portA1.website\/", "epoch": "0", "platforms": "darwin", "name": "port-A1-subport", "depends_lib": ["lib:pq:port-A2", "port:port-A3-diff"], "long_description": "Just a test port written to test something.", "license": "MIT", "maintainers": [{ "email": { "domain": "email.com", "name": "user" }, "github": "user" }], "categories": ["categoryA"], "version": "1.0.0", "revision": "0" } ]) port_status = Port.objects.get(name='port-A1-subport').active self.assertEquals(port_status, True)
def test_deleted(self): Port.mark_deleted({'categoryA/port-A1': {'port-A1': True}}) port_status = Port.objects.get(name='port-A1-subport').active for port in Port.objects.all(): print(port.name) self.assertEquals(port_status, False)
def handle(self, *args, **options): # Fetch the latest version of PortIndex.json and open the file data = Port.PortIndexUpdateHandler().sync_and_open_file() # If no argument is provided, use the commit-hash from JSON file: if options['new_commit'] is None: new_commit = data['info']['commit'] # If argument is provided else: new_commit = options['new_commit'] # If no argument is provided, options['old_commit'] will default to None # The code will then use the commit from last update which is stored in the database updated_portdirs = git_update.get_list_of_changed_ports( new_commit, options['old_commit']) # Generate a dictionary containing all the portdirs and initialise their values # with empty sets. The set would contain the ports under that portdir. dict_of_portdirs_with_ports = {} for portdir in updated_portdirs: dict_of_portdirs_with_ports[portdir] = set() # Using the received set of updated portdirs, find corresponding JSON objects for all ports under # that portdir. ports_to_be_updated_json = [] for port in data['ports']: portdir = port['portdir'].lower() portname = port['name'].lower() if portdir in updated_portdirs: ports_to_be_updated_json.append(port) dict_of_portdirs_with_ports[portdir].add(portname) # Mark deleted ports Port.mark_deleted(dict_of_portdirs_with_ports) # Run updates Port.update(ports_to_be_updated_json) # Write the commit hash into database LastPortIndexUpdate.update_or_create_first_object( data['info']['commit'])
def handle(self, *args, **options): # Fetch the latest version of PortIndex.json and open the file data = Port.PortIndexUpdateHandler().sync_and_open_file() # If no argument is provided, use the commit-hash from JSON file: if options['new_commit'] is None: new_commit = data['info']['commit'] # If argument is provided else: new_commit = options['new_commit'] # If no argument is provided, options['old_commit'] will default to None # The code will then use the commit from last update which is stored in the database updated_portdirs = git_update.get_list_of_changed_ports( new_commit, options['old_commit']) # Using the received list of port names, find related JSON objects ports_to_be_updated_json = [] found_ports_tree = {} for port in data['ports']: portdir = port['portdir'].lower() portname = port['name'].lower() if portdir in updated_portdirs: ports_to_be_updated_json.append(port) if found_ports_tree.get(portdir) is None: found_ports_tree[portdir] = {} found_ports_tree[portdir][portname] = True # Mark deleted ports Port.mark_deleted(found_ports_tree) # Run updates Port.update(ports_to_be_updated_json) # Write the commit hash into database LastPortIndexUpdate.update_or_create_first_object( data['info']['commit'])
def test_moved(self): Port.update([{ "variants": ["universal"], "portdir": "categoryA/port-A1", "depends_fetch": ["bin:port-A4:port-A4"], "description": "This is port A1 of categoryA", "homepage": "http:\/\/portA1.website\/", "epoch": "0", "platforms": "darwin", "name": "port-A2-subport", "depends_lib": ["lib:pq:port-A2", "port:port-A3-diff"], "long_description": "Just a test port written to test something.", "license": "MIT", "maintainers": [{ "email": { "domain": "email.com", "name": "user" }, "github": "user" }], "categories": ["categoryA"], "version": "1.0.0", "revision": "0" }, { "variants": ["universal"], "portdir": "categoryA/port-A1", "depends_fetch": ["bin:port-A4:port-A4"], "description": "This is port A1 of categoryA", "homepage": "http:\/\/portA1.website\/", "epoch": "0", "platforms": "darwin", "name": "port-A3-subport", "depends_lib": ["lib:pq:port-A2", "port:port-A3-diff"], "long_description": "Just a test port written to test something.", "license": "MIT", "maintainers": [{ "email": { "domain": "email.com", "name": "user" }, "github": "user" }], "categories": ["categoryA"], "version": "1.0.0", "revision": "0" }]) port_status_subport1 = Port.objects.get(name='port-A1-subport').active port_status_subport2 = Port.objects.get(name='port-A2-subport').active port_status_subport3 = Port.objects.get(name='port-A3-subport').active self.assertEquals(port_status_subport1, True) self.assertEquals(port_status_subport2, True) self.assertEquals(port_status_subport3, True) # Entire categoryA/port-A1 portdir is removed, but the subports move to other directory # All ports under category/port-A1 would be deleted. Port.mark_deleted({'categoryA/port-A1': {}}) port_status_subport1 = Port.objects.get(name='port-A1-subport').active port_status_subport2 = Port.objects.get(name='port-A2-subport').active port_status_subport3 = Port.objects.get(name='port-A3-subport').active self.assertEquals(port_status_subport1, False) self.assertEquals(port_status_subport2, False) self.assertEquals(port_status_subport3, False) # The moved ports would be found at the new location and will be appended to the list of JSON objects Port.update([{ "variants": ["universal"], "portdir": "categoryTemp/newPorts", "depends_fetch": ["bin:port-A4:port-A4"], "description": "This is port A1 of categoryA", "homepage": "http:\/\/portA1.website\/", "epoch": "0", "platforms": "darwin", "name": "port-A2-subport", "depends_lib": ["lib:pq:port-A2", "port:port-A3-diff"], "long_description": "Just a test port written to test something.", "license": "MIT", "maintainers": [{ "email": { "domain": "email.com", "name": "user" }, "github": "user" }], "categories": ["categoryA"], "version": "1.0.0", "revision": "0" }, { "variants": ["universal"], "portdir": "categoryTemp/newPorts", "depends_fetch": ["bin:port-A4:port-A4"], "description": "This is port A1 of categoryA", "homepage": "http:\/\/portA1.website\/", "epoch": "0", "platforms": "darwin", "name": "port-A3-subport", "depends_lib": ["lib:pq:port-A2", "port:port-A3-diff"], "long_description": "Just a test port written to test something.", "license": "MIT", "maintainers": [{ "email": { "domain": "email.com", "name": "user" }, "github": "user" }], "categories": ["categoryA"], "version": "1.0.0", "revision": "0" }]) port_status_subport2 = Port.objects.get(name='port-A2-subport').active port_status_subport3 = Port.objects.get(name='port-A3-subport').active self.assertEquals(port_status_subport2, True) self.assertEquals(port_status_subport3, True)