示例#1
0
文件: helpers.py 项目: toxinu/ubik
def install_package(ws, package):
    p_name = package
    if p_name in lock:
        log(ws, '<strong>Error</strong>: Someone already work with %s package' % package)
        return
    lock.append(p_name)
    try:
        log(ws, 'Sync database')
        api.db.sync()
        installer = Installer()
        package = api.db.get(package)[0]
        log(ws, 'Resolve dependencies')
        installer.resolve(package)
        installer.feed(installer.resolved)
        installed_packages = "<ul>"
        for p in installer.packages:
            installed_packages += "<li>%s</li>" % p.name
        installed_packages = installed_packages + "</ul>"
        log(ws, 'Following dependencies will be installed: %s' % installed_packages)
        log(ws, 'Download package(s)')
        installer.download()
        log(ws, 'Install package(s)')
        installer.install()
        log(ws, 'Done')
    except Exception as err:
        log(ws, '<strong>Error</strong>: %s' % err)
    lock.remove(p_name)
示例#2
0
文件: helpers.py 项目: toxinu/ubik
def install_package(ws, package):
    p_name = package
    if p_name in lock:
        log(
            ws,
            '<strong>Error</strong>: Someone already work with %s package' %
            package)
        return
    lock.append(p_name)
    try:
        log(ws, 'Sync database')
        api.db.sync()
        installer = Installer()
        package = api.db.get(package)[0]
        log(ws, 'Resolve dependencies')
        installer.resolve(package)
        installer.feed(installer.resolved)
        installed_packages = "<ul>"
        for p in installer.packages:
            installed_packages += "<li>%s</li>" % p.name
        installed_packages = installed_packages + "</ul>"
        log(
            ws, 'Following dependencies will be installed: %s' %
            installed_packages)
        log(ws, 'Download package(s)')
        installer.download()
        log(ws, 'Install package(s)')
        installer.install()
        log(ws, 'Done')
    except Exception as err:
        log(ws, '<strong>Error</strong>: %s' % err)
    lock.remove(p_name)
示例#3
0
    def test_100_install_package_01(self):
        # Install 'package_01' package with it's 'package_02' require
        self.db.sync()
        installer = Installer()
        installer.resolve(self.package_01)
        installer.feed(installer.resolved)
        self.assertEqual(len(installer.packages), 2)

        installer.download()
        installer.install()
        self.assertEqual(self.db.count_installed(), 2)
示例#4
0
	def test_100_install_package_01(self):
		# Install 'package_01' package with it's 'package_02' require
		self.db.sync()
		installer = Installer()
		installer.resolve(self.package_01)
		installer.feed(installer.resolved)
		self.assertEqual(len(installer.packages), 2)

		installer.download()
		installer.install()
		self.assertEqual(self.db.count_installed(), 2)
示例#5
0
    def test_100_install_package(self):
        self.db.sync()
        installer = Installer()
        installer.resolve(self.package)
        installer.feed(installer.resolved)
        self.assertEqual(len(installer.packages), 1)

        installer.download()
        installer.install()
        self.assertTrue(self.db.get('package_14'))
        self.assertEqual(self.db.count_installed(), 2)
示例#6
0
    def test_100_install_package(self):
        self.db.sync()
        installer = Installer()
        installer.resolve(self.package)
        installer.feed(installer.resolved)
        self.assertEqual(len(installer.packages), 1)

        installer.download()
        installer.install()
        self.assertTrue(self.db.get('package_14'))
        self.assertEqual(self.db.count_installed(), 2)
示例#7
0
    def test_100_install_package(self):
        self.db.sync()
        installer = Installer()
        try:
            installer.resolve(self.package)
            raise Exception('Dependence must be unvailable')
        except DatabaseException:
            pass
        self.assertEqual(len(installer.packages), 0)
        self.assertTrue(self.db.get('package_10'))

        # Just package_03 installed
        self.assertEqual(self.db.count_installed(), 1)

        path = "%s/bin/package_10" % api.conf.get('settings', 'packages')
        self.assertFalse(os.path.exists(path))
