Esempio n. 1
0
def select(params, src):
    paramArr = __parseParams(params)
    title = paramArr[0]
    params = paramArr[1]
    menuItems = params.split("|")
    return select(title, menuItems)
 def downloadCustomModules(self):
     
     def get_dir_listing(url):
         
         
         f = urllib.urlopen(url)
         response = f.read()
         f.close()
         
         text = response.split("\n")
         urls = []
         httptag = "http://"
         tag=' href="'
         for line in text:
             if tag in line.lower():
                 for i, _ in enumerate(line):
                     if tag == line[i:i+len(tag)].lower():
                         textline = line[i+len(tag):]
                         end = textline.find('"')
                         u = textline[:end]
                         if not httptag in u and not ".." in u and not "mailto:" in u and not "mailto:" in u:
                             if url[-1] != "/":
                                 u = url+"/"+u
                             else:
                                 u = url+u
                             if not "/." in u:
                                 urls.append(u)
     
         return urls
     
     
     def downloadFile(url, file_path):
         urllib.urlretrieve(url, file_path)
         return os.path.isfile(file_path)
     
     
     def extract(fileOrPath, directory):                
         if not directory.endswith(':') and not os.path.exists(directory):
             os.mkdir(directory)
     
         zf = zipfile.ZipFile(fileOrPath)
     
         for _, name in enumerate(zf.namelist()):
             if name.endswith('/'):
                 os.makedirs(os.path.join(directory, name), 0777)
             else:
                 outfile = open(os.path.join(directory, name), 'wb')
                 outfile.write(zf.read(name))
                 outfile.flush()
                 outfile.close()
                 
 
 
     repo_url = self._customModulesRepo
    
     xbmcUtils.showBusyAnimation()
     files = get_dir_listing(repo_url)
     menuItems = map(lambda x: x.replace(repo_url,'').replace('.zip',''), files)
     xbmcUtils.hideBusyAnimation()
     
     select = xbmcUtils.select('Select module', menuItems)
     if select:
         target = os.path.join(self._customModulesFolder, select + '.zip')
         
         xbmcUtils.showBusyAnimation()
         index = menuItems.index(select)
         success = downloadFile(files[index], target)
         xbmcUtils.hideBusyAnimation()
        
         if success:
             extract(target, self._customModulesFolder)
             os.remove(target)
             return True
         else:
             return False
         
     return None
Esempio n. 3
0
def select(params,src):
    paramArr = __parseParams(params)
    title = paramArr[0]
    params = paramArr[1]
    menuItems = params.split("|")
    return select(title, menuItems)
 def downloadCustomModules(self):
     
     def get_dir_listing(url):
         
         
         f = urllib.urlopen(url)
         response = f.read()
         f.close()
         
         text = response.split("\n")
         urls = []
         httptag = "http://"
         tag=' href="'
         for line in text:
             if tag in line.lower():
                 for i, _ in enumerate(line):
                     if tag == line[i:i+len(tag)].lower():
                         textline = line[i+len(tag):]
                         end = textline.find('"')
                         u = textline[:end]
                         if not httptag in u and not ".." in u and not "mailto:" in u and not "mailto:" in u:
                             if url[-1] != "/":
                                 u = url+"/"+u
                             else:
                                 u = url+u
                             if not "/." in u:
                                 urls.append(u)
     
         return urls
     
     
     def downloadFile(url, file_path):
         urllib.urlretrieve(url, file_path)
         return os.path.isfile(file_path)
     
     
     def extract(fileOrPath, directory):                
         if not directory.endswith(':') and not os.path.exists(directory):
             os.mkdir(directory)
     
         zf = zipfile.ZipFile(fileOrPath)
     
         for _, name in enumerate(zf.namelist()):
             if name.endswith('/'):
                 os.makedirs(os.path.join(directory, name), 0777)
             else:
                 outfile = open(os.path.join(directory, name), 'wb')
                 outfile.write(zf.read(name))
                 outfile.flush()
                 outfile.close()
                 
 
 
     repo_url = self._customModulesRepo
    
     xbmcUtils.showBusyAnimation()
     files = get_dir_listing(repo_url)
     menuItems = map(lambda x: x.replace(repo_url,'').replace('.zip',''), files)
     xbmcUtils.hideBusyAnimation()
     
     select = xbmcUtils.select('Select module', menuItems)
     if select:
         target = os.path.join(self._customModulesFolder, select + '.zip')
         
         xbmcUtils.showBusyAnimation()
         index = menuItems.index(select)
         success = downloadFile(files[index], target)
         xbmcUtils.hideBusyAnimation()
        
         if success:
             extract(target, self._customModulesFolder)
             os.remove(target)
             return True
         else:
             return False
         
     return None