def remove_show(self, title):
        """Removes the DB entry & the strm files for the show given

        Parameters
        ----------
        title : :obj:`str`
            Title of the show

        Returns
        -------
        bool
            Delete successfull
        """
        title = re.sub(r'[?|$|!|:|#]', r'', title)
        folder = re.sub(
            r'[?|$|!|:|#]', r'',
            self.db[self.series_label][title]['alt_title'].encode('utf-8'))
        del self.db[self.series_label][title]
        self._update_local_db(filename=self.db_filepath, db=self.db)
        show_dir = os.path.join(self.tvshow_path, folder)
        if xbmcvfs.exists(show_dir):
            show_files = xbmcvfs.listdir(show_dir)[1]
            for filename in show_files:
                xbmcvfs.delete(os.path.join(show_dir, filename))
            xbmcvfs.rmdir(show_dir)
            return True
        return False
Esempio n. 2
0
def rmtree(path):
    dirs, files = xbmcvfs.listdir(path)
    for dir in dirs:
        rmtree(os.path.join(path, dir))
    for file in files:
        xbmcvfs.delete(os.path.join(path, file))
    xbmcvfs.rmdir(path)
Esempio n. 3
0
def __delete_directory_alt(source):
    log("delete directory alt")
    hidden = ['Thumbs.db', '.DS_Store']
    dirs, files = xbmcvfs.listdir(source)
    for d in dirs:
        d = os.path.join(source, d)
        dirs2, files2 = xbmcvfs.listdir(d)
        for d2 in dirs2:
            d2 = os.path.join(d, d2)
            if not xbmcvfs.rmdir(d2):
                raise ValueError('xbmcvfs.rmdir', d2)
        for f2 in files2:
            f2 = os.path.join(d, f2)
            if not xbmcvfs.delete(f2):
                raise ValueError('xbmcvfs.delete', f2)
        for h in hidden:
            h = os.path.join(d, h)
            if xbmcvfs.exists(h):
                if not xbmcvfs.delete(h):
                    raise ValueError('xbmcvfs.delete', h)
        if not xbmcvfs.rmdir(d):
            raise ValueError('xbmcvfs.rmdir', d)

    for f in files:
        f = os.path.join(source, f)
        if not xbmcvfs.delete(f):
            raise ValueError('xbmcvfs.delete', f)
    for h in hidden:
        h = os.path.join(source, h)
        if xbmcvfs.exists(h):
            if not xbmcvfs.delete(h):
                raise ValueError('xbmcvfs.delete', h)

    if not xbmcvfs.rmdir(source):
        raise ValueError('xbmcvfs.rmdir', source)