示例#8
0
    def test_101_install_package_12(self):
        self.db.sync()
        installer = Installer()
	try:
		installer.resolve(self.package_12)
		raise Exception('Dependences resolving must failed')
	except DatabaseException:
		pass
        self.assertEqual(len(installer.packages), 0)
        self.assertTrue(self.db.get('package_12'))

	# Just package_03 installed
        self.assertEqual(self.db.count_installed(), 1)

	path = "%s/bin/package_12" % api.conf.get('settings', 'packages')
	self.assertFalse(os.path.exists(path))
示例#9
0
    def test_100_install_package(self):
        clean()
        # Invalid local archive package
        os.system('echo "jambon" >> %s/var/lib/ubik/packages/package_04.tar' % api.conf.get('settings', 'packages'))
        self.db.sync()
        installer = Installer()
        installer.resolve(self.package)
        installer.feed(installer.resolved)
        self.assertEqual(len(installer.packages), 2)

        try:
            installer.download()
            raise Exception('Downloader must failed')
        except:
            pass

        try:
            self.db.get_installed()['package_04']
            raise Exception('Package_04 must not be installed')
        except:
            pass
        self.assertEqual(self.db.count_installed(), 3)
示例#10
0
    def test_100_install_package(self):
        clean()
        # Invalid local archive package
        os.system('echo "jambon" >> %s/var/lib/ubik/packages/package_04.tar' %
                  api.conf.get('settings', 'packages'))
        self.db.sync()
        installer = Installer()
        installer.resolve(self.package)
        installer.feed(installer.resolved)
        self.assertEqual(len(installer.packages), 2)

        try:
            installer.download()
            raise Exception('Downloader must failed')
        except:
            pass

        try:
            self.db.get_installed()['package_04']
            raise Exception('Package_04 must not be installed')
        except:
            pass
        self.assertEqual(self.db.count_installed(), 3)
