Exemple #1
0
    def perform(self, source):
        tok = token.PackageOptVersionToken()
        (pkgname, vers) = tok.accept(source)
        self.assert_done(source)

        if (vers is None):
            dirname = frame.loader.generate_package_path(pkgname)
            if (not os.path.exists(dirname)):
                raise CommandError('No such package group: ' + pkgname)

            if (not frame.is_force):
                desc = ' all versions of'
                try:
                    # A bad collection dir shouldn't derail us here
                    pgroup = frame.loader.load_group(pkgname)
                    if (len(pgroup.versions) == 0):
                        desc = ' the directory for'
                    elif (len(pgroup.versions) == 1):
                        desc = ''
                    else:
                        desc = ' ' + str(len(pgroup.versions)) + ' versions of'
                except:
                    pass
                
                print ('Are you sure you want to delete' + desc + ' '
                    + pkgname + '?')
                tok = token.YesNoToken()
                res = tok.accept(source)
                if (not res):
                    raise CommandCancelled()

            frame.loader.delete_group(pkgname)
            print 'All of package', pkgname, 'deleted.'
        else:
            pkg = frame.loader.load(pkgname, vers)
        
            if (not frame.is_force):
                print ('Are you sure you want to delete ' + pkg.name
                    + ' (version ' + str(pkg.version) + ')?')
                tok = token.YesNoToken()
                res = tok.accept(source)
                if (not res):
                    raise CommandCancelled()

            frame.loader.delete_package(pkg.name, pkg.version)
            print 'Package', format_package(pkg), 'deleted.'
Exemple #2
0
    def perform(self, source):
        self.assert_done(source)
        
        if (not frame.is_force):
            print 'Are you sure you want to delete every package in your collection?'
            tok = token.YesNoToken()
            res = tok.accept(source)
            if (not res):
                raise CommandCancelled()

        frame.loader.delete_whole_collection()
        print 'All packages deleted.'
    def perform(self, source):
        tok = token.PackageFileURLToken()
        (srctype, loc) = tok.accept(source)
        self.assert_done(source)

        if srctype == collect.Source_PACKAGE:
            (pkgname, vers) = loc
            if isinstance(vers, Version):
                # really this should query boodler.org for matching version
                raise CommandError('You must supply an exact version number')
            if vers is None:
                # really this should query boodler.org for the latest version
                raise CommandError('You must supply a version number')
            destfile = create.build_package_filename(pkgname, vers)
            srctype = collect.Source_URL
            loc = collect.REPOSITORY_URL + destfile
            print('Downloading package from:', loc)

        ensure_fetched(srctype, loc)
        try:
            pkg = frame.loader.find_source(srctype, loc)
            frame.loader.load(pkg.name, pkg.version)
            already_got = True
        except:
            pkg = None
            already_got = False

        if already_got and (not frame.is_force):
            print(
                ('The package ' + pkg.name + ' (version ' + str(pkg.version) +
                 ') is already installed. Do you want to reinstall it?'))
            tok = token.YesNoToken()
            res = tok.accept(source)
            if not res:
                raise CommandCancelled()

        pkg = frame.loader.install_source(srctype, loc)

        print('Package:', pkg.name, '   Version:', str(pkg.version))
        meta = pkg.metadata
        print('Title:', meta.get_one('dc.title', '<not available>'))
Exemple #4
0
    def perform(self, source):
        tok = token.DirToken()
        (dirname, direxists) = tok.accept(source)

        destname = None
        if (not source.is_empty()):
            tok = token.FileToken(False)
            (destname, destexists) = tok.accept(source)

        self.assert_done(source)

        if (not frame.loader.importing_ok):
            raise CommandError('Creating requires importing packages, and the --import option has not been set.')

        absdirname = os.path.abspath(dirname)
        abscoldir = os.path.abspath(frame.loader.collecdir)
        if (absdirname.startswith(abscoldir)):
            raise CommandError('Directory is inside the collection tree: ' + absdirname)

        if (destname):
            if (not destname.endswith(collect.Suffix_PackageArchive)):
                destname = destname+collect.Suffix_PackageArchive
        
        tup = create.examine_directory(frame.loader, absdirname, destname)
        ((pkgname, pkgvers), contents, meta, ress) = tup

        frame.loader.clear_external_packages()

        if (not destname):
            destname = os.path.dirname(absdirname)
            destfile = create.build_package_filename(pkgname, pkgvers)
            destname = os.path.join(destname, destfile)

        if (os.path.exists(destname) and not frame.is_force):
            print 'Are you sure you want to overwrite ' + destname + '?'
            tok = token.YesNoToken()
            res = tok.accept(source)
            if (not res):
                raise CommandCancelled()

        metafile = frame.loader.create_temp_file('metadata')
        ressfile = None
        if (ress):
            ressfile = frame.loader.create_temp_file('resources')

        # Comments for the head of the metadata and resource files
        comments = [ format_package( (pkgname, pkgvers) ),
            'package built ' + time.ctime() ]
        
        writer = codecs.getwriter('utf-8')

        fl = open(metafile, 'wb')
        ufl = writer(fl)
        try:
            meta.dump(ufl, comments)
        finally:
            ufl.close()
            fl.close()
            
        if (ress):
            fl = open(ressfile, 'wb')
            ufl = writer(fl)
            try:
                ress.dump(ufl, comments)
            finally:
                ufl.close()
                fl.close()
                
        fl = zipfile.ZipFile(destname, 'w')
        try:
            create.construct_zipfile(fl,
                (pkgname, pkgvers), absdirname, contents, metafile, ressfile)
        finally:
            fl.close()
        print 'Package created:', destname