def recursive_delete_dir(fullpath):
    '''helper to recursively delete a directory'''
    if PY_V >= 3:
        success = True
        dirs, files = xbmcvfs.listdir(fullpath)

        for file in files:
            success = xbmcvfs.delete(os.path.join(fullpath, file))
        for directory in dirs:
            success = recursive_delete_dir(os.path.join(fullpath, directory))
        success = xbmcvfs.rmdir(fullpath)
        return success
    else:
        success = True
        if not isinstance(fullpath, unicode):
            fullpath = fullpath.decode("utf-8")
        dirs, files = xbmcvfs.listdir(fullpath)
        for file in files:
            file = file.decode("utf-8")
            success = xbmcvfs.delete(os.path.join(fullpath, file))
        for directory in dirs:
            directory = directory.decode("utf-8")
            success = recursive_delete_dir(os.path.join(fullpath, directory))
        success = xbmcvfs.rmdir(fullpath)
        return success
	def extract_and_copy(extraction=0):
		i = 0
		for root, dirs, files in os.walk(extract_path, topdown=False):
			for file in files:
				dirfile = os.path.join(root, file)
				
				# Sanitize filenames - converting them to ASCII - and remove them from folders
				f = xbmcvfs.File(dirfile)
				temp = f.read()
				f.close()
				xbmcvfs.delete(dirfile)
				dirfile_with_path_name = os.path.relpath(dirfile, extract_path)
				dirfile_with_path_name = re.sub(r"[/\\]{1,2}","-", dirfile_with_path_name)
				dirfile_with_path_name = _UNICODE(dirfile_with_path_name).encode('ascii', 'ignore')
				new_dirfile = os.path.join(extract_path, dirfile_with_path_name)
				os.write(os.open(new_dirfile, os.O_RDWR | os.O_CREAT), temp)
				
				# Get the file extention
				ext = os.path.splitext(new_dirfile)[1][1:].lower()
				if ext in sub_ext and xbmcvfs.exists(new_dirfile):
					if not new_dirfile in legendas_tmp:
						#Append the matching file
						legendas_tmp.append(new_dirfile)
				elif ext in "rar zip" and not extraction:
					# Extract compressed files, extracted priorly
					xbmc.executebuiltin("XBMC.Extract(%s, %s)" % (new_dirfile, extract_path))
					xbmc.sleep(1000)
					extract_and_copy(1)
				elif ext not in "idx": 
					xbmcvfs.delete(new_dirfile)
			for dir in dirs:
				dirfolder = os.path.join(root, dir)
				xbmcvfs.rmdir(dirfolder)
 def extract_and_copy(extraction=0):
     for root, dirs, files in os.walk(extractPath, topdown=False):
         for file in files:
             dirfile = os.path.join(root, file)
             
             # Sanitize filenames - converting them to ASCII - and remove them from folders
             f = xbmcvfs.File(dirfile)
             temp = f.read()
             f.close()
             xbmcvfs.delete(dirfile)
             dirfile_with_path_name = normalizeString(os.path.relpath(dirfile, extractPath))
             dirname, basename = os.path.split(dirfile_with_path_name)
             dirname = re.sub(r"[/\\]{1,10}","-", dirname)
             dirfile_with_path_name = "(%s)%s" % (dirname, basename) if len(dirname) else basename
             new_dirfile = os.path.join(extractPath, dirfile_with_path_name)
             with open(new_dirfile, "w") as f:
                 f.write(temp)
             
             # Get the file extension
             ext = os.path.splitext(new_dirfile)[1][1:].lower()
             if ext in sub_ext and xbmcvfs.exists(new_dirfile):
                 if not new_dirfile in subtitles:
                     #Append the matching file
                     subtitles.append(new_dirfile)
             elif ext in "rar zip" and not extraction:
                 # Extract compressed files, extracted priorly
                 xbmc.executebuiltin("XBMC.Extract(%s, %s)" % (new_dirfile, extractPath))
                 xbmc.sleep(1000)
                 extract_and_copy(1)
             elif ext not in "idx": 
                 xbmcvfs.delete(new_dirfile)
         for dir in dirs:
             dirfolder = os.path.join(root, dir)
             xbmcvfs.rmdir(dirfolder)
    def __init__(self):

        #Check if a path has been set in the addon settings
        settings_path = common.addon.get_setting('meta_folder_location')
        
        if settings_path:
            self.path = xbmc.translatePath(settings_path)
        else:
            self.path = xbmc.translatePath('special://profile/addon_data/script.module.metahandler')

        self.work_path = os.path.join(self.path, 'work')
        self.cache_path = os.path.join(self.path,  'meta_cache')
        self.videocache = os.path.join(self.cache_path, 'video_cache.db')
        self.work_videocache = os.path.join(self.work_path, 'video_cache.db')
        self.movie_images = os.path.join(self.cache_path, 'movie')
        self.tv_images = os.path.join(self.cache_path, 'tvshow')        
        
        self.table_list = ['movie_meta', 'tvshow_meta', 'season_meta', 'episode_meta']
     
        common.addon.log('---------------------------------------------------------------------------------------', 2)
        #delete and re-create work_path to ensure no previous files are left over
        if xbmcvfs.exists(self.work_path):
            import shutil
            try:
                common.addon.log('Removing previous work folder: %s' % self.work_path, 2)
                # shutil.rmtree(self.work_path)
                xbmcvfs.rmdir(self.work_path)
            except Exception, e:
                common.addon.log('Failed to delete work folder: %s' % e, 4)
                pass
def autostart():
        xbmcaddon.Addon().setSetting(id="files_overwrite", value='false')
        tempdir = os.path.join(__addonprofile__, 'temp')
        service_runtime  = str(setting.get('service_runtime') + ':00')
        log('## Service - Run at startup: %s'% setting.get('service_startup'), xbmc.LOGNOTICE)        
        log('## Service - Delayed startup: %s minutes'% setting.get('service_startupdelay'), xbmc.LOGNOTICE)   
        log('## Service - Run as service: %s'% setting.get('service_enable'), xbmc.LOGNOTICE)
        log('## Service - Time: %s'% service_runtime, xbmc.LOGNOTICE)
        log("##########........................")
        # Check if tempdir exists and remove it
        if xbmcvfs.exists(tempdir):
            xbmcvfs.rmdir(tempdir)
            log('Removing temp folder from previous aborted run.')
            xbmc.sleep(5000)
        # Run script when enabled and check on existence of tempdir.
        # This because it is possible that script was running even when we previously deleted it.
        # Could happen when switching profiles and service gets triggered again
        if setting.get('service_startup') and not xbmcvfs.exists(tempdir):
            xbmc.executebuiltin('XBMC.AlarmClock(ArtworkDownloader,XBMC.RunScript(script.artwork.downloader,silent=true),00:%s:15,silent)' % setting.get('setting.service_startupdelay')) 
        if setting.get('service_enable'):
            while (not xbmc.abortRequested):
                xbmc.sleep(5000)
                if not(time.strftime('%H:%M') == service_runtime):
                    pass
                else:
                    if not xbmcvfs.exists(tempdir):
                        log('Time is %s:%s, Scheduled run starting' % (time.strftime('%H'), time.strftime('%M')))
                        xbmc.executebuiltin('XBMC.RunScript(script.artwork.downloader,silent=true)')
                        # Because we now use the commoncache module the script is run so fast it is possible it is started twice
                        # within the one minute window. So keep looping until it goes out of that window
                        while (not xbmc.abortRequested and time.strftime('%H:%M') == service_runtime):
                            xbmc.sleep(5000)
                    else:
                        log('Addon already running, scheduled run aborted', xbmc.LOGNOTICE)
