Esempio n. 1
0
 def find_versions(self,app):
     version_re = "[a-zA-Z0-9\\.-_]+"
     appname_re = "(?P<version>%s)" % (version_re,)
     name_re = "(%s|%s)" % (app.name, urllib.quote(app.name))
     appname_re = join_app_version(name_re,appname_re,app.platform)
     filename_re = "%s\\.(zip|exe|from-(?P<from_version>%s)\\.patch)"
     filename_re = filename_re % (appname_re,version_re,)
     link_re = "href=['\"](?P<href>([^'\"]*/)?%s)['\"]" % (filename_re,)
     # Read the URL.  If this followed any redirects, update the
     # recorded URL to match the final endpoint.
     df = self.open_url(self.download_url)
     try:
         if df.url != self.download_url:
             self.download_url = df.url
     except AttributeError:
         pass
     # TODO: would be nice not to have to guess encoding here.
     try:
         downloads = df.read().decode("utf-8")
     finally:
         df.close()
     for match in re.finditer(link_re,downloads,re.I):
         version = match.group("version")
         href = match.group("href")
         from_version = match.group("from_version")
         # TODO: try to assign costs based on file size.
         if from_version is None:
             cost = 40
         else:
             cost = 1
         self.version_graph.add_link(from_version or "",version,href,cost)
     return self.version_graph.get_versions(app.version)
Esempio n. 2
0
 def _copy_best_version(self,app,uppath):
     best_vdir = join_app_version(app.name,app.version,app.platform)
     source = os.path.join(app.appdir,best_vdir)
     shutil.copytree(source,os.path.join(uppath,best_vdir))
     with open(os.path.join(source,ESKY_CONTROL_DIR,"bootstrap-manifest.txt"),"r") as manifest:
         for nm in manifest:
             nm = nm.strip()
             bspath = os.path.join(app.appdir,nm)
             dstpath = os.path.join(uppath,nm)
             if os.path.isdir(bspath):
                 shutil.copytree(bspath,dstpath)
             else:
                 if not os.path.isdir(os.path.dirname(dstpath)):
                     os.makedirs(os.path.dirname(dstpath))
                 shutil.copy2(bspath,dstpath)
Esempio n. 3
0
 def find_versions(self,app):
     version_re = "[a-zA-Z0-9\\.-_]+"
     appname_re = "(?P<version>%s)" % (version_re,)
     appname_re = join_app_version(app.name,appname_re,app.platform)
     filename_re = "%s\\.(zip|exe|from-(?P<from_version>%s)\\.patch)"
     filename_re = filename_re % (appname_re,version_re,)
     for nm in os.listdir(self.download_url):
         match = re.match(filename_re,nm)
         if match:
             version = match.group("version")
             from_version = match.group("from_version")
             if from_version is None:
                 cost = 40
             else:
                 cost = 1
             self.version_graph.add_link(from_version or "",version,nm,cost)
     return self.version_graph.get_versions(app.version)
Esempio n. 4
0
    def _copy_best_version(self,app,uppath,force_appdata_dir=True):
        """Copy the best version directory from the given app.

        This copies the best version directory from the given app into the
        unpacking path.  It's useful for applying patches against an existing
        version.
        """
        best_vdir = join_app_version(app.name,app.version,app.platform)
        #  TODO: remove compatability hooks for ESKY_APPDATA_DIR="".
        source = os.path.join(app.appdir,ESKY_APPDATA_DIR,best_vdir)
        if not os.path.exists(source):
            source = os.path.join(app.appdir,best_vdir)
        if not force_appdata_dir:
            dest = uppath
        else:
            dest = os.path.join(uppath,ESKY_APPDATA_DIR)
        try:
            os.mkdir(dest)
        except OSError, e:
            if e.errno not in (errno.EEXIST,183):
                raise
