示例#1
0
 def download_unpack(self):
     content_type = self.content_type
     if is_html(content_type):
         logger.error("Invalid content-type: `%s`" % content_type)
         sys.exit(1)
     if is_file(self.download_url):
         path = fileurl_to_path(self.download_url)
         if os.path.isdir(path):
             logger.info('Copying %s into %s' % (path, self.build_dir))
             if os.path.isdir(self.build_dir):
                 shutil.rmtree(self.build_dir)
             shutil.copytree(path, self.build_dir)
             return
     if os.path.isfile(self.download_file):
         logger.info("Use the previously fetched %s" % (self.download_file))
     else:
         msg = Link(self.download_url).show_msg
         try:
             dl = Downloader()
             dl.download(msg, self.download_url, self.download_file)
         except:
             unlink(self.download_file)
             logger.info("\nInterrupt to abort. `%s`" % (self.download_url))
             sys.exit(1)
     # unpack
     if not unpack_downloadfile(self.content_type, self.download_file, self.build_dir):
         sys.exit(1)
示例#2
0
文件: update.py 项目: nvie/pythonbrew
 def run_command(self, options, args):
     if args:
         version = args[0]
     else:
         version = get_stable_version()
         
     # check for latest version
     if version <= VERSION:
         logger.info("You are already running the installed latest version of pythonbrew.")
         sys.exit()
     
     download_url = get_pythonbrew_update_url(version)
     if not download_url:
         logger.error("`%s` of pythonbrew not found." % version)
         sys.exit(1)
     resp = get_response_from_url(download_url)
     content_type = resp.info()['content-type']
     if not is_gzip(content_type, Link(download_url).filename):
         logger.error("Invalid content-type: `%s`" % content_type)
         sys.exit(1)
     
     filename = "pythonbrew-%s" % version
     distname = "%s.tgz" % filename
     download_file = os.path.join(PATH_DISTS, distname)
     try:
         d = Downloader()
         d.download(distname, download_url, download_file)
     except:
         logger.error("Failed to download. `%s`" % download_url)
         sys.exit(1)
     
     extract_dir = os.path.join(PATH_BUILD, filename)
     rm_r(extract_dir)
     if not unpack_downloadfile(content_type, download_file, extract_dir):
         sys.exit(1)
     
     try:
         installer_path = "%s/pythonbrew" % (extract_dir)
         logger.info("Installing %s into %s" % (extract_dir, ROOT))
         PythonbrewInstaller().install(installer_path)
     except:
         logger.error("Failed to update pythonbrew.")
         raise
         sys.exit(1)
     logger.info("The pythonbrew has been updated.")
示例#3
0
 def _update_pythonbrew(self, options, args):
     # pythonbrew update
     if options.head:
         version = 'head'
     else:
         version = get_stable_version()
         # check for version
         if not options.force and version <= VERSION:
             logger.info("You are already running the installed latest version of pythonbrew.")
             return
     
     download_url = get_pythonbrew_update_url(version)
     if not download_url:
         logger.error("`%s` of pythonbrew not found." % version)
         sys.exit(1)
     headinfo = get_headerinfo_from_url(download_url)
     content_type = headinfo['content-type']
     # head is only for gzip.
     if not options.head and not is_gzip(content_type, Link(download_url).filename):
         logger.error("Invalid content-type: `%s`" % content_type)
         sys.exit(1)
     
     filename = "pythonbrew-%s" % version
     distname = "%s.tgz" % filename
     download_file = os.path.join(PATH_DISTS, distname)
     try:
         d = Downloader()
         d.download(distname, download_url, download_file)
     except:
         logger.error("Failed to download. `%s`" % download_url)
         sys.exit(1)
     
     extract_dir = os.path.join(PATH_BUILD, filename)
     rm_r(extract_dir)
     if not unpack_downloadfile(content_type, download_file, extract_dir):
         sys.exit(1)
     
     try:
         logger.info("Installing %s into %s" % (extract_dir, ROOT))
         s = Subprocess()
         s.check_call('%s %s/pythonbrew_install.py --upgrade' % (sys.executable, extract_dir))
     except:
         logger.error("Failed to update pythonbrew.")
         sys.exit(1)
     logger.info("The pythonbrew has been updated.")
示例#4
0
 def unpack(self):
     if not unpack_downloadfile(self.content_type, self.download_file, self.build_dir):
         sys.exit(1)