示例#11
0
文件: cli.py 项目: toxinu/ubik
    def start(self):
        ###################
        # conf            #
        ###################
        if self.args.get('conf', False):
            get_conf()
        ###################
        # stats           #
        ###################
        if self.args.get('stats', False):
            get_stats()
        ###################
        # list            #
        ###################
        elif self.args.get('list', False):
            get_view()
        ###################
        # update          #
        ###################
        elif self.args.get('update', False):
            stream_logger.info('=> Update')
            try:
                db.sync()
            except Exception as err:
                if int(conf.get('logger','level')) >= 2:
                    traceback.print_exc(file=sys.stdout)
                self.error_link()
        ###################
        # clean           #
        ###################
        elif self.args.get('clean', False):
            stream_logger.info('=> Cleaning')
            clean()
        ###################
        # reinstall       #
        ###################
        elif self.args.get('reinstall', False):
            # Sync Database
            stream_logger.info('=> Updating')
            try:
                db.sync()
            except Exception as err:
                if int(conf.get('logger','level')) >= 2:
                    traceback.print_exc(file=sys.stdout)
                self.error_link()
            # Create installer
            stream_logger.info('=> Resolving')
            reinstaller = Reinstaller()
            if not isinstance(self.args['<package>'], list):
                packages = [self.args['<package>']]
            else:
                packages = self.args['<package>']

            try:
                if self.args.get('--with-deps', False):
                    for package in db.get(packages):
                        try:
                            reinstaller.resolve(package)
                            reinstaller.feed(reinstaller.resolved)
                        except RuntimeError as err:
                            if int(conf.get('logger','level')) >= 2:
                                traceback.print_exc(file=sys.stdout)
                            stream_logger.info('!! Dependencies resolve failed (%s)' % err)
                            sys.exit(1)
                else:
                    reinstaller.feed(db.get(packages))
            except DatabaseException as err:
                if int(conf.get('logger','level')) >= 2:
                    traceback.print_exc(file=sys.stdout)
                self.error_link()

            if not reinstaller.packages:
                stream_logger.info('=> No package(s) to reinstall')
                sys.exit(0)
            stream_logger.info('=> Following packages will be reinstalled:')
            for package in reinstaller.packages:
                stream_logger.info('   - %s' % package.name)
            if not self.args.get('--force-yes', False):
                if confirm():
                    reinstaller.download()
                    try:
                        reinstaller.reinstall(ignore_errors=self.args.get('--ignore-errors', False))
                    except Exception as err:
                        if int(conf.get('logger','level')) >= 2:
                            traceback.print_exc(file=sys.stdout)
                        raise
                else:
                    stream_logger.info('Abort.')
                    sys.exit(1)
            else:
                reinstaller.download()
                try:
                    reinstaller.reinstall(ignore_errors=self.args.get('--ignore-errors', False))
                except Exception as err:
                    if int(conf.get('logger','level')) >= 2:
                        traceback.print_exc(file=sys.stdout)
                    raise

        ###################
        # install         #
        ###################
        elif self.args.get('install', False):
            # Sync Database
            stream_logger.info('=> Updating')
            try:
                db.sync()
            except Exception as err:
                if int(conf.get('logger','level')) >= 2:
                    traceback.print_exc(file=sys.stdout)
                self.error_link()
            # Create installer
            installer = Installer()
            # Resolve deps
            stream_logger.info('=> Resolving dependencies')
            if not isinstance(self.args['<package>'], list):
                packages = [self.args['<package>']]
            else:
                packages = self.args['<package>']

            try:
                for package in db.get(packages):
                    try:
                        installer.resolve(package)
                        installer.feed(installer.resolved)
                    except RuntimeError as err:
                        if int(conf.get('logger','level')) >= 2:
                            traceback.print_exc(file=sys.stdout)
                        stream_logger.info('!! Dependencies resolve failed (%s)' % err)
                        sys.exit(1)
            except DatabaseException as err:
                if int(conf.get('logger','level')) >= 2:
                    traceback.print_exc(file=sys.stdout)
                self.error_link()

            if not installer.packages:
                stream_logger.info('   - No package(s) found')
                sys.exit(1)
            stream_logger.info('=> Following dependencies will be installed:')
            for dep in installer.packages:
                stream_logger.info('   - %s' % dep.name)

            if not self.args.get('--force-yes', False):
                if confirm():
                    installer.download()
                    try:
                        installer.install(ignore_errors=self.args.get('--ignore-errors', False))
                    except Exception as err:
                        if int(conf.get('logger','level')) >= 2:
                            traceback.print_exc(file=sys.stdout)
                        raise
                else:
                    stream_logger.info('Abort.')
                    sys.exit(1)
            else:
                installer.download()
                try:
                    installer.install(ignore_errors=self.args.get('--ignore-errors', False))
                except Exception as err:
                    if int(conf.get('logger','level')) >= 2:
                        traceback.print_exc(file=sys.stdout)
                    raise
        ###################
        # upgrade         #
        ###################
        elif self.args.get('upgrade', False):
            # Sync Database
            stream_logger.info('=> Updating')
            try:
                db.sync()
            except Exception as err:
                if int(conf.get('logger','level')) >= 2:
                    traceback.print_exc(file=sys.stdout)
                self.error_link()
            # Create Upgrader
            upgrader = Upgrader()
            stream_logger.info('=> Resolving')
            if not isinstance(self.args['<package>'], list):
                packages = [self.args['<package>']]
            else:
                packages = self.args['<package>']

            if not packages:
                upgrader.feed(db.get_upgrades())
            else:
                upgrader.feed(packages)

            if not upgrader.packages:
                stream_logger.info('!! No package(s) to upgrade')
                sys.exit(0)

            stream_logger.info('=> Following packages will be upgraded:')
            for package in upgrader.packages:
                stream_logger.info('   - %s' % package.name)

            if not self.args.get('--force-yes', False):
                if confirm():
                    upgrader.download()
                    try:
                        upgrader.upgrade(ignore_errors=self.args.get('--ignore-errors', False))
                    except Exception as err:
                        if int(conf.get('logger','level')) >= 2:
                            traceback.print_exc(file=sys.stdout)
                        raise
                else:
                    stream_logger.info('Abort.')
                    sys.exit(1)
            else:
                upgrader.download()
                try:
                    upgrader.upgrade(ignore_errors=self.args.get('--ignore-errors', False))
                except Exception as err:
                    if int(conf.get('logger','level')) >= 2:
                        traceback.print_exc(file=sys.stdout)
                    raise
        ###################
        # remove          #
        ###################
        elif self.args.get('remove', False):
            # Create remover
            remover = Remover()
            packages = db.get(self.args.get('<package>'))

            try:
                remover.feed(packages)
            except DatabaseException as err:
                if int(conf.get('logger','level')) >= 2:
                    traceback.print_exc(file=sys.stdout)
                self.error_link()

            if not remover.packages:
                sys.exit(0)

            stream_logger.info('=> Following packages will be removed:')
            for package in remover.packages:
                stream_logger.info('   - %s' % package.name)

            if not self.args.get('--force-yes', False):
                if confirm():
                    remover.remove(ignore_errors=self.args.get('--ignore-errors', False))
                else:
                    stream_logger.info('Abort.')
                    sys.exit(1)
            else:
                try:
                    remover.remove(ignore_errors=self.args.get('--ignore-errors', False))
                except Exception as err:
                    if int(conf.get('logger','level')) >= 2:
                        traceback.print_exc(file=sys.stdout)
                        raise
        ##########
        # search #
        ##########
        elif self.args.get('search', False):
            packages = db.get(self.args.get('<package>'))
            if not packages:
                stream_logger.info('!! No package found')
                sys.exit(1)
            for package in packages:
                stream_logger.info('Name: %s' % package.name)
                if package in db.get_installed():
                    stream_logger.info('Version: %s-%s' % (package.version, package.release))
                    stream_logger.info('Status: %s' % status[package.status])
                else:
                    stream_logger.info('Version: %s-%s' % (package.repo_version, package.repo_release))
                    stream_logger.info('Status: %s' % status[package.status])

                stream_logger.info('Requires: %s' % ','.join(package.requires))
                stream_logger.info('Description: %s' % package.description)
                stream_logger.info('Architecture: %s' % package.arch)
                stream_logger.info('Distribution: %s' % package.dist)
                stream_logger.info('Distribution version: %s' % package.vers)
                if package is not packages[-1]:
                    stream_logger.info('')
            sys.exit(0)
