Exemplo 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)
Exemplo n.º 2
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)
Exemplo n.º 3
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/'
            )
Exemplo n.º 4
0
 def test_tarball(self):
     pkg = Package('configure')
     rc, stdout, stderr = self.run_command(EXECUTABLE, 'tarball', pkg.name)
     # Prints nothing to stderr
     self.assertEqual(stderr, '')
     # returns successfully
     self.assertEqual(rc, 0)
     # Prints to stdout
     self.assertEqual(stdout.rstrip(), pkg.tarball_filename)
Exemplo n.º 5
0
 def run_tarball(self, package_name):
     """
     tarball: Find the tarball filename given a package name
 
     $ sage-package tarball pari
     pari-2.8-1564-gdeac36e.tar.gz
     """
     package = Package(package_name)
     print(package.tarball.filename)
Exemplo n.º 6
0
 def update(self):
     package = Package(self.name)
     if package.version == self.version:
         log.info('%s is already at the latest version', self.name)
         return
     log.info('Updating %s: %s -> %s', self.name, package.version,
              self.version)
     update = PackageUpdater(self.name, self.version)
     update.download_upstream(self.url)
     update.fix_checksum()
Exemplo n.º 7
0
 def tarball(self, package_name):
     """
     Find the tarball filename given a package name
 
     $ sage --package tarball pari
     pari-2.8-1564-gdeac36e.tar.gz
     """
     log.debug('Looking up tarball name for %s', package_name)
     package = Package(package_name)
     print(package.tarball.filename)
Exemplo n.º 8
0
 def test_tarball(self):
     pkg = Package('configure')
     tarball = Tarball(pkg.tarball_filename)
     self.assertEqual(tarball, pkg.tarball)
     self.assertEqual(pkg, tarball.package)
     with CapturedOutput() as (stdout, stderr):
         with CapturedLog() as _:
             tarball.download()
     self.assertEqual(stdout.getvalue(), '')
     self.assertTrue(tarball.checksum_verifies())
Exemplo n.º 9
0
 def test_download(self):
     pkg = Package('configure')
     with CapturedLog() as _:
         pkg.tarball.download()
     rc, stdout, stderr = self.run_command(EXECUTABLE, 'download', pkg.name)
     # Prints info to stderr
     self.assertTrue(stderr.startswith('Using cached file'))
     # returns successfully
     self.assertEqual(rc, 0)
     # Prints filename to stdout
     self.assertEqual(stdout.rstrip(), pkg.tarball.upstream_fqn)
Exemplo n.º 10
0
 def test_package(self):
     pkg = Package('pari')
     self.assertTrue(pkg.name, 'pari')
     self.assertTrue(pkg.path.endswith('build/pkgs/pari'))
     self.assertEqual(pkg.tarball_pattern, 'pari-VERSION.tar.gz')
     self.assertEqual(pkg.tarball_filename, pkg.tarball.filename)
     self.assertTrue(pkg.tarball.filename.startswith('pari-') and
                     pkg.tarball.filename.endswith('.tar.gz'))
     self.assertTrue(pkg.tarball.filename.startswith('pari-') and
                     pkg.tarball.filename.endswith('.tar.gz'))
     self.assertTrue(isinstance(pkg.tarball, Tarball))
Exemplo n.º 11
0
 def update_latest(self, package_name):
     """
     Update a package to the latest version. This modifies the Sage sources. 
     """
     try:
         pypi = PyPiVersion(package_name)
     except PyPiNotFound:
         log.debug('%s is not a pypi package', package_name)
         return
     else:
         pypi.update(Package(package_name))
Exemplo n.º 12
0
    def download(self, package_name, allow_upstream=False):
        """
        Download a package

        $ sage --package download pari
        Using cached file /home/vbraun/Code/sage.git/upstream/pari-2.8-2044-g89b0f1e.tar.gz
        /home/vbraun/Code/sage.git/upstream/pari-2.8-2044-g89b0f1e.tar.gz
        """
        log.debug('Downloading %s', package_name)
        package = Package(package_name)
        package.tarball.download(allow_upstream=allow_upstream)
        print(package.tarball.upstream_fqn)
Exemplo n.º 13
0
 def test_update(self):
     pkg = Package('configure')
     # The confball never has a patchlevel since we are upstream...
     self.assertEqual(pkg.patchlevel, -1)
     rc, stdout, stderr = self.run_command(EXECUTABLE, 'update', pkg.name,
                                           pkg.version)
     # Prints nothing to stderr
     self.assertEqual(stderr, '')
     # returns successfully
     self.assertEqual(rc, 0)
     # Prints nothing to stdout
     self.assertEqual(stdout, '')