Esempio n. 9
0
def remove_movie(title):
    movie_dir = get_movie_dir(title)[0]
    xbmcvfs.rmdir(movie_dir+os.sep, force=True)
    if generic_utility.get_setting('update_db') == 'true':
        xbmc.executebuiltin('CleanLibrary(video)')
    else:
        xbmc.executebuiltin("Container.Refresh")
Esempio n. 10
0
def remove_series(series_title):
    series_file = get_series_dir(series_title)
    xbmcvfs.rmdir(series_file+os.sep, force=True)
    if generic_utility.get_setting('update_db') == 'true':
        xbmc.executebuiltin('CleanLibrary(video)')
    else:
        xbmc.executebuiltin("Container.Refresh")
Esempio n. 11
0
def remove_files(path):
    dirs, files = xbmcvfs.listdir(path)
    for d in dirs:
        remove_files("%s%s/" % (path, d))
    for f in files:
        xbmcvfs.delete("%s%s" % (path, f))
    xbmcvfs.rmdir(path)
Esempio n. 12
0
 def delete(self, path, inner=False):
     dirlist, filelist = self.listdir(path, full=True)
     [xbmcvfs.delete(self._path(x)) for x in filelist]
     [self.delete(self._path(x)) for x in dirlist]
     if not inner:
         if not xbmcvfs.delete(self._path(path)):
             xbmcvfs.rmdir(self._path(path))
Esempio n. 13
0
 def cleanup(self):
     for i in range(MAXCAMS):
         if self.cams[i]['tmpdir']:
             files = xbmcvfs.listdir(self.cams[i]['tmpdir'])[1]
             for file in files:
                 xbmcvfs.delete(os.path.join(self.cams[i]['tmpdir'], file))
             xbmcvfs.rmdir(self.cams[i]['tmpdir'])
Esempio n. 14
0
def delete(path):
    dirs, files = xbmcvfs.listdir(path)
    for file in files:
        xbmcvfs.delete(path + file)
    for dir in dirs:
        delete(path + dir + '/')
    xbmcvfs.rmdir(path)
Esempio n. 15
0
    def set_m3u8(self,sUrl):
        if xbmcvfs.exists(video_file) == 1:
            xbmcvfs.rmdir(video_file, True)
            xbmcvfs.mkdirs("%s%s" % (video_file, 'm3u8/'))
        else:
            xbmcvfs.mkdirs("%s%s" % (video_file, 'm3u8/'))

        req = urllib3.PoolManager(retries=False)
        rep = req.request('GET', sUrl, headers=HEADERS)
        stat = rep.status
        if stat:
            if not stat == 200:
                return False
            else:
                cFile = xbmcvfs.File("%s%s%s%s" % (video_file, 'm3u8/', self.filename, '.m3u8'), 'w')
                sHtmlContent = rep.data.splitlines()
                
                i = 0
                for x in sHtmlContent:  
                    if not x.startswith('#') and x != '':
                        cFile.write("%s%s%s%s" % (video_file, str(i), '.ts', '\n'))
                        if x.startswith('http'):
                            self.urls_list.append(x)
                        else:
                            self.urls_list.append('%s/%s' % (sUrl.rsplit('/',1)[0], x))
                            
                        i+=1

                    else:
                        if not x.startswith('#EXT-X-BYTERANGE'): #jawcloud
                            cFile.write("%s%s" % (x, '\n'))

                cFile.close()
                return True
def autostart():
        xbmcaddon.Addon().setSetting(id="files_overwrite", value='false')
        settings = _settings()
        settings._get_general()
        addondir = xbmc.translatePath( utils.__addon__.getAddonInfo('profile') )
        tempdir = os.path.join(addondir, 'temp')
        service_runtime  = str(settings.service_runtime + ':00')
        log('Service - Run at startup: %s'%settings.service_startup, xbmc.LOGNOTICE)        
        log('Service - Delayed startup: %s minutes'%settings.service_startupdelay, xbmc.LOGNOTICE)   
        log('Service - Run as service: %s'%settings.service_enable, xbmc.LOGNOTICE)
        log('Service - Time: %s'%service_runtime, xbmc.LOGNOTICE)
        if xbmcvfs.exists(tempdir):
            xbmcvfs.rmdir(tempdir)
            log('Removing temp folder from previous run.')
        if settings.service_startup:
            if settings.service_startupdelay != '--':
                xbmc.executebuiltin('XBMC.AlarmClock(ArtworkDownloader,XBMC.RunScript(script.artwork.downloader,silent=true),00:%s:00,silent)' %settings.service_startupdelay) 
            else:
                xbmc.executebuiltin('XBMC.AlarmClock(ArtworkDownloader,XBMC.RunScript(script.artwork.downloader,silent=true),00:00:20,silent)') 
        if settings.service_enable:
            while (not xbmc.abortRequested):
                xbmc.sleep(5000)
                if not(time.strftime('%H:%M') == service_runtime):
                    pass
                else:
                    if not xbmcvfs.exists(tempdir):
                        log('Time is %s:%s, Scheduled run starting' % (time.strftime('%H'), time.strftime('%M')))
                        xbmc.executebuiltin('XBMC.RunScript(script.artwork.downloader,silent=true)')
                    else:
                        log('Addon already running, scheduled run aborted', xbmc.LOGNOTICE)
