Beispiel #1
0
    def test_deleted(self):
        # mark_deleted function expects everything to be in lower case
        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)
Beispiel #2
0
    def handle(self, *args, **options):
        type_of_run = options['type']

        if type_of_run == 'full':
            git_update.refresh_portindex_json()
            data = git_update.get_portindex_json()
            if data is None:
                raise CommandError("Failed to parse portindex.json")
            Port.add_or_update(data['ports'])
            Port.mark_deleted_full_run(data['ports'])
            LastPortIndexUpdate.update_or_create_first_object(
                data['info']['commit'])
            return

        # It is an incremental update
        # An incremental update is only possible when the database has a
        # history of the commit till which it is up to date
        old_commit_object = LastPortIndexUpdate.objects.all().first()
        if old_commit_object is None:
            raise CommandError(
                "Failed to run incremental update. No old commit found, cannot generate range of commits."
            )

        updated_portdirs = git_update.get_updated_portdirs()

        # fetch the latest version of PortIndex.json and open the file
        data = git_update.get_portindex_json()
        if data is None:
            raise CommandError("Failed to parse portindex.json")

        # 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.add_or_update(ports_to_be_updated_json)

        # Write the commit hash into database
        LastPortIndexUpdate.update_or_create_first_object(
            data['info']['commit'])
Beispiel #3
0
 def test_added_back(self):
     Port.mark_deleted({'categoryA/port-A1': {'port-A1'}})
     Port.add_or_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)
Beispiel #4
0
    def test_moved(self):
        Port.add_or_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.add_or_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)