Esempio n. 1
0
    def test_add_to_config(self):
        # add storage mirrors to config
        config = self.repo.get_config()
        StorageManager.add_to_config(self.repo, config)

        # assert that we now have storage mirror in the config
        self.assertTrue(len(config['mirrors']) == 1)
        url = 'https://example.com/repos/WRK98dKjNKjR5XJy5sjH_Ptuxrs4QgNK/repo'
        self.assertEqual(url, config['mirrors'][0])
Esempio n. 2
0
    def test_add_to_config(self):
        # get config from repo and assert that it doesn't contain storage mirrors
        config = self.repo.get_config()
        self.assertFalse('mirrors' in config)

        # add existing storage mirrors to config
        StorageManager.add_to_config(self.repo, config)

        # assert that we now have all the storage mirrors in the config
        self.assertTrue('mirrors' in config)
        self.assertTrue(len(config['mirrors']) == 3)
        self.assertTrue('https://s3.amazonaws.com/s3_bucket/fdroid/repo' in
                        config['mirrors'])
        self.assertTrue('ssh_url' in config['mirrors'])
        self.assertTrue('git_url/repo' in config['mirrors'])
Esempio n. 3
0
    def update(self):
        """
        Updates the repository on disk, generates index, categories, etc.

        You normally don't need to call this directly
        as it is meant to be run in a background task scheduled by update_async().
        """
        from repomaker.models import App, ApkPointer
        from repomaker.models.storage import StorageManager
        self.chdir()
        config = self.get_config()
        StorageManager.add_to_config(self, config)

        # ensure that this repo's main URL is set prior to updating
        if not self.url and len(config['mirrors']) > 0:
            self.set_url(config['mirrors'][0])

        # Gather information about all the apk files in the repo directory, using
        # cached data if possible.
        apkcache = update.get_cache()

        # Process all apks in the main repo
        knownapks = common.KnownApks()
        apks, cache_changed = update.process_apks(apkcache, REPO_DIR,
                                                  knownapks, False)

        # Apply app metadata from database
        apps = {}
        categories = set()
        for apk in apks:
            try:
                app = App.objects.get(
                    repo=self,
                    package_id=apk['packageName']).to_metadata_app()
                apps[app.id] = app
                categories.update(app.Categories)
            except ObjectDoesNotExist:
                logging.warning("App '%s' not found in database",
                                apk['packageName'])

        # Scan non-apk files in the repo
        files, file_cache_changed = update.scan_repo_files(
            apkcache, REPO_DIR, knownapks, False)

        # Apply metadata from database
        for file in files:
            pointers = ApkPointer.objects.filter(repo=self,
                                                 apk__hash=file['hash'])
            if not pointers.exists():
                logging.warning("App with hash '%s' not found in database",
                                file['hash'])
            elif pointers.count() > 1:
                logging.error("Repo %d has more than one app with hash '%s'",
                              self.pk, file['hash'])
            else:
                # add app to list of apps to be included in index
                pointer = pointers[0]
                app = pointer.app.to_metadata_app()
                apps[pointer.app.package_id] = app
                categories.update(app.Categories)

                # update package data and add to repo files
                file['name'] = pointer.app.name
                file['versionCode'] = pointer.apk.version_code
                file['versionName'] = pointer.apk.version_name
                file['packageName'] = pointer.apk.package_id
                apks.append(file)

        update.apply_info_from_latest_apk(apps, apks)

        # Sort the app list by name
        sortedids = sorted(apps.keys(),
                           key=lambda app_id: apps[app_id].Name.upper())

        # Make the index for the repo
        index.make(apps, sortedids, apks, REPO_DIR, False)
        update.make_categories_txt(REPO_DIR, categories)

        # Update cache if it changed
        if cache_changed or file_cache_changed:
            update.write_cache(apkcache)

        # Update repo page
        self._generate_page()