예제 #1
0
 def download(self):
     fname = self.url.split('/')[-1].split('?')[0]
     temppath = os.path.join(gettempdir(), fname)
     opener = urlopen(self.url)
     try:
         data = opener.read()
     except Exception as err:
         log_to_file(str(err))
         # self._log_output(err)
         return False
     with open(temppath, 'wb') as ofile:
         ofile.write(data)
     handler = None
     for extension in self.archive_handlers:
         if fname.endswith(extension):
             handler = self.archive_handlers[extension]
             break
     if handler is None:
         logger.error('unsupported archive for application %s' % Color.GREEN+self.name+Color.END)
         return False
     mode = 'r'
     archive_type = fname.split('.')[-1]
     if archive_type in ('gz', 'bz2'):
         mode = 'r:%s' % archive_type
     archive = handler(temppath, mode=mode)
     archive.extractall(self.path)
     os.remove(temppath)
     self.is_updated = True
     return True
예제 #2
0
def run_command(cmd):
    logger.debug('running external command: %s' % Color.GREEN + cmd + Color.END)
    cmd = shlex.split(cmd)
    p = Popen(cmd, shell=False, stdout=PIPE, stderr=PIPE)
    stdout, stderr = p.communicate()
    # display STDOUT content
    if stdout:
        for line in stdout.splitlines():
            logger.debug(Color.BLUE+line+Color.END)
    # display an error (STDERR or generic message) if returncode is non-zero
    if p.returncode != 0:
        tmpname = log_to_file(stderr)
        logger.error('an error occured, see %s for more details' % (Color.GREEN+tmpname+Color.END))
        return False
    return True