Exemplo n.º 14
0
 def test_fix_checksum(self):
     pkg = Package('configure')
     rc, stdout, stderr = self.run_command(EXECUTABLE, 'fix-checksum',
                                           'configure')
     # Prints nothing to stderr
     self.assertEqual(stderr, '')
     # returns successfully
     self.assertEqual(rc, 0)
     # Prints to stdout
     self.assertEqual(
         stdout.rstrip(), 'Checksum of {0} (tarball {1}) unchanged'.format(
             pkg.name, pkg.tarball_filename))
Exemplo n.º 15
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)
Exemplo n.º 16
0
    def upload(self, package_name):
        """
        Upload a package to the Sage mirror network

        $ sage --package upload pari
        Uploading /home/vbraun/Code/sage.git/upstream/pari-2.8-2044-g89b0f1e.tar.gz
        """
        package = Package(package_name)
        if not os.path.exists(package.tarball.upstream_fqn):
            log.debug('Skipping %s because there is no local tarbal', package_name)
            return
        log.info('Uploading %s', package.tarball.upstream_fqn)
        fs = FileServer()
        fs.upload(package)
Exemplo n.º 17
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)
Exemplo n.º 18
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()
Exemplo n.º 19
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()
Exemplo n.º 20
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/')
Exemplo n.º 21
0
 def test_checksum(self):
     pkg = Package('configure')
     tarball = pkg.tarball
     with CapturedOutput() as (stdout, stderr):
         with CapturedLog() as log:
             tarball.download()
     self.assertTrue(tarball.checksum_verifies())
     with open(tarball.upstream_fqn, 'w') as f:
         f.write('foobar')
     self.assertFalse(tarball.checksum_verifies())
     with CapturedOutput() as (stdout, stderr):
         with CapturedLog() as log:
             tarball.download()
     msg = log.messages()
     self.assertTrue(
         ('INFO', 'Attempting to download package {0} from mirrors'.format(
             pkg.tarball_filename)) in msg)
     self.assertEqual(stdout.getvalue(), '')
     self.assertEqual(
         stderr.getvalue(),
         '[......................................................................]\n'
     )
     self.assertTrue(tarball.checksum_verifies())
Exemplo n.º 22
0
 def package(self):
     if self.__package is None:
         self.__package = Package(self.package_name)
     return self.__package
Exemplo n.º 23
0
 def test_all(self):
     pari = Package('pari')
     self.assertTrue(pari in Package.all())
Exemplo n.º 24
0
 def _init_huge(self, predicate):
     self.names.extend(pkg.name for pkg in Package.all() if pkg.type == 'huge' and predicate(pkg))
Exemplo n.º 25
0
 def _init_optional(self, predicate):
     self.names.extend(pkg.name for pkg in Package.all() if pkg.type == 'optional' and predicate(pkg))
Exemplo n.º 26
0
 def _init_standard(self, predicate):
     self.names.extend(pkg.name for pkg in Package.all() if pkg.type == 'standard' and predicate(pkg))
Exemplo n.º 27
0
 def _init_all(self, predicate):
     self.names.extend(pkg.name for pkg in Package.all() if predicate(pkg))
Exemplo n.º 28
0
 def _init_huge(self):
     self.names = [pkg.name for pkg in Package.all() if pkg.type == 'huge']
Exemplo n.º 29
0
 def _init_experimental(self):
     self.names = [
         pkg.name for pkg in Package.all() if pkg.type == 'experimental'
     ]
Exemplo n.º 30
0
 def _init_optional(self):
     self.names = [
         pkg.name for pkg in Package.all() if pkg.type == 'optional'
     ]
Exemplo n.º 31
0
 def _init_standard(self):
     self.names = [
         pkg.name for pkg in Package.all() if pkg.type == 'standard'
     ]
Exemplo n.º 32
0
 def _update_version(self, new_version):
     old = Package(self.package_name)
     package_version_txt = os.path.join(old.path, 'package-version.txt')
     with open(package_version_txt, 'w') as f:
         f.write(new_version.strip() + '\n')
Exemplo n.º 33
0
 def _init_all(self):
     self.names = [pkg.name for pkg in Package.all()]
Exemplo n.º 34
0
 def _init_experimental(self, predicate):
     self.names.extend(pkg.name for pkg in Package.all() if pkg.type == 'experimental' and predicate(pkg))