Esempio n. 1
0
def cache_packages():
    preexisting = set([model.name for model in PackageModel.select()])
    output = []
    for pkg in Package.all():
        pkg_data = dict(
            name =  pkg.name,
            sha1 = pkg.sha1,
            version = pkg.version,
            patchlevel = pkg.patchlevel,
            filename = pkg.tarball_filename,
            description = gracefully_read(pkg, 'SPKG.txt'),
            pkgtype = gracefully_read(pkg, 'type'),
        )
        try:
            with database.atomic():
                model = PackageModel.create(**pkg_data)
        except peewee.IntegrityError:
            PackageModel.update(
                **pkg_data
            ).where(
                PackageModel.name == pkg.name
            ).execute()
        output.append(pformat(pkg_data))
        preexisting.discard(pkg.name)
    for pkg_name in preexisting:
        PackageModel.delete().where(PackageModel.name == pkg_name)
    return '\n'.join(output)
Esempio n. 2
0
    def apropos(self, incorrect_name):
        """
        Find up to 5 package names that are close to the given name

        $ sage --package apropos python
        Did you mean: cython, ipython, python2, python3, patch?
        """
        log.debug('Apropos for %s', incorrect_name)
        from sage_bootstrap.levenshtein import Levenshtein, DistanceExceeded
        levenshtein = Levenshtein(5)
        names = []
        for pkg in Package.all():
            try:
                names.append([levenshtein(pkg.name, incorrect_name), pkg.name])
            except DistanceExceeded:
                pass
        if names:
            names = sorted(names)[:5]
            print('Did you mean: {0}?'.format(', '.join(name[1]
                                                        for name in names)))
        else:
            print('There is no package similar to {0}'.format(incorrect_name))
            print(
                'You can find further packages at http://files.sagemath.org/spkg/'
            )
Esempio n. 3
0
    def __init__(self, tarball_name, package=None):
        """
        A (third-party downloadable) tarball

        Note that the tarball might also be a different kind of
        archive format that is supported, it does not necessarily have
        to be tar.

        INPUT:

        - ``name`` - string. The full filename (``foo-1.3.tar.bz2``)
          of a tarball on the Sage mirror network.
        """
        self.__filename = tarball_name
        if package is None:
            self.__package = None
            for pkg in Package.all():
                if pkg.tarball_filename == tarball_name:
                    self.__package = pkg
            if self.package is None:
                error = 'tarball {0} is not referenced by any Sage package'.format(tarball_name)
                log.error(error)
                raise ValueError(error)
        else:
            self.__package = package
            if package.tarball_filename != tarball_name:
                error = 'tarball {0} is not referenced by the {1} package'.format(tarball_name, package.name)
                log.error(error)
                raise ValueError(error)
Esempio n. 4
0
    def run_list(self):
        """
        list: Print a list of all available packages

        $ sage-package list | sort
        4ti2
        arb
        atlas
        autotools
        [...]
        zn_poly
        """
        for pkg in Package.all():
            print(pkg.name)
Esempio n. 5
0
    def list(self):
        """
        Print a list of all available packages

        $ sage --package list | sort
        4ti2
        arb
        atlas
        autotools
        [...]
        zn_poly
        """
        log.debug('Listing packages')
        for pkg in Package.all():
            print(pkg.name)
Esempio n. 6
0
    def fix_all_checksums(self):
        """
        Fix the checksum of a package

        $ sage --package fix-checksum
        """
        for pkg in Package.all():
            if not os.path.exists(pkg.tarball.upstream_fqn):
                log.debug('Ignoring {0} because tarball is not cached'.format(pkg.tarball_filename))
                continue
            if pkg.tarball.checksum_verifies():
                log.debug('Checksum of {0} (tarball {1}) unchanged'.format(pkg.name, pkg.tarball_filename))
                continue
            update = ChecksumUpdater(pkg.name)
            print('Updating checksum of {0} (tarball {1})'.format(pkg.name, pkg.tarball_filename))
            update.fix_checksum()
Esempio n. 7
0
    def fix_all_checksums(self):
        """
        Fix the checksum of a package

        $ sage --package fix-checksum
        """
        for pkg in Package.all():
            if not os.path.exists(pkg.tarball.upstream_fqn):
                log.debug('Ignoring {0} because tarball is not cached'.format(pkg.tarball_filename))
                continue
            if pkg.tarball.checksum_verifies():
                log.debug('Checksum of {0} unchanged'.format(pkg.tarball_filename))
                continue
            update = ChecksumUpdater(pkg.name)
            print('Updating checksum of {0}'.format(pkg.tarball_filename))
            update.fix_checksum()
Esempio n. 8
0
    def run_apropos(self, incorrect_name):
        """
        apropos: Find up to 5 package names that are close to the given name

        $ sage-package apropos python
        Did you mean: cython, ipython, python2, python3, patch?
        """
        from sage_bootstrap.levenshtein import Levenshtein, DistanceExceeded
        levenshtein = Levenshtein(5)
        names = []
        for pkg in Package.all():
            try:
                names.append([levenshtein(pkg.name, incorrect_name), pkg.name])
            except DistanceExceeded:
                pass
        if names:
            names = sorted(names)[:5]
            print('Did you mean: {0}?'.format(', '.join(name[1] for name in names)))
        else:
            print('There is no package similar to {0}'.format(incorrect_name))
            print('You can find further packages at http://files.sagemath.org/spkg/')
Esempio n. 9
0
 def _init_standard(self):
     self.names = [
         pkg.name for pkg in Package.all() if pkg.type == 'standard'
     ]
Esempio n. 10
0
 def _init_huge(self, predicate):
     self.names.extend(pkg.name for pkg in Package.all() if pkg.type == 'huge' and predicate(pkg))
Esempio n. 11
0
 def _init_experimental(self, predicate):
     self.names.extend(pkg.name for pkg in Package.all() if pkg.type == 'experimental' and predicate(pkg))
Esempio n. 12
0
 def _init_optional(self, predicate):
     self.names.extend(pkg.name for pkg in Package.all() if pkg.type == 'optional' and predicate(pkg))
Esempio n. 13
0
 def _init_standard(self, predicate):
     self.names.extend(pkg.name for pkg in Package.all() if pkg.type == 'standard' and predicate(pkg))
Esempio n. 14
0
 def _init_all(self, predicate):
     self.names.extend(pkg.name for pkg in Package.all() if predicate(pkg))
Esempio n. 15
0
 def _init_huge(self):
     self.names = [pkg.name for pkg in Package.all() if pkg.type == 'huge']
Esempio n. 16
0
 def _init_experimental(self):
     self.names = [
         pkg.name for pkg in Package.all() if pkg.type == 'experimental'
     ]
Esempio n. 17
0
 def _init_optional(self):
     self.names = [
         pkg.name for pkg in Package.all() if pkg.type == 'optional'
     ]
Esempio n. 18
0
 def _init_all(self):
     self.names = [pkg.name for pkg in Package.all()]
Esempio n. 19
0
 def test_all(self):
     pari = Package('pari')
     self.assertTrue(pari in Package.all())
Esempio n. 20
0
 def test_all(self):
     pari = Package('pari')
     self.assertTrue(pari in Package.all())