def GET(self, path): path = import_path(path) gallery_fs_dir = os.path.dirname('%s/%s' % (self.data_dir, path)) images = files.list_files(gallery_fs_dir, files.file_is_image, recursive=False) parent_dir = os.path.dirname(os.path.dirname(path)) extended = [] for img in images: info = files.get_file_info(img, path_prefix=self.data_dir) exif = self._get_exif(Image.open(img)) info['exif_datetime'] = exif.get('DateTime') info['exif_model'] = '%s (%s)' % (exif.get('Model'), exif.get('Make')) info['exif_orientation'] = exif.get('Orientation') info['exif_light_source'] = exif.get('LightSource') info['exif_exposure_time'] = exif.get('ExposureTime') info['exif_scene_type'] = exif.get('SceneType') info['exif_image_width'] = exif.get('ExifImageWidth') info['exif_image_height'] = exif.get('ExifImageHeight') extended.append(info) page_list = files.strip_prefix(files.list_files(gallery_fs_dir, os.path.isdir, recursive=False, include_dirs=True), self.data_dir) page_list = map(lambda x: (x, os.path.basename(x)), page_list) values = dict(files=extended, page_list=page_list, parent_dir=parent_dir, curr_dir_name=self.get_current_dirname(path)) return self._render('gallery.html', values)
def __init__(self, args): # Creacion de la carpeta compartida self.sharedir = os.path.abspath(args["shared"]) P2Pnode.__create_shared(self.sharedir) self.files = files.list_files(self.sharedir + "/") self.virtualdir = {} print("[SHARED]", self.sharedir) for f in self.files: print("\t", f) self.__resource = [] self.__sem = None self.port = int(args["port"]) # Lista inicial vacía de los demás nodos en la red P2P self.peersocks = [] # Si no se pasan peers, una nueva red se inicia desde cero self.peernames = [] if args["peers"]: self.__search_peers(args["peers"].split(',')) else: print("No se pasaron peers. Este es el primero en la red P2P.") # Se inicializa el servicio de este nodo self.__initcomm(self.port)
def generate_page_list(self, curr_dir_fs): page_list = files.list_files(curr_dir_fs, None, recursive=False, include_dirs=True) return [(files.strip_prefix(x, self.data_dir), os.path.basename(files.strip_prefix(x, self.data_dir)), os.path.isdir(x)) for x in page_list]
async def get(self): images = files.list_files(self.data_dir, files.file_is_image, recursive=True) extended = [] for img in images: extended.append(files.get_file_info(img, path_prefix=self.data_dir)) return self.response_html('files.html', dict(files=extended))
def GET(self, path): if not path: raise web.seeother('%spage/index' % APP_PATH) path = import_path(path) page_fs_path = '%s/%s' % (self.data_dir, path) if files.page_is_dir(page_fs_path): try: metadata = json.load(open('%s/metadata.json' % page_fs_path, 'rb')) except IOError: metadata = {} if metadata.get('directoryType', 'page') == 'gallery': raise web.seeother('%sgallery/%s/index' % (APP_PATH, path)) else: raise web.seeother('%spage/%s/index' % (APP_PATH, path)) else: page_fs_path = '%s.md' % page_fs_path curr_dir = os.path.dirname(path) page_name = os.path.basename(path) # setup the directory information if curr_dir: parent_dir = '%s' % os.path.dirname(curr_dir) curr_dir_fs = '%s/%s' % (self.data_dir, curr_dir) else: curr_dir = u"\u2302" parent_dir = None curr_dir_fs = self.data_dir # transform the page if files.page_exists(page_fs_path): page_info = files.get_version_info(self.data_dir, page_fs_path, info_encoding=conf['hgInfoEncoding']) inner_html = load_markdown(page_fs_path) page_template = 'page.html' else: inner_html = '' page_info = '' page_template = 'dummy_page.html' page_list = files.strip_prefix(files.list_files(curr_dir_fs, None, recursive=False, include_dirs=True), self.data_dir) page_list = map(lambda x: (x, os.path.basename(x)), page_list) data = dict(html=inner_html, page_list=page_list, parent_dir=parent_dir, page_info=page_info, page_name=page_name, curr_dir_name=self.get_current_dirname(curr_dir)) return self._render(page_template, data)
def updateUiLoadApps(self): appsDir = os.path.expanduser('~/Apps') try: tree = files.list_files(appsDir) except: return [ '~/Apps not Found', 'ColourApp is not properly set in your system. Please create a directory called "~/Apps".' ] print(tree) items = files.tree_to_path(tree) print(items) for i in range(len(items[0])): QLWIItem = QListWidgetItem(items[0][i]) QLWIItem.setToolTip(items[1][i]) self.QLWApps.addItem(QLWIItem) return None
async def get(self): gallery_fs_dir = os.path.join(self.data_dir, self.riki_path) if files.page_is_dir(gallery_fs_dir): if self.dir_metadata.directory_type == 'page': raise web.HTTPSeeOther( f'{APP_PATH}page/{self.riki_path}/index') elif self.dir_metadata.directory_type == 'gallery': raise web.HTTPSeeOther( f'{APP_PATH}gallery/{self.riki_path}/index') else: raise web.HTTPServerError('Unknown page type') elif os.path.isfile(gallery_fs_dir): raise web.HTTPInternalServerError('Gallery directory malformed') elif os.path.basename(gallery_fs_dir) == 'index': gallery_fs_dir = os.path.dirname(gallery_fs_dir) else: raise web.HTTPNotFound() try: images = files.list_files(gallery_fs_dir, files.file_is_image, recursive=False) except FileNotFoundError: raise web.HTTPNotFound() extended: List[files.FileInfo] = [] for img in images: info = files.get_file_info(img, path_prefix=self.data_dir) info.metadata = pictures.get_metadata(img) extended.append(info) values = dict(files=extended, page_list=[], path_elms=path_dir_elms(self.riki_path), curr_dir_name=self.get_current_dirname(self.riki_path), num_files=await self.get_num_files(gallery_fs_dir), description=self.dir_metadata.description) return self.response_html('gallery.html', values)
def clear_logs(): d = join(dirname(BASE_DIR), 'logs') for f in list_files(d): f = f.replace('.log','') print 'remove', log_file(f) remove(log_file(f))
folders = input('\nFolders to be deleted [separate with spaces]: ').split() file_ext = input('File type that will be deleted [empty for entire folder]: ') try: folders = [Path(folder) for folder in folders] is_folder = [folder.is_dir() for folder in folders] assert all(is_folder) except AssertionError: print('Invalid folder.') else: if file_ext: if file_ext[0] != '.': file_ext = '.' + file_ext for folder in folders: for filename in folder.glob('*' + file_ext): print(filename) else: for folder in folders: list_files(str(folder)) if file_ext: for folder in folders: for filename in folder.glob('*' + file_ext): send2trash.send2trash(filename) else: for folder in folders: send2trash.send2trash(folder) print('\nMoved to trash.')
def main(): """ Main que gestiona todo el funcionamiento del sistema. :return: """ # Creamos un parser para los argumentos de entrada del programa parser = argparse.ArgumentParser(description="Cliente SecureBox") # Ayuda # Gestion de usuarios parser.add_argument("--create_id", nargs=2, metavar=('name', 'email')) parser.add_argument("--search_id", nargs=1, metavar=('data')) parser.add_argument("--delete_id", nargs=1, metavar=('user_id')) # Gestion de ficheros parser.add_argument("--upload", nargs=1, metavar=('file')) parser.add_argument("--source_id", nargs=1, metavar=('user_id')) parser.add_argument("--dest_id", nargs=1, metavar=('user_id')) parser.add_argument("--list_files", action='store_true') parser.add_argument("--download", nargs=1, metavar=('file_id')) parser.add_argument("--delete_file", nargs=1, metavar=('file_id')) # Gestion del cifrado y firmado de documentos parser.add_argument("--encrypt", nargs=1, metavar=('file')) parser.add_argument("--sign", nargs=1, metavar=('file')) parser.add_argument("--enc_sign", nargs=1, metavar=('file')) # Se parsean los argumentos args = parser.parse_args() # Si no se encuentan los parametros suficientes if len(sys.argv) < 2: print( "Se necesitan mas argumentos de entrada para ejecutar el programa." ) print("Si necesita ayuda ejecute el programa con la flag --help") return # Gestion de usuarios if args.create_id: users.register_user(name=args.create_id[0], email=args.create_id[1], token=token) elif args.search_id: users.search_user(data_search=args.search_id[0], token=token) elif args.delete_id: users.delete_user(user_id=args.delete_id[0], token=token) # Gestion de cifrado y firmado elif args.encrypt and args.dest_id: key = users.get_public_key(user_id=args.dest_id[0], token=token) crypto.encrypt(file=args.encrypt[0], public_key_receiver=key) elif args.sign: crypto.sign(file=args.sign[0]) elif args.enc_sign and args.dest_id: key = users.get_public_key(user_id=args.dest_id[0], token=token) crypto.encrypt_and_sign(file=args.enc_sign[0], public_key_receiver=key) # Gestion de ficheros elif args.upload and args.dest_id: key = users.get_public_key(user_id=args.dest_id[0], token=token) files.upload_file(file=args.upload[0], public_key_dest=key, token=token) elif args.list_files: files.list_files(token=token) elif args.download and args.source_id: key = users.get_public_key(user_id=args.source_id[0], token=token) files.download_file(file_id=args.download[0], public_key_receiver=key, token=token) elif args.delete_file: files.delete_file(file_id=args.delete_file[0], token=token) else: print("Comando no soportado") print( "Revise con el comando --help los comandos que puede ejecutar el cliente SecureBox." )
def item_list(d): dirs = [ basename(f) for f in list_files(d) if not f.startswith('.') and not f.startswith('Index') ] return '\n'.join(app_links(dirs))
def clear_logs(): d = environ['p'] + '/logs/' for f in list_files(d): f = f.replace('.log', '') print 'remove', log_file(f) remove(log_file(f))
def list_logs(): d = environ['p']+'/logs/' for f in list_files(d): f = f.replace('.log','') log = show_log(f) print len(log.split('\n')), log_file(f)
def list_logs(): d = join(dirname(BASE_DIR), 'logs') for f in list_files(d): f = f.replace('.log','') log = show_log(f) print len(log.split('\n')), log_file(f)
def clear_logs(): d = LOG_DIR for f in list_files(d): f = f.replace('.log','') print 'remove', log_file(f) remove(log_file(f))
def clear_logs(): d = environ['p']+'/logs/' for f in list_files(d): f = f.replace('.log','') print 'remove', log_file(f) remove(log_file(f))
def directory_listing(dir): return [x for x in list_files(dir) if not x in ['Index', 'Random']]
def list_logs(): d = join(dirname(BASE_DIR), 'logs') for f in list_files(d): f = f.replace('.log','') log = show_log(f) print len(log.split('\n')), log_file(f)
def clear_logs(): d = join(dirname(BASE_DIR), 'logs') for f in list_files(d): f = f.replace('.log','') print 'remove', log_file(f) remove(log_file(f))
def item_list(d): dirs = [ basename(f) for f in list_files(d) if not f.startswith('.') and not f.startswith('Index') ] return '\n'.join(app_links(dirs))
def GET(self): images = files.list_files(self.data_dir, files.file_is_image, recursive=True) extended = [] for img in images: extended.append(files.get_file_info(img, path_prefix=self.data_dir)) return self._render('files.html', dict(files=extended))
def list_logs(): d = environ['p'] + '/logs/' for f in list_files(d): f = f.replace('.log', '') log = show_log(f) print len(log.split('\n')), log_file(f)
def list_logs(): d = LOG_DIR for f in list_files(d): f = f.replace('.log', '') log = show_log(f) print len(log.split('\n')), log_file(f)
def list_logs(): d = LOG_DIR for f in list_files(d): f = f.replace('.log','') log = show_log(f) print len(log.split('\n')), log_file(f)
users.create_id(args.create_id[0], args.create_id[1]) elif args.search_id: users.search_id(args.search_id) elif args.delete_id: users.delete_id(args.delete_id) elif args.upload: if args.dest_id: files.upload(args.upload, args.dest_id) else: print("--upload necesita --dest_id") elif args.list_files: files.list_files() elif args.download: if args.source_id: files.download(args.download, args.source_id) else: print("--download necesita --source_id") elif args.delete_file: files.delete(args.delete_file) # Para encriptar pedimos la clave publica del destinatario, ciframos # y guardamos el fichero encriptado en path_archivos elif args.encrypt: if args.dest_id: publicKey = users.get_public_key(args.dest_id)
def clear_logs(): d = LOG_DIR for f in list_files(d): f = f.replace('.log', '') print 'remove', log_file(f) remove(log_file(f))
def directory_listing(dir): return [ x for x in list_files(dir) if not x in ['Index','Random'] ]
""" Created on Tue Sep 17 08:56:26 2019 """ import files as fl import database as db db_name = 'Freddiemac_Loan_Level_Dataset' db_origination = db.table_origination(db_name) db_monthly = db.table_monthly(db_name) fl.unzip_rawdata() files = fl.list_files(fl.unzip_path) for file in files: if 'txt' in file: if 'historical_data1_Q' in file: data = fl.read_txt_2_df(fl.unzip_path+file, seperator='|', header=None, rows = 2000000) for datum in data: datum.columns = db_origination.fields[0:26] datum.set_index('LOAN_SEQUENCE_NUMBER', inplace=True) db_origination.func_import_from_df(datum) if 'historical_data1_time_Q' in file: data = fl.read_txt_2_df(fl.unzip_path+file, seperator='|', header=None, rows = 2000000) for datum in data: datum.columns=db_monthly.fields[1:28] datum['Id'] = datum['LOAN_SEQUENCE_NUMBER'] +' '+ datum['MONTHLY_REPORTING_PERIOD'] datum.set_index('Id', inplace=True) db_monthly.func_import_from_df(datum)