示例#12
0
文件: cli.py 项目: toxinu/ubik
    def start(self):
        ###################
        # conf            #
        ###################
        if self.args.get('conf', False):
            get_conf()
        ###################
        # stats           #
        ###################
        if self.args.get('stats', False):
            get_stats()
        ###################
        # list            #
        ###################
        elif self.args.get('list', False):
            get_view()
        ###################
        # update          #
        ###################
        elif self.args.get('update', False):
            stream_logger.info('=> Update')
            try:
                db.sync()
            except Exception as err:
                if int(conf.get('logger', 'level')) >= 2:
                    traceback.print_exc(file=sys.stdout)
                self.error_link()
        ###################
        # clean           #
        ###################
        elif self.args.get('clean', False):
            stream_logger.info('=> Cleaning')
            clean()
        ###################
        # reinstall       #
        ###################
        elif self.args.get('reinstall', False):
            # Sync Database
            stream_logger.info('=> Updating')
            try:
                db.sync()
            except Exception as err:
                if int(conf.get('logger', 'level')) >= 2:
                    traceback.print_exc(file=sys.stdout)
                self.error_link()
            # Create installer
            stream_logger.info('=> Resolving')
            reinstaller = Reinstaller()
            if not isinstance(self.args['<package>'], list):
                packages = [self.args['<package>']]
            else:
                packages = self.args['<package>']

            try:
                if self.args.get('--with-deps', False):
                    for package in db.get(packages):
                        try:
                            reinstaller.resolve(package)
                            reinstaller.feed(reinstaller.resolved)
                        except RuntimeError as err:
                            if int(conf.get('logger', 'level')) >= 2:
                                traceback.print_exc(file=sys.stdout)
                            stream_logger.info(
                                '!! Dependencies resolve failed (%s)' % err)
                            sys.exit(1)
                else:
                    reinstaller.feed(db.get(packages))
            except DatabaseException as err:
                if int(conf.get('logger', 'level')) >= 2:
                    traceback.print_exc(file=sys.stdout)
                self.error_link()

            if not reinstaller.packages:
                stream_logger.info('=> No package(s) to reinstall')
                sys.exit(0)
            stream_logger.info('=> Following packages will be reinstalled:')
            for package in reinstaller.packages:
                stream_logger.info('   - %s' % package.name)
            if not self.args.get('--force-yes', False):
                if confirm():
                    reinstaller.download()
                    try:
                        reinstaller.reinstall(ignore_errors=self.args.get(
                            '--ignore-errors', False))
                    except Exception as err:
                        if int(conf.get('logger', 'level')) >= 2:
                            traceback.print_exc(file=sys.stdout)
                        raise
                else:
                    stream_logger.info('Abort.')
                    sys.exit(1)
            else:
                reinstaller.download()
                try:
                    reinstaller.reinstall(
                        ignore_errors=self.args.get('--ignore-errors', False))
                except Exception as err:
                    if int(conf.get('logger', 'level')) >= 2:
                        traceback.print_exc(file=sys.stdout)
                    raise

        ###################
        # install         #
        ###################
        elif self.args.get('install', False):
            # Sync Database
            stream_logger.info('=> Updating')
            try:
                db.sync()
            except Exception as err:
                if int(conf.get('logger', 'level')) >= 2:
                    traceback.print_exc(file=sys.stdout)
                self.error_link()
            # Create installer
            installer = Installer()
            # Resolve deps
            stream_logger.info('=> Resolving dependencies')
            if not isinstance(self.args['<package>'], list):
                packages = [self.args['<package>']]
            else:
                packages = self.args['<package>']

            try:
                for package in db.get(packages):
                    try:
                        installer.resolve(package)
                        installer.feed(installer.resolved)
                    except RuntimeError as err:
                        if int(conf.get('logger', 'level')) >= 2:
                            traceback.print_exc(file=sys.stdout)
                        stream_logger.info(
                            '!! Dependencies resolve failed (%s)' % err)
                        sys.exit(1)
            except DatabaseException as err:
                if int(conf.get('logger', 'level')) >= 2:
                    traceback.print_exc(file=sys.stdout)
                self.error_link()

            if not installer.packages:
                stream_logger.info('   - No package(s) found')
                sys.exit(1)
            stream_logger.info('=> Following dependencies will be installed:')
            for dep in installer.packages:
                stream_logger.info('   - %s' % dep.name)

            if not self.args.get('--force-yes', False):
                if confirm():
                    installer.download()
                    try:
                        installer.install(ignore_errors=self.args.get(
                            '--ignore-errors', False))
                    except Exception as err:
                        if int(conf.get('logger', 'level')) >= 2:
                            traceback.print_exc(file=sys.stdout)
                        raise
                else:
                    stream_logger.info('Abort.')
                    sys.exit(1)
            else:
                installer.download()
                try:
                    installer.install(
                        ignore_errors=self.args.get('--ignore-errors', False))
                except Exception as err:
                    if int(conf.get('logger', 'level')) >= 2:
                        traceback.print_exc(file=sys.stdout)
                    raise
        ###################
        # upgrade         #
        ###################
        elif self.args.get('upgrade', False):
            # Sync Database
            stream_logger.info('=> Updating')
            try:
                db.sync()
            except Exception as err:
                if int(conf.get('logger', 'level')) >= 2:
                    traceback.print_exc(file=sys.stdout)
                self.error_link()
            # Create Upgrader
            upgrader = Upgrader()
            stream_logger.info('=> Resolving')
            if not isinstance(self.args['<package>'], list):
                packages = [self.args['<package>']]
            else:
                packages = self.args['<package>']

            if not packages:
                upgrader.feed(db.get_upgrades())
            else:
                upgrader.feed(packages)

            if not upgrader.packages:
                stream_logger.info('!! No package(s) to upgrade')
                sys.exit(0)

            stream_logger.info('=> Following packages will be upgraded:')
            for package in upgrader.packages:
                stream_logger.info('   - %s' % package.name)

            if not self.args.get('--force-yes', False):
                if confirm():
                    upgrader.download()
                    try:
                        upgrader.upgrade(ignore_errors=self.args.get(
                            '--ignore-errors', False))
                    except Exception as err:
                        if int(conf.get('logger', 'level')) >= 2:
                            traceback.print_exc(file=sys.stdout)
                        raise
                else:
                    stream_logger.info('Abort.')
                    sys.exit(1)
            else:
                upgrader.download()
                try:
                    upgrader.upgrade(
                        ignore_errors=self.args.get('--ignore-errors', False))
                except Exception as err:
                    if int(conf.get('logger', 'level')) >= 2:
                        traceback.print_exc(file=sys.stdout)
                    raise
        ###################
        # remove          #
        ###################
        elif self.args.get('remove', False):
            # Create remover
            remover = Remover()
            packages = db.get(self.args.get('<package>'))

            try:
                remover.feed(packages)
            except DatabaseException as err:
                if int(conf.get('logger', 'level')) >= 2:
                    traceback.print_exc(file=sys.stdout)
                self.error_link()

            if not remover.packages:
                sys.exit(0)

            stream_logger.info('=> Following packages will be removed:')
            for package in remover.packages:
                stream_logger.info('   - %s' % package.name)

            if not self.args.get('--force-yes', False):
                if confirm():
                    remover.remove(
                        ignore_errors=self.args.get('--ignore-errors', False))
                else:
                    stream_logger.info('Abort.')
                    sys.exit(1)
            else:
                try:
                    remover.remove(
                        ignore_errors=self.args.get('--ignore-errors', False))
                except Exception as err:
                    if int(conf.get('logger', 'level')) >= 2:
                        traceback.print_exc(file=sys.stdout)
                        raise
        ##########
        # search #
        ##########
        elif self.args.get('search', False):
            packages = db.get(self.args.get('<package>'))
            if not packages:
                stream_logger.info('!! No package found')
                sys.exit(1)
            for package in packages:
                stream_logger.info('Name: %s' % package.name)
                if package in db.get_installed():
                    stream_logger.info('Version: %s-%s' %
                                       (package.version, package.release))
                    stream_logger.info('Status: %s' % status[package.status])
                else:
                    stream_logger.info(
                        'Version: %s-%s' %
                        (package.repo_version, package.repo_release))
                    stream_logger.info('Status: %s' % status[package.status])

                stream_logger.info('Requires: %s' % ','.join(package.requires))
                stream_logger.info('Description: %s' % package.description)
                stream_logger.info('Architecture: %s' % package.arch)
                stream_logger.info('Distribution: %s' % package.dist)
                stream_logger.info('Distribution version: %s' % package.vers)
                if package is not packages[-1]:
                    stream_logger.info('')
            sys.exit(0)