Example #1
0
File: gist.py Project: Malex/pyg
    def download(self, dest, accumulator):
        logger.info('Retrieving file names')
        for filename in self.files:
            logger.indent = 0
            logger.info('Downloading {0}', filename)
            logger.indent = 8
            path = os.path.abspath(os.path.join(dest, filename))
            if os.path.exists(path):
                txt = 'The destination already exists: {0}\nWhat do you want to do'.format(path)
                u = logger.ask(txt, choices={'destroy': 'd', 'backup': 'b', 'exit': 'x'})

                if u == 'd':
                    logger.info('Removing {0}', path)
                    os.remove(path)
                elif u == 'b':
                    d = path + '.pyg-backup'
                    logger.info('Moving {0} to {1}', path, d)
                    shutil.copyfile(path, d)
                elif u == 'x':
                    logger.info('Exiting...')
                    sys.exit(0)
            with open(path, 'w') as f:
                logger.info('Writing data into {0}', filename)
                f.write(self.get_file_content(filename))
                accumulator.add(filename)
Example #2
0
File: inst.py Project: fdev31/pyg
    def update(self):
        '''
        Searches for updates for every package in the WorkingSet.
        Then calls :meth:`~pyg.inst.Updater.upgrade`.
        '''

        logger.info('Searching for updates')
        for dist in self.working_set:
            package = dist.project_name
            version = Version(dist.version)
            logger.verbose('Found: {0}=={1}', package, version)
            try:
                json = PyPIJson(package).retrieve()
                new_version = Version(json['info']['version'])
            except Exception as e:
                logger.error('Error: Failed to fetch data for {0} ({1})', package, e)
                continue
            if version >= new_version:
                continue

            txt = 'A new release is avaiable for {0}: {1!s} (old {2}), update'.format(package, new_version, dist.version)
            u = logger.ask(txt, bool=('upgrade version', 'keep working version'), dont_ask=self.yes)
            if u:
                self.upgrade(package, json, new_version)
            else:
                logger.info('{0} has not been upgraded', package)
        self._clean()
        logger.success('Updating finished successfully')
Example #3
0
File: base.py Project: Malex/pyg
 def check_dest(self):
     ## If the target directory is empty we don't have to worry
     try:
         if not os.listdir(self.dest):
             return
     ## If self.dest does not exist we leave it as it is, because it will be
     ## created by the `else` clause (below)
     except OSError:
         pass
     if os.path.exists(self.dest):
         txt = 'The destination already exists: {0}\nWhat do you want to do ?'.format(self.dest)
         u = logger.ask(txt, choices={'destroy': 'd', 'backup': 'b', 'exit': 'x'})
         if u == 'd':
             logger.info('Removing {0}...', self.dest)
             shutil.rmtree(self.dest)
             os.makedirs(self.dest)
         elif u == 'b':
             dst = os.path.join(os.path.dirname(self.dest),
                                                 self.dest + '-pyg-backup')
             logger.info('Moving {0} to {1}', self.dest, dst)
             shutil.move(self.dest, dst)
             os.makedirs(self.dest)
         elif u == 'x':
             logger.info('Exiting...')
             sys.exit(0)
     else:
         os.makedirs(self.dest)
Example #4
0
File: inst.py Project: fdev31/pyg
 def uninstall(self):
     path_re = re.compile(r'\./{0}-[\d\w\.]+-py\d\.\d.egg'.format(self.name), re.I)
     path_re2 = re.compile(r'\.{0}'.format(self.name), re.I)
     to_del = self.find_files()
     if not to_del:
         logger.warn('{0}: did not find any files to delete', self.name)
         raise PygError
     logger.info('Uninstalling {0}', self.name)
     logger.indent += 8
     for d in to_del:
         logger.info(d)
     logger.indent -= 8
     do_it = logger.ask('Proceed', bool=('remove files', 'cancel'), dont_ask=args_manager['install']['yes'])
     if do_it:
         for d in to_del:
             try:
                 logger.verbose('Deleting: {0}', d)
                 shutil.rmtree(d)
             except OSError: ## It is not a directory
                 try:
                     os.remove(d)
                 except OSError:
                     logger.error('Error: cannot delete {0}', d)
         logger.verbose('Removing egg path from easy_install.pth...')
         with open(EASY_INSTALL) as f:
             lines = f.readlines()
         with open(EASY_INSTALL, 'w') as f:
             for line in lines:
                 if path_re.match(line) or path_re2.match(line):
                     continue
                 f.write(line)
         logger.success('{0} uninstalled succesfully', self.name)
     else:
        logger.info('{0} has not been uninstalled', self.name)
Example #5
0
File: req.py Project: fdev31/pyg
 def _check_bad_eggs(self, bad_eggs):
     ## Bad eggs are eggs which require a different Python version.
     ## If we don't find anything more, we check bad eggs.s
     txt = 'Found only eggs for another Python version, which one do you want to install'
     choice = logger.ask(txt, choices={v[1]: v for v in bad_eggs})
     self._download_and_install(*choice)