def downloadPlugin(url, plugin): """download a plugin and unzip that it""" plugin.status["installStatus"] = "downloading" plugin.save() if not url.endswith(".zip"): feed = True else: feed = False if feed: try: downloaded = zeroinstallHelper.downloadZeroFeed(url) feedName = zeroinstallHelper.getFeedName(url) except: plugin.status["installStatus"] = "failed" plugin.status["result"] = str(sys.exc_info()[1][0]) plugin.save() return False plugin.url = url plugin.save() else: downloaded = downloadChunks(url) if not downloaded: plugin.status["installStatus"] = "failed" plugin.status["result"] = "processed" plugin.save() return False plugin.status["installStatus"] = "installed" #for now rename it to the name of the zip file if not feed: plugin.name = os.path.splitext(os.path.basename(url))[0] plugin.path = os.path.join(settings.PLUGIN_PATH, plugin.name ) plugin.save() unzipStatus = unzip_archive(plugin.path, downloaded) #clean up os.unlink(downloaded) os.rmdir(os.path.dirname(downloaded)) if unzipStatus: plugin.status["result"] = "unzipped" else: plugin.status["result"] = "failed to unzip" plugin.save() else: pluginDirs = [ name for name in os.listdir(downloaded) if os.path.isdir(os.path.join(downloaded, name)) ] if pluginDirs: plugin.path = os.path.join(downloaded,pluginDirs[0]) plugin.status["result"] = "0install" plugin.selected = True plugin.active = True #get version using the same function used in views.py plugin.version = get_version(os.path.join(plugin.path,"launch.sh")) plugin.name = feedName.replace(" ","") plugin.save()
def downloadPluginZeroInstall(url, plugin, logger=None): """ To be called for zeroinstall xml feed urls. Returns plugin prototype, not full plugin model object. """ try: downloaded = zeroinstallHelper.downloadZeroFeed(url) feedName = zeroinstallHelper.getFeedName(url) except: logger.exception("Failed to fetch zeroinstall feed") plugin.status["installStatus"] = "failed" plugin.status["result"] = str(sys.exc_info()[1][0]) return False # The url field stores the zeroinstall feed url plugin.url = url plugin.name = feedName.replace(" ", "") if not downloaded: logger.error("Failed to download url: '%s'", url) plugin.status["installStatus"] = "failed" plugin.status["result"] = "processed" return False plugin.status["installStatus"] = "installed" # Find plugin in subdirectory of extracted and installed path for d in os.listdir(downloaded): # Skip MACOSX attribute zip artifact if d == '__MACOSX': continue nestedpath = os.path.join(downloaded, d) if not os.path.isdir(nestedpath): continue # only take subdirectory with launch.sh script if os.path.exists(os.path.join(nestedpath, 'launch.sh')): plugin.path = os.path.normpath(nestedpath) break if os.path.exists(os.path.join(nestedpath, plugin.name + '.py')): plugin.path = os.path.normpath(nestedpath) break else: # Plugin expanded without top level folder plugin.path = downloaded # assert launch.sh exists? plugin.status["result"] = "0install" # Other fields we can get from zeroinstall feed? logger.debug(plugin) # Version is parsed during install - from launch.sh, ignoring feed value return plugin
def downloadPluginZeroInstall(url, plugin, logger=None): """ To be called for zeroinstall xml feed urls. Returns plugin prototype, not full plugin model object. """ try: downloaded = zeroinstallHelper.downloadZeroFeed(url) feedName = zeroinstallHelper.getFeedName(url) except: logger.exception("Failed to fetch zeroinstall feed") plugin.status["installStatus"] = "failed" plugin.status["result"] = str(sys.exc_info()[1][0]) return False # The url field stores the zeroinstall feed url plugin.url = url plugin.name = feedName.replace(" ","") if not downloaded: logger.error("Failed to download url: '%s'", url) plugin.status["installStatus"] = "failed" plugin.status["result"] = "processed" return False plugin.status["installStatus"] = "installed" # Find plugin in subdirectory of extracted and installed path for d in os.listdir(downloaded): # Skip MACOSX attribute zip artifact if d == '__MACOSX': continue nestedpath = os.path.join(downloaded, d) if not os.path.isdir(nestedpath): continue # only take subdirectory with launch.sh script if os.path.exists(os.path.join(nestedpath, 'launch.sh')): plugin.path = os.path.normpath(nestedpath) break if os.path.exists(os.path.join(nestedpath, plugin.name + '.py')): plugin.path = os.path.normpath(nestedpath) break else: # Plugin expanded without top level folder plugin.path = downloaded # assert launch.sh exists? plugin.status["result"] = "0install" # Other fields we can get from zeroinstall feed? logger.debug(plugin) # Version is parsed during install - from launch.sh, ignoring feed value return plugin