def standardize_path(path, pathsep='/', explicit_cwd=False): _path_ = path or '' _path_ = _path_.replace('"', '') \ .replace("'", '/') if not _path_ and (not explicit_cwd): return '' if (not explicit_cwd) and (not os.path.isabs(_path_)): _path_ = os.path.relpath(_path_) else: _path_ = os.path.realpath(_path_) if pathsep == '/': _path_ = _path_.replace('\\', '/') else: _path_ = _path_.replace('/', '\\') if _path_ and os_isdir(_path_): if not _path_.endswith(pathsep): _path_ += pathsep return _path_
def clear_dir(filedir): filedir = standardize_dir(filedir, explicit_cwd=True) if not os.path.exists(filedir): return if not os_isdir(filedir): raise TypeError('"{}" is not a directory'.format(filedir)) for item in os.listdir(filedir): path = filedir + item if os_isdir(path): shutil.rmtree(path) else: os.remove(path)
def _build_mod_list(mod_path: list, suffix: str, blacklist: list) -> list: """ _build_mod_list(mod_path, suffix) -> Add all the paths in mod_path to sys.path and return a list of all modules in sys.path ending in suffix. """ from sys import path as sys_path mod_path = [mod_path] if type(mod_path) is str else mod_path blacklist = [blacklist] if type(blacklist) is str else blacklist # Add suffix to all names in blacklist. blacklist.extend(["%s%s" % (name, suffix) for name in blacklist if not name.endswith(suffix)]) # Add the path of this file to the search path. mod_path.append(os_abspath(os_dirname(__file__))) # Add the path(s) in mod_path to sys.path so we can import from # them. [sys_path.extend((path, os_dirname(path.rstrip("/")))) for path in mod_path if path not in sys_path] # Build the list of modules ending in suffix in the mod_path(s). mod_list = ( (path, name) for path in sys_path if os_isdir(path) for name in os_listdir(path) if name.endswith(suffix) and name not in blacklist ) return mod_list
def get_files(file_list): """ Returns a list of all the files in filename. """ from os.path import isdir as os_isdir from os.path import isdir as os_isfile from os.path import join as os_join from os import walk as os_walk from pathlib import Path out_list = [] ext = ['.mp3', '.flac', '.ogg', '.s3m', '.mod', '.xm', '.it'] for name in file_list: if os_isdir(name): for root, sub, files in os_walk(name): join_list = [ os_join(root, f) for f in files if Path(f.lower()).suffix in ext ] out_list.extend(join_list) else: out_list.append(name) return out_list
def updateInfo(self): self.activityTimer.stop() # system("touch /boot/dummy") # if fileExists("/boot/dummy"): # os_remove("/boot/dummy") if fileExists("/.meoinfo"): self.myClose(_("Sorry, Meoboot can be installed or upgraded only when booted from Flash")) self.close() else: system("chown -R root:root /usr/lib/enigma2/python/Plugins/Extensions/MeoBoot") system("chmod -R a+x /usr/lib/enigma2/python/Plugins/Extensions/MeoBoot/contrib") system("chmod a+x /usr/lib/enigma2/python/Plugins/Extensions/MeoBoot/ex_init.py") for fn in listdir("/media/meoboot/MbootM"): dirfile = "/media/meoboot/MbootM/" + fn if os_isdir(dirfile): target = dirfile + "/usr/lib/enigma2/python/Plugins/Extensions/MeoBoot" cmd = "rm -r " + target + " > /dev/null 2>&1" system(cmd) cmd = "cp -r /usr/lib/enigma2/python/Plugins/Extensions/MeoBoot " + target system(cmd) cmd = "cp -r /usr/lib/enigma2/python/Plugins/Extensions/MeoBoot/contrib/meoinit /sbin/meoinit" system(cmd) out = open("/media/meoboot/MbootM/.version", "w") out.write(PLUGINVERSION) out.close() self.myClose(_("MeoBoot successfully updated. You can restart the plugin now.\nHave fun !!"))
def _build_mod_list(mod_path, suffix, blacklist): """ _build_mod_list(mod_path, suffix) -> Add all the paths in mod_path to sys.path and return a list of all modules in sys.path ending in suffix. """ from sys import path as sys_path mod_path = [mod_path] if type(mod_path) is str else mod_path blacklist = [blacklist] if type(blacklist) is str else blacklist # Add suffix to all names in blacklist. blacklist.extend([ '%s%s' % (name, suffix) for name in blacklist if not name.endswith(suffix) ]) # Add the path of this file to the search path. mod_path.append(os_abspath(os_dirname(__file__))) # Add the path(s) in mod_path to sys.path so we can import from # them. [ sys_path.extend((path, os_dirname(path.rstrip('/')))) for path in mod_path if path not in sys_path ] # Build the list of modules ending in suffix in the mod_path(s). mod_list = ((path, name) for path in sys_path if os_isdir(path) for name in os_listdir(path) if name.endswith(suffix) and name not in blacklist) return mod_list
def domyInstall(self, answer): mydev = "" cmd = "cp " + pluginpath + "/contrib/meoinit /sbin/meoinit" system(cmd) cmd = "ln -sfn /sbin/meoinit /sbin/init" system(cmd) system("rm -f /media/meoboot") cmd = "ln -sfn " + self.instdevice + " /media/meoboot" system(cmd) system("mkdir /media/meoboot/MbootM") system("mkdir /media/meoboot/MbootUpload") out = open("/media/meoboot/MbootM/.meoboot", "w") out.write("Flash") out.close() f = open("/proc/mounts",'r') for line in f.readlines(): if line.find(self.instdevice) != -1: parts = line.strip().split() mydev = parts[0] f.close() if os_isdir("/usr/lib/enigma2/python/Blackhole") == False: if mydev: out = open("/etc/fstab", "a") line = "\nmount " + mydev + " " + self.instdevice out.write(line) out.close() #Upgrade images for fn in listdir("/media/meoboot/MbootM"): dirfile = "/media/meoboot/MbootM/" + fn if os_isdir(dirfile): target = dirfile + "/usr/lib/enigma2/python/Plugins/Extensions/MeoBoot" cmd = "rm -r " + target + " > /dev/null 2>&1" system(cmd) cmd = "cp -r /usr/lib/enigma2/python/Plugins/Extensions/MeoBoot " + target system(cmd) out = open("/media/meoboot/MbootM/.version", "w") out.write(PLUGINVERSION) out.close() self.myClose(_("MeoBoot successfully installed. You can restart the plugin now.\nHave fun !!"))
def updateInfo(self): if pathExists('/media/usb/ImageBoot'): neoboot = 'usb' elif pathExists('/media/hdd/ImageBoot'): neoboot = 'hdd' device = '/media/' + neoboot + '' usfree = '0' devicelist = ['cf', 'hdd', 'card', 'usb', 'usb2'] for d in devicelist: test = '/media/' + d + '/ImageBoot/.neonextboot' if fileExists(test): device = '/media/' + d rc = system('df > /tmp/ninfo.tmp') f = open('/proc/mounts', 'r') for line in f.readlines(): if line.find('/hdd') != -1: self.backupdir = '/media/' + neoboot + '/NeoBootImageBackup' device = '/media/' + neoboot + '' f.close() if pathExists(self.backupdir) == 0 and createDir(self.backupdir): pass if fileExists('/tmp/ninfo.tmp'): f = open('/tmp/ninfo.tmp', 'r') for line in f.readlines(): line = line.replace('part1', ' ') parts = line.strip().split() totsp = len(parts) - 1 if parts[totsp] == device: if totsp == 5: usfree = parts[3] else: usfree = parts[2] break f.close() os_remove('/tmp/ninfo.tmp') self.availablespace = usfree[0:-3] strview = _('Masz zainstalowane nas\xc5\xa7\xc4\x99puj\xc4\x85ce obrazy') self['lab1'].setText(strview) strview = _('Masz jeszcze wolne: ') + self.availablespace + ' MB' self['lab2'].setText(strview) imageslist = ['Flash'] for fn in listdir('/media/' + neoboot + '/ImageBoot'): dirfile = '/media/' + neoboot + '/ImageBoot/' + fn if os_isdir(dirfile) and imageslist.append(fn): pass self['list'].list = imageslist
def extractImage(self): count = 0 for fn in listdir("/media/meoboot/MbootM"): dirfile = "/media/meoboot/MbootM/" + fn if os_isdir(dirfile): count = count +1; if count > 7: myerror = _("Sorry you can install a max of 8 images.") self.session.open(MessageBox, myerror, MessageBox.TYPE_INFO) elif int(self.availablespace) < 500: myerror = _("Sorry there is not enought available space on your device. You need at least 500 Mb free to install a new image") self.session.open(MessageBox, myerror, MessageBox.TYPE_INFO) else: self.session.open(mbImageSetup)
def find_folder(object_names: list) -> list: """ Функция ищет имена папок, имена файлов и скрытых папок в Linux (начинающиеся с точки) исключаются :param object_names: список имен файлов и папок :return: список, содержащий только имена папок """ list_folders = [] for i in object_names: check_patch = patch_to_folder + "/{}".format(i) if os_isdir(check_patch) and i[ 0] != ".": # Проверка является ли директорией и исключает скрытые папки в Linux list_folders.append(i) return list_folders
def traverse_dir(rootdir='.', pathsep='/', explicit_cwd=True, *, recurse=False, subdirs_only=False, files_only=False): if not is_windows_os: raise NotImplementedError('only available on windows OS') if (subdirs_only is False) and (files_only is False): subdirs_only = True files_only = True rootdir = standardize_dir(rootdir, pathsep, explicit_cwd) if recurse: args = 'dir /b /s "{}"'.format(rootdir) else: args = 'dir /b "{}"'.format(rootdir) with os.popen(args) as os_cmd: out = os_cmd.read() out = out.split('\n') out.sort() if out and out[0] == '': del out[0] if recurse is False: out = [rootdir + p for p in out] if subdirs_only and files_only: return out elif subdirs_only: return [path for path in out if os_isdir(path)] elif files_only: return [path for path in out if os_isfile(path)]
def get_files(file_list): """ Returns a list of all the files in filename. """ from os.path import isdir as os_isdir from os.path import isdir as os_isfile from os.path import join as os_join from os import walk as os_walk out_list = [] for name in file_list: if os_isdir(name): for root, sub, files in os_walk(name): join_list = [os_join(root, f) for f in files] out_list.extend(join_list) else: out_list.append(name) return out_list
def _build_mod_list(mod_path: list) -> list: """ _build_mod_list(mod_path, suffix) -> Add all the paths in mod_path to sys.path and return a list of all modules in sys.path ending in suffix. """ mod_path = [mod_path] if type(mod_path) is str else mod_path # Add the path of this file to the search path. mod_path.append(os_abspath(os_dirname(__file__))) # Build the list of modules in mod_path(s). mod_list = ('{0}.{1}.{2}'.format(os_basename(path), \ os_basename(root).replace(os_basename(path), ''), \ name.rsplit('.', 1)[0]).replace('..', '.') \ for path in mod_path \ if os_isdir(path) \ for root, dirs, files in os_walk(path) \ for name in files \ if name.endswith('.py')) return mod_list
def _build_mod_list(mod_path): """ _build_mod_list(mod_path, suffix) -> Add all the paths in mod_path to sys.path and return a list of all modules in sys.path ending in suffix. """ mod_path = [mod_path] if type(mod_path) is str else mod_path # Add the path of this file to the search path. mod_path.append(os_abspath(os_dirname(__file__))) # Build the list of modules in mod_path(s). mod_list = ('{0}.{1}.{2}'.format(os_basename(path), \ os_basename(root).replace(os_basename(path), ''), \ name.rsplit('.', 1)[0]).replace('..', '.') \ for path in mod_path \ if os_isdir(path) \ for root, dirs, files in os_walk(path) \ for name in files \ if name.endswith('.py')) return mod_list
def get_files(file_list): """ Returns a list of all the files in filename. """ from os.path import isdir as os_isdir from os.path import isdir as os_isfile from os.path import join as os_join from os import walk as os_walk from pathlib import Path out_list = [] ext = ['.mp3', '.flac', '.ogg', '.s3m', '.mod', '.xm', '.it'] for name in file_list: if os_isdir(name): for root, sub, files in os_walk(name): join_list = [os_join(root, f) for f in files if Path(f.lower()).suffix in ext] out_list.extend(join_list) else: out_list.append(name) return out_list
def updateInfo(self): curimage = "Flash" if fileExists("/.meoinfo"): f = open("/.meoinfo",'r') curimage = f.readline().strip() f.close() strview = _("Current Running Image: ") + curimage self.curimage = curimage self["lab1"].setText(strview) device = "meoboot" for d in listdir("/media/"): if d == "meoboot": continue test = "/media/" + d + "/MbootM/.meoboot" if fileExists(test): device = d strview = _("MeoBoot Installed on: ") + device self["lab2"].setText(strview) icon = "dev_usb.png" if device == "card" or device == "sd": icon = "dev_sd.png" elif device == "hdd": icon = "dev_hdd.png" elif device == "cf": icon = "dev_cf.png" icon = pluginpath + "/icons/" + icon png = LoadPixmap(icon) self["lab3"].instance.setPixmap(png) device = "/media/" + device ustot = usfree = usperc = "" rc = system("df > /tmp/ninfo.tmp") if fileExists("/tmp/ninfo.tmp"): f = open("/tmp/ninfo.tmp",'r') for line in f.readlines(): line = line.replace('part1', ' ') parts = line.strip().split() totsp = (len(parts) -1) if parts[totsp] == device: if totsp == 5: ustot = parts[1] usfree = parts[3] usperc = parts[4] else: ustot = "N/A " usfree = parts[2] usperc = parts[3] break f.close() os_remove("/tmp/ninfo.tmp") self.availablespace = usfree[0:-3] strview =_("Used: ") + usperc + _(" Available: ") + usfree[0:-3] + " MB" self["lab4"].setText(strview) imageslist = ["Flash"] for fn in listdir("/media/meoboot/MbootM"): dirfile = "/media/meoboot/MbootM/" + fn if os_isdir(dirfile): imageslist.append(fn) self["list"].list = imageslist
import sqlite3 from configs import PATH from os.path import isfile as os_isfile, join as os_join, isdir as os_isdir from os import mkdirs as os_mkdirs from __future__ import print_function _PIC_PATH = os_join(PATH, 'banners') if not os_isdir(_PIC_PATH): os_mkdirs(_PIC_PATH) _DB_PATH = os_join(PATH, 'series.db') _TABLE_NAMES = { 'series':{ 'query':'create table series (seriesid integer primary key' + ', firstaired text, imdb_id text, overview text, language text,' + ' rating real, ratingcount integer, runtime real, banner text,' + ' poster text, seriesname text, status text)' ,'attributes':['seriesid','firstaired','imdb_id','overview' ,'language','rating','ratingcount','runtime' ,'banner','poster','seriesname','status']}, 'episode':{ 'query':'create table episode ( episodeid integer primary key,' + 'seriesid integer, seasonid integer, episodeoverview text,' + ' director text, episodename text, episodenumber integer,' + ' firstaired text, seasonnumber integer, rating real,' + ' ratingcount integer, writer text, filename text)' ,'attributes':['episodeid','seriesid','seasonid' ,'episodeoverview','director','episodename' ,'episodenumber','firstaired','seasonnumber' ,'rating','ratingcount','writer','filename']}, 'genre':{ 'query':'create table genre ( ' +