Esempio n. 5
0
 def find_versions(self,app):
     version_re = "[a-zA-Z0-9\\.-_]+"
     appname_re = "(?P<version>%s)" % (version_re,)
     appname_re = join_app_version(app.name,appname_re,app.platform)
     filename_re = "%s\\.(zip|exe|from-(?P<from_version>%s)\\.patch)"
     filename_re = filename_re % (appname_re,version_re,)
     link_re = "href=['\"](?P<href>([^'\"]*/)?%s)['\"]" % (filename_re,)
     # TODO: would be nice not to have to guess encoding here.
     df = self.open_url(self.download_url)
     try:
         downloads = df.read().decode("utf-8")
     finally:
         df.close()
     for match in re.finditer(link_re,downloads,re.I):
         version = match.group("version")
         href = match.group("href")
         from_version = match.group("from_version")
         # TODO: try to assign costs based on file size.
         if from_version is None:
             cost = 40
         else:
             cost = 1
         self.version_graph.add_link(from_version or "",version,href,cost)
     return self.version_graph.get_versions(app.version)
Esempio n. 6
0
 def _ready_name(self,app,version):
     version = join_app_version(app.name,version,app.platform)
     return os.path.join(self._workdir(app,"ready"),version)
Esempio n. 7
0
                     really_rmtree(uppath)
                     os.mkdir(uppath)
                     self._copy_best_version(app,uppath,False)
                     break
             except (PatchError,EnvironmentError):
                 self.version_graph.remove_all_links(patchurl)
                 try:
                     os.unlink(patchfile)
                 except EnvironmentError:
                     pass
                 raise
         else:
             break
 # Find the actual version dir that we're unpacking.
 # TODO: remove compatability hooks for ESKY_APPDATA_DIR=""
 vdir = join_app_version(app.name,version,app.platform)
 vdirpath = os.path.join(uppath,ESKY_APPDATA_DIR,vdir)
 if not os.path.isdir(vdirpath):
     vdirpath = os.path.join(uppath,vdir)
     if not os.path.isdir(vdirpath):
         self.version_graph.remove_all_links(path[0][1])
         err = version + ": version directory does not exist"
         raise EskyVersionError(err)
 # Move anything that's not the version dir into "bootstrap" dir.
 ctrlpath = os.path.join(vdirpath,ESKY_CONTROL_DIR)
 bspath = os.path.join(ctrlpath,"bootstrap")
 if not os.path.isdir(bspath):
     os.makedirs(bspath)
 for nm in os.listdir(uppath):
     if nm != vdir and nm != ESKY_APPDATA_DIR:
         really_rename(os.path.join(uppath,nm),
Esempio n. 8
0
                     really_rmtree(uppath)
                     os.mkdir(uppath)
                     self._copy_best_version(app,uppath,False)
                     break
             except (PatchError,EnvironmentError):
                 self.version_graph.remove_all_links(patchurl)
                 try:
                     os.unlink(patchfile)
                 except EnvironmentError:
                     pass
                 raise
         else:
             break
 # Find the actual version dir that we're unpacking.
 # TODO: remove compatability hooks for ESKY_APPDATA_DIR=""
 vdir = join_app_version(app.name,version,app.platform)
 vdirpath = os.path.join(uppath,ESKY_APPDATA_DIR,vdir)
 if not os.path.isdir(vdirpath):
     vdirpath = os.path.join(uppath,vdir)
     if not os.path.isdir(vdirpath):
         self.version_graph.remove_all_links(path[0][1])
         err = version + ": version directory does not exist"
         raise EskyVersionError(err)
 # Move anything that's not the version dir into "bootstrap" dir.
 ctrlpath = os.path.join(vdirpath,ESKY_CONTROL_DIR)
 bspath = os.path.join(ctrlpath,"bootstrap")
 if not os.path.isdir(bspath):
     os.makedirs(bspath)
 for nm in os.listdir(uppath):
     if nm != vdir and nm != ESKY_APPDATA_DIR:
         really_rename(os.path.join(uppath,nm),
Esempio n. 9
0
 def _ready_name(self, app, version):
     version = join_app_version(app.name, version, app.platform)
     return os.path.join(self._workdir(app, "ready"), version)