Esempio n. 17
0
 def extract_and_copy(extraction=0):
     i = 0
     for root, dirs, files in os.walk(extract_path, topdown=False):
         for file in files:
             dirfile = os.path.join(root, file)
             
             # Sanitize filenames - converting them to ASCII - and remove them from folders
             f = xbmcvfs.File(dirfile)
             temp = f.read()
             f.close()
             xbmcvfs.delete(dirfile)
             dirfile_with_path_name = os.path.relpath(dirfile, extract_path)
             dirfile_with_path_name = re.sub(r"[/\\]{1,2}","-", dirfile_with_path_name)
             dirfile_with_path_name = LTV._UNICODE(dirfile_with_path_name).encode('ascii', 'ignore')
             new_dirfile = os.path.join(extract_path, dirfile_with_path_name)
             os.write(os.open(new_dirfile, os.O_RDWR | os.O_CREAT), temp)
             
             # Get the file extention
             ext = os.path.splitext(new_dirfile)[1][1:].lower()
             if ext in sub_ext and xbmcvfs.exists(new_dirfile):
                 if not new_dirfile in legendas_tmp:
                     #Append the matching file
                     legendas_tmp.append(new_dirfile)
             elif ext in "rar zip" and not extraction:
                 # Extract compressed files, extracted priorly
                 xbmc.executebuiltin("XBMC.Extract(%s, %s)" % (new_dirfile, extract_path))
                 xbmc.sleep(1000)
                 extract_and_copy(1)
             elif ext not in "idx": 
                 xbmcvfs.delete(new_dirfile)
         for dir in dirs:
             dirfolder = os.path.join(root, dir)
             xbmcvfs.rmdir(dirfolder)
Esempio n. 18
0
def cache():
    try:
        xbmcvfs.rmdir(generic_utility.cache_dir(), force=True)
        generic_utility.log('Cache folder deleted.')
        generic_utility.notification(generic_utility.get_string(30309))
    except Exception:
        pass
Esempio n. 19
0
def cache():
    try:
        xbmcvfs.rmdir(generic_utility.cache_dir(), force=True)
        generic_utility.log('Cache folder deleted.')
        generic_utility.notification(generic_utility.get_string(30309))
    except Exception:
        pass
Esempio n. 20
0
def rm(path, quiet=False, recursive=False):
    if not exists(path):
        if debug:
            xbmc.log("******** VFS rmdir notice: %s does not exist" % path)
        return False
    if not quiet:
        msg = "Confirmation"
        msg2 = "Please confirm directory removal!"
        if not confirm(msg, msg2, path):
            return False

    if not recursive:
        try:
            xbmcvfs.delete(path)
        except Exception as e:
            xbmc.log("******** VFS error: %s" % e)
    else:
        dirs, files = ls(path)
        for f in files:
            r = os.path.join(xbmc.translatePath(path), f)
            try:
                xbmcvfs.delete(r)
            except Exception as e:
                xbmc.log("******** VFS error: %s" % e)
        for d in dirs:
            subdir = os.path.join(xbmc.translatePath(path), d)
            rm(subdir, quiet=True, recursive=True)
        try:
            xbmcvfs.rmdir(path)
        except Exception as e:
            xbmc.log("******** VFS error: %s" % e)
    return True
Esempio n. 21
0
 def delete(self, path, inner=False):
     dirlist, filelist = self.listdir(path, full=True)
     [xbmcvfs.delete(self._path(x)) for x in filelist]
     [self.delete(self._path(x)) for x in dirlist]
     if not inner:
         if not xbmcvfs.delete(self._path(path)):
             xbmcvfs.rmdir(self._path(path))
Esempio n. 22
0
    def remove_movie(self, title, year):
        """Removes the DB entry & the strm file for the movie given

        Parameters
        ----------
        title : :obj:`str`
            Title of the movie

        year : :obj:`int`
            Release year of the movie

        Returns
        -------
        bool
            Delete successfull
        """
        title = re.sub(r'[?|$|!|:|#]', r'', title)
        movie_meta = '%s (%d)' % (title, year)
        folder = re.sub(r'[?|$|!|:|#]', r'',
                        self.db[self.movies_label][movie_meta]['alt_title'])
        del self.db[self.movies_label][movie_meta]
        self._update_local_db(filename=self.db_filepath, db=self.db)
        dirname = os.path.join(self.movie_path, folder)
        filename = os.path.join(self.movie_path, folder, movie_meta + '.strm')
        if xbmcvfs.exists(dirname):
            xbmcvfs.delete(filename)
            xbmcvfs.rmdir(dirname)
            return True
        return False
Esempio n. 23
0
def remove_dir (path):
       dirList, flsList = xbmcvfs.listdir(path)
       for fl in flsList: 
            xbmcvfs.delete(os.path.join(path, fl))
       for dr in dirList: 
            remove_dir(os.path.join(path, dr))
       xbmcvfs.rmdir(path)
