import sys import os import stat import locale import tempfile class shmanager: def __init__(self,packagekit=None,action=None,app={}): self.locale=locale.getlocale()[0] self.dbg=0 self.pluginInfo={'install':'sh'} if action=='install': self.install_App(app) #def __init__ def set_debug(self,dbg='1'): self.dbg=int(dbg) self.debug ("Debug enabled") #def set_debug def debug(self,msg=''): if self.dbg==1: print ('DEBUG Zmd: '+msg) #def debug def register(self): return(self.pluginInfo) #def register def execute_action(self,action,applist): count=len(applist) if (action): if action=='install': self._install_App(appInfo) self.progress=100 return(self.result) #def execute_action def _install_App(self,appInfo): return_msg=False appUrl=appinfo['installerUrl'] self.debug("Checking availabilty for "+appUrl) tmpDir=tempfile.mkdtemp(None,None,'/tmp') fileName=appUrl.split('/')[-1] dest_path=tmpDir+'/'+fileName if self._download_App(appUrl,dest_path): os.chdir(tmpDir) os.chmod(dest_path, stat.S_IRUSR|stat.S_IWUSR|stat.S_IXUSR) #def install_App def _download_App(self,appUrl,dest_path=None): appUrl.strip() if not dest_path: tmpDir=tempfile.mkdtemp(None,None,'/tmp') dest_path=tmpDir+'/'+appUrl.split('/')[-1] self.debug("Downloading "+appUrl+" to "+dest_path) try: urllib.request.urlretrieve(appUrl,dest_path) return_msg=True except Exception as e: self.debug(str(e)) return_msg=False return return_msg #def _download_App