1 | import sys |
---|
2 | import os |
---|
3 | import stat |
---|
4 | import locale |
---|
5 | import tempfile |
---|
6 | |
---|
7 | class shmanager: |
---|
8 | def __init__(self,packagekit=None,action=None,app={}): |
---|
9 | self.locale=locale.getlocale()[0] |
---|
10 | self.dbg=0 |
---|
11 | self.pluginInfo={'install':'sh'} |
---|
12 | if action=='install': |
---|
13 | self.install_App(app) |
---|
14 | #def __init__ |
---|
15 | |
---|
16 | def set_debug(self,dbg='1'): |
---|
17 | self.dbg=int(dbg) |
---|
18 | self.debug ("Debug enabled") |
---|
19 | #def set_debug |
---|
20 | |
---|
21 | def debug(self,msg=''): |
---|
22 | if self.dbg==1: |
---|
23 | print ('DEBUG Zmd: '+msg) |
---|
24 | #def debug |
---|
25 | |
---|
26 | def register(self): |
---|
27 | return(self.pluginInfo) |
---|
28 | #def register |
---|
29 | |
---|
30 | def execute_action(self,action,applist): |
---|
31 | count=len(applist) |
---|
32 | if (action): |
---|
33 | if action=='install': |
---|
34 | self._install_App(appInfo) |
---|
35 | self.progress=100 |
---|
36 | return(self.result) |
---|
37 | #def execute_action |
---|
38 | |
---|
39 | def _install_App(self,appInfo): |
---|
40 | return_msg=False |
---|
41 | appUrl=appinfo['installerUrl'] |
---|
42 | self.debug("Checking availabilty for "+appUrl) |
---|
43 | tmpDir=tempfile.mkdtemp(None,None,'/tmp') |
---|
44 | fileName=appUrl.split('/')[-1] |
---|
45 | dest_path=tmpDir+'/'+fileName |
---|
46 | if self._download_App(appUrl,dest_path): |
---|
47 | os.chdir(tmpDir) |
---|
48 | os.chmod(dest_path, stat.S_IRUSR|stat.S_IWUSR|stat.S_IXUSR) |
---|
49 | #def install_App |
---|
50 | |
---|
51 | def _download_App(self,appUrl,dest_path=None): |
---|
52 | appUrl.strip() |
---|
53 | if not dest_path: |
---|
54 | tmpDir=tempfile.mkdtemp(None,None,'/tmp') |
---|
55 | dest_path=tmpDir+'/'+appUrl.split('/')[-1] |
---|
56 | self.debug("Downloading "+appUrl+" to "+dest_path) |
---|
57 | try: |
---|
58 | urllib.request.urlretrieve(appUrl,dest_path) |
---|
59 | return_msg=True |
---|
60 | except Exception as e: |
---|
61 | self.debug(str(e)) |
---|
62 | return_msg=False |
---|
63 | return return_msg |
---|
64 | #def _download_App |
---|