Esempio n. 24
0
 def set_url_list(self,urlslist):
     self.urls_list = urlslist
     self.modEXT = True
     if xbmcvfs.exists(video_file) == 1:
         xbmcvfs.rmdir(video_file, True)
         xbmcvfs.mkdir("%s" % (video_file))
     else:
         xbmcvfs.mkdir("%s" % (video_file))
Esempio n. 25
0
def recursive_delete_dir(fullpath):
    '''helper to recursively delete a directory, including all files'''
    dirs, files = xbmcvfs.listdir(fullpath)
    for file in files:
        xbmcvfs.delete(os.path.join(fullpath, file))
    for directory in dirs:
        recursive_delete_dir(os.path.join(fullpath, directory))
    xbmcvfs.rmdir(fullpath)
Esempio n. 26
0
    def login(self):
        log('login')
        header_dict = {}
        header_dict[
            'Accept'] = 'application/json, text/javascript, */*; q=0.01'
        header_dict['Host'] = 'api.pluto.tv'
        header_dict['Connection'] = 'keep-alive'
        header_dict['Referer'] = 'http://pluto.tv/'
        header_dict['Origin'] = 'http://pluto.tv'
        header_dict[
            'User-Agent'] = 'Mozilla/5.0 (Windows NT 6.2; rv:24.0) Gecko/20100101 Firefox/24.0'

        #ignore guest login
        if USER_EMAIL == LANGUAGE(30009):
            return

        if len(USER_EMAIL) > 0:
            try:
                #remove COOKIE_JAR Folder
                xbmcvfs.rmdir(COOKIE_JAR)
            except:
                pass

            if xbmcvfs.exists(COOKIE_JAR) == False:
                try:
                    xbmcvfs.mkdirs(SETTINGS_LOC)
                    f = xbmcvfs.File(COOKIE_JAR, 'w')
                    f.close()
                except:
                    log('login, Unable to create the storage directory',
                        xbmc.LOGERROR)

            form_data = ({
                'optIn': 'true',
                'password': PASSWORD,
                'synced': 'false',
                'userIdentity': USER_EMAIL
            })
            self.net.set_cookies(COOKIE_JAR)
            try:
                loginlink = json.loads(
                    self.net.http_POST(
                        BASE_API + '/auth/local',
                        form_data=form_data,
                        headers=header_dict).content.encode("utf-8").rstrip())
                if loginlink and loginlink['email'].lower(
                ) == USER_EMAIL.lower():
                    xbmcgui.Dialog().notification(
                        ADDON_NAME,
                        LANGUAGE(30006) + loginlink['displayName'], ICON, 4000)
                    self.net.save_cookies(COOKIE_JAR)
                    return True
                else:
                    xbmcgui.Dialog().notification(ADDON_NAME, LANGUAGE(30007),
                                                  ICON, 4000)
            except Exception, e:
                log('login, Unable to create the storage directory ' + str(e),
                    xbmc.LOGERROR)
Esempio n. 27
0
def delete_directory(source):
    dirs, files = xbmcvfs.listdir(source)
    for d in dirs:
        d = os.path.join(source, d)
        delete_directory(d)
    for f in files:
        f = os.path.join(source, f)
        xbmcvfs.delete(f)
    xbmcvfs.rmdir(source)
Esempio n. 28
0
def removeDirectory(path):
    if xbmcvfs.exists(path):
        allDirs, allFiles = xbmcvfs.listdir(path)
        for dir in allDirs:
            xbmcvfs.rmdir(os.path.join(path,dir))
        for file in allFiles:
            xbmcvfs.delete(os.path.join(path,file))
        
        xbmcvfs.rmdir(path)
def cleanFolder(path):
    dirs, files = xbmcvfs.listdir(path)
    for file in files:
        full = path + '/' + file
        xbmcvfs.delete(full)
    for dir in dirs:
        full = path + '/' + dir
        cleanFolder(full)
    xbmcvfs.rmdir(path)
Esempio n. 30
0
def rmtree(path):
    if isinstance(path, unicode):
        path = path.encode('utf-8')
    dirs, files = xbmcvfs.listdir(path)
    for dir in dirs:
        rmtree(os.path.join(path, dir))
    for file in files:
        xbmcvfs.delete(os.path.join(path, file))
    xbmcvfs.rmdir(path)
Esempio n. 31
0
def rmtree(path):
    if isinstance(path, unicode):
        path = path.encode('utf-8')
    dirs, files = xbmcvfs.listdir(path)
    for dir in dirs:
        rmtree(os.path.join(path, dir))
    for file in files:
        xbmcvfs.delete(os.path.join(path, file))
    xbmcvfs.rmdir(path)
Esempio n. 32
0
def addon():
    dialog = xbmcgui.Dialog()
    if dialog.yesno(generic_utility.addon_name + ':', generic_utility.get_string(30307)):
        try:
            xbmcvfs.rmdir(generic_utility.data_dir(), force=True)
            generic_utility.log('Addon userdata folder deleted.')
            generic_utility.notification(generic_utility.get_string(30308))
        except Exception:
            pass
Esempio n. 33
0
 def remove_temp_dir(self):
     temp_path = 'special://temp/plugin.video.youtube/'
     try:
         xbmcvfs.rmdir(temp_path, force=True)
         return True
     except:
         self.context.log_debug(
             'Failed to remove directory: {dir}'.format(dir=temp_path))
         return False
Esempio n. 34
0
def removeDirectory(path):
    if xbmcvfs.exists(path):
        allDirs, allFiles = xbmcvfs.listdir(path)
        for dir in allDirs:
            xbmcvfs.rmdir(os.path.join(path,dir))
        for file in allFiles:
            xbmcvfs.delete(os.path.join(path,file))
        
        xbmcvfs.rmdir(path)
Esempio n. 35
0
def addon():
    dialog = xbmcgui.Dialog()
    if dialog.yesno(utility.addon_name + ':', utility.get_string(30307)):
        try:
            xbmcvfs.rmdir(utility.data_dir(), force=True)
            utility.log('Addon userdata folder deleted.')
            utility.notification(utility.get_string(30308))
        except Exception:
            pass
Esempio n. 36
0
def __delete_directory_alt(source):
	dirs, files = xbmcvfs.listdir(source)
	for d in dirs:
		d = os.path.join(source, d)
		__delete_directory(d)
	for f in files:
		f = os.path.join(source, f)
		xbmcvfs.delete(f)
	xbmcvfs.rmdir(source)
Esempio n. 37
0
    def login(self, user, password):
        log('login')
        if len(user) > 0:
            try:
                xbmcvfs.rmdir(COOKIE_JAR)
            except:
                pass

            if xbmcvfs.exists(COOKIE_JAR) == False:
                try:
                    xbmcvfs.mkdirs(SETTINGS_LOC)
                    f = xbmcvfs.File(COOKIE_JAR, 'w')
                    f.close()
                except:
                    log('login, Unable to create the storage directory',
                        xbmc.LOGERROR)

            try:
                login = self.mechze
                login.set_handle_robots(False)
                login.set_cookiejar(self.cj)
                login.addheaders = [(
                    'User-Agent',
                    'Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)'
                )]
                login.open(LOGIN_URL)
                if '/myaccount' in login.response().read(): return True
                # login.open(LOGIN_URL)
                login.select_form(nr=0)
                login.form['email'] = user
                login.form['password'] = password
                login.submit()
                login.open(LOGIN_URL)
                if '/myaccount' not in login.response().read():
                    notificationDialog(LANGUAGE(30024))
                    return False
                self.cj.save(COOKIE_JAR, ignore_discard=True)
                return True
            except Exception as e:
                log("login, failed! " + str(e), xbmc.LOGERROR)
                notificationDialog(LANGUAGE(30001))
                return False
        else:
            #firstrun wizard
            if yesnoDialog(LANGUAGE(30010),
                           no=LANGUAGE(30008),
                           yes=LANGUAGE(30009)):
                user = inputDialog(LANGUAGE(30006))
                password = inputDialog(LANGUAGE(30007),
                                       opt=xbmcgui.ALPHANUM_HIDE_INPUT)
                REAL_SETTINGS.setSetting('User_Email', user)
                REAL_SETTINGS.setSetting('User_Password', password)
                return self.login(user, password)
            else:
                okDialog(LANGUAGE(30012))
                return False
def delete_files(source, match, del_empty=False):
	# delete files from source if match
	dirs, files = xbmcvfs.listdir(source)
	for f in files:
		if match in f:
			f = os.path.join(source, f)
			xbmcvfs.delete(f)
	# delete source directory if empty
	if del_empty and len(xbmcvfs.listdir(source)) == 0:
		xbmcvfs.rmdir(source)
Esempio n. 39
0
    def remove_dir(self, path):
        dir_list, file_list = xbmcvfs.listdir(path)

        for file in file_list:
            xbmcvfs.delete(os.path.join(path, file))

        for directory in dir_list:
            self.remove_dir(os.path.join(path, directory))

        xbmcvfs.rmdir(path)
Esempio n. 40
0
def __delete_files_alt(source, match, del_empty):
	# delete files from source if match
	dirs, files = xbmcvfs.listdir(source)
	for f in files:
		if match == os.path.splitext(f)[0]:
			f = os.path.join(source, f)
			xbmcvfs.delete(f)
	# delete source directory if empty
	if del_empty and len(xbmcvfs.listdir(source)) == 0:
		xbmcvfs.rmdir(source)
Esempio n. 41
0
def delete_files(source, match, del_empty=False):
    # delete files from source if match
    dirs, files = xbmcvfs.listdir(source)
    for f in files:
        if match in f:
            f = os.path.join(source, f)
            xbmcvfs.delete(f)
    # delete source directory if empty
    if del_empty and len(xbmcvfs.listdir(source)) == 0:
        xbmcvfs.rmdir(source)
def __delete_directory_alt(source):
	dirs, files = xbmcvfs.listdir(source)
	for d in dirs:
		d = os.path.join(source, d)
		if not xbmcvfs.rmdir(d):
			raise ValueError('xbmcvfs.rmdir', d)
	for f in files:
		f = os.path.join(source, f)
		xbmcvfs.delete(f)
	if not xbmcvfs.rmdir(source):
		raise ValueError('xbmcvfs.rmdir', source)
Esempio n. 43
0
def rmtree(folder):
    import os
    current, dirs, files = walk(folder)

    for file in files:
        remove(os.path.join(current, file))

    for dir in dirs:
        rmtree(os.path.join(current, dir))

    xbmcvfs.rmdir(folder)
def rmtree(folder):
    import os
    current, dirs, files = walk(folder)

    for file in files:
        remove(os.path.join(current, file))

    for dir in dirs:
        rmtree(os.path.join(current, dir))

    xbmcvfs.rmdir(folder)
Esempio n. 45
0
	def rmdir(self, path, quiet=False):
		if not self.exists(path):
			xbmc.log('******** VFS rmdir notice: %s does not exist' % path)
			return False
		if not quiet:
			msg = 'Remove Directory'
			msg2 = 'Please confirm directory removal!'
			if not self.confirm(msg, msg2, path): return False
		try:		
			xbmcvfs.rmdir(path)
		except Exception, e:
			xbmc.log('******** VFS error: %s' % e)
Esempio n. 46
0
    def _rmtree(self, directory, removeSelf=False):
        self.log("Processing folder %s" % directory, level=xbmc.LOGDEBUG)

        dirs, files = xbmcvfs.listdir(directory)
        for f in files:
            fileName = os.path.join(directory, f)
            self.log(" -- delete %s" % fileName, level=xbmc.LOGDEBUG)
            xbmcvfs.delete(fileName)
        for d in dirs:
            self._rmtree(os.path.join(directory, d), removeSelf=True)
        if removeSelf:
            self.log(" -- delete %s" % directory, level=xbmc.LOGDEBUG)
            xbmcvfs.rmdir(directory)
def cleanup():
    if xbmcvfs.exists(tempdir):
        dialog_msg('update', percentage = 100, line1 = __localize__(32005), background =  __addon__.getSetting('background'))
        log('Cleaning up temp files')
        for x in os.listdir(tempdir):
            tempfile = os.path.join(tempdir, x)
            xbmcvfs.delete(tempfile)
            if xbmcvfs.exists(tempfile):
                log('Error deleting temp file: %s' % tempfile, xbmc.LOGERROR)
        xbmcvfs.rmdir(tempdir)
        if xbmcvfs.exists(tempdir):
            log('Error deleting temp directory: %s' % tempdir, xbmc.LOGERROR)
        else:
            log('Deleted temp directory: %s' % tempdir)
Esempio n. 48
0
def nestedDelete(rootDir):
    # If the file already exists, delete it
    if dir_exists(rootDir):
        # Remove the png files in the directory first
        dirs, files = xbmcvfs.listdir(rootDir)
        # Remove nested directories first
        for adir in dirs:
            nestedDelete(os_path_join(rootDir, adir))
        # If there are any nested files remove them
        for aFile in files:
            xbmcvfs.delete(os_path_join(rootDir, aFile))
        # Now remove the actual directory
        xbmcvfs.rmdir(rootDir)
    else:
        log("nestedDelete: Directory %s does not exist" % rootDir)
def cleanDirectory(directory):
    try:
        if xbmcvfs.exists(directory):
            for root, dirs, files in os.walk(directory):
                for f in files:
                    file = os.path.join(root, f)
                    xbmcvfs.delete(file)
                for d in dirs:
                    dir = os.path.join(root, d)
                    xbmcvfs.rmdir(dir)
    except:
        pass
    
    if not xbmcvfs.exists(directory):
        os.makedirs(directory)
def Download(language, hash, filename, dlLink):
    subtitle_list = []
    ## Cleanup temp dir, we recomend you download/unzip your subs in temp folder and
    ## pass that to XBMC to copy and activate
    if xbmcvfs.exists(TEMP_FOLDER):
        xbmcvfs.rmdir(TEMP_FOLDER,True)
    xbmcvfs.mkdirs(TEMP_FOLDER)
    filename = os.path.basename(xbmc.Player().getPlayingFile().decode('utf-8'))
    filename = filename[:filename.rfind(".")] + ".srt"
    filename = os.path.join(TEMP_FOLDER, filename)
    napiHelper = SubTiToolHelper(filename, hash)
    filename = napiHelper.download(dlLink,language)
    subtitle_list.append(filename)  # this can be url, local path or network path.

    return subtitle_list
Esempio n. 51
0
    def _del_path(self, path):

        common.addon.log('Attempting to remove folder: %s' % path, 0)
        if xbmcvfs.exists(path):
            try:
                common.addon.log('Removing folder: %s' % path, 0)
                try:
                    dirs, files = xbmcvfs.listdir(path)
                    for file in files:
                        xbmcvfs.delete(os.path.join(path, file))
                    success = xbmcvfs.rmdir(path)
                    if success == 0:
                        raise
                except Exception as e:
                    try:
                        common.addon.log('Failed to delete path using xbmcvfs: %s' % e, 4)
                        common.addon.log('Attempting to remove with shutil: %s' % path, 0)
                        shutil.rmtree(path)
                    except:
                        raise
            except Exception as e:
                common.addon.log('Failed to delete path: %s' % e, 4)
                return False
        else:
            common.addon.log('Folder does not exist: %s' % path)
Esempio n. 52
0
    def delete_empty_folders(self, location):
        """
        Delete the folder if it is empty. Presence of custom file extensions can be ignored while scanning.

        To achieve this, edit the ignored file types setting in the addon settings.

        Example:
            success = delete_empty_folders(path)

        :type location: str
        :param location: The path to the folder to be deleted.
        :rtype: bool
        :return: True if the folder was deleted successfully, False otherwise.
        """
        if not get_setting(delete_folders):
            debug("Deleting of empty folders is disabled.")
            return False

        folder = self.unstack(location)[0]  # Stacked paths should have the same parent, use any
        debug("Checking if %r is empty" % folder)
        ignored_file_types = [file_ext.strip() for file_ext in get_setting(ignore_extensions).split(",")]
        debug("Ignoring file types %r" % ignored_file_types)

        subfolders, files = xbmcvfs.listdir(folder)
        debug("Contents of %r:\nSubfolders: %r\nFiles: %r" % (folder, subfolders, files))

        empty = True
        try:
            for f in files:
                _, ext = os.path.splitext(f)
                if ext and not ext in ignored_file_types:  # ensure f is not a folder and its extension is not ignored
                    debug("Found non-ignored file type %r" % ext)
                    empty = False
                    break
        except OSError as oe:
            debug("Error deriving file extension. Errno " + str(oe.errno), xbmc.LOGERROR)
            empty = False

        # Only delete directories if we found them to be empty (containing no files or filetypes we ignored)
        if empty:
            debug("Directory is empty and will be removed")
            try:
                # Recursively delete any subfolders
                for f in subfolders:
                    debug("Deleting file at " + str(os.path.join(folder, f)))
                    self.delete_empty_folders(os.path.join(folder, f))

                # Delete any files in the current folder
                for f in files:
                    debug("Deleting file at " + str(os.path.join(folder, f)))
                    xbmcvfs.delete(os.path.join(folder, f))

                # Finally delete the current folder
                return xbmcvfs.rmdir(folder)
            except OSError as oe:
                debug("An exception occurred while deleting folders. Errno " + str(oe.errno), xbmc.LOGERROR)
                return False
        else:
            debug("Directory is not empty and will not be removed")
            return False
Esempio n. 53
0
def recursiveDelete(path):
    success = True
    path = try_encode(path)
    dirs, files = xbmcvfs.listdir(path)
    for file in files:
        success = xbmcvfs.delete(os.path.join(path,file))
    for dir in dirs:
        success = recursiveDelete(os.path.join(path,dir))
    success = xbmcvfs.rmdir(path)
    return success 
    def remove_show(self, title):
        """Removes the DB entry & the strm files for the show given

        Parameters
        ----------
        title : :obj:`str`
            Title of the show

        Returns
        -------
        bool
            Delete successfull
        """
        title = re.sub(r'[?|$|!|:|#]', r'', title)
        label = self.series_label
        rep_str = self.db[label][title]['alt_title'].encode('utf-8')
        folder = re.sub(
            pattern=r'[?|$|!|:|#]',
            repl=r'',
            string=rep_str)
        progress = xbmcgui.DialogProgress()
        progress.create(self.kodi_helper.get_local_string(1210), title)
        time.sleep(0.5)
        del self.db[self.series_label][title]
        self._update_local_db(filename=self.db_filepath, db=self.db)
        show_dir = self.nx_common.check_folder_path(
            path=os.path.join(self.tvshow_path, folder))
        if xbmcvfs.exists(show_dir):
            show_files = xbmcvfs.listdir(show_dir)[1]
            episode_count_total = len(show_files)
            step = round(100.0 / episode_count_total, 1)
            percent = 100 - step
            for filename in show_files:
                progress.update(int(percent))
                xbmcvfs.delete(os.path.join(show_dir, filename))
                percent = percent - step
                time.sleep(0.05)
            xbmcvfs.rmdir(show_dir)
            return True
        return False
        time.sleep(1)
        progress.close()
def recursive_delete_dir(path):
    '''helper to recursively delete a directory'''
    success = True
    path = try_encode(path)
    dirs, files = xbmcvfs.listdir(path)
    for file in files:
        success = xbmcvfs.delete(os.path.join(path, file))
    for directory in dirs:
        success = recursive_delete_dir(os.path.join(path, directory))
    success = xbmcvfs.rmdir(path)
    return success
Esempio n. 56
0
def rmdir(path):

    """
    rmdir(path) -- Remove a folder.

    path        : folder

    example:
     - success = vfs.rmdir(path)
    """

    return xbmcvfs.rmdir(path)
def __delete_files_alt(source, match, del_empty):
	# delete files from source if match
	dirs, files = xbmcvfs.listdir(source)
	for f in files:
		if os.path.splitext(f)[0].startswith(match):
			f = os.path.join(source, f)
			if not xbmcvfs.delete(f):
				raise ValueError('xbmcvfs.delete', f)
	# delete source directory if empty
	if del_empty and len(xbmcvfs.listdir(source)) == 0:
		if not xbmcvfs.rmdir(source):
			raise ValueError('xbmcvfs.rmdir', source)