def getExpandedPath(path): if os.path.isfile(path): if ( path.lower().endswith('mpc-be.exe'.lower()) or path.lower().endswith('mpc-be64.exe'.lower()) or path.lower().endswith('mpc-beportable.exe'.lower()) ): return path if os.path.isfile(path + "mpc-be.exe"): path += "mpc-be.exe" return path if os.path.isfile(path + "\\mpc-be.exe"): path += "\\mpc-be.exe" return path if os.path.isfile(path + "mpc-beportable.exe"): path += "mpc-beportable.exe" return path if os.path.isfile(path + "\\mpc-beportable.exe"): path += "\\mpc-beportable.exe" return path if os.path.isfile(path + "mpc-be64.exe"): path += "mpc-be64.exe" return path if os.path.isfile(path + "\\mpc-be64.exe"): path += "\\mpc-be64.exe" return path
def is_crashing_test(path): """Checks for the string 'crash' in the file name""" if not path.endswith('expected.txt'): if 'crash' in path.lower(): if 'svn' not in path.lower(): return True return False
def getExpandedPath(path): if os.path.isfile(path): if path.lower().endswith(u'mpc-hc.exe'.lower()) or path.lower( ).endswith(u'mpc-hc64.exe'.lower()) or path.lower().endswith( u'mpc-hc64_nvo.exe'.lower()) or path.lower().endswith( u'mpc-hc_nvo.exe'.lower()): return path if os.path.isfile(path + u"mpc-hc.exe"): path += u"mpc-hc.exe" return path if os.path.isfile(path + u"\\mpc-hc.exe"): path += u"\\mpc-hc.exe" return path if os.path.isfile(path + u"mpc-hc_nvo.exe"): path += u"mpc-hc_nvo.exe" return path if os.path.isfile(path + u"\\mpc-hc_nvo.exe"): path += u"\\mpc-hc_nvo.exe" return path if os.path.isfile(path + u"mpc-hc64.exe"): path += u"mpc-hc64.exe" return path if os.path.isfile(path + u"\\mpc-hc64.exe"): path += u"\\mpc-hc64.exe" return path if os.path.isfile(path + u"mpc-hc64_nvo.exe"): path += u"mpc-hc64_nvo.exe" return path if os.path.isfile(path + u"\\mpc-hc64_nvo.exe"): path += u"\\mpc-hc64_nvo.exe" return path
def deleteFileDB(self, path, account=None): self.logger.debug('deleting file <' + path + '>') files_table = self.database['files'] if account: files_table.delete(internal_path=path.lower(), accountType=account.getAccountType(), user=account.user) else: files_table.delete(internal_path=path.lower())
def update_node_format(self, node_id): assert node_id != "" path = self.tree.set(node_id, "path") if os.path.isdir(path) or path.endswith(":") or path.endswith(":\\"): self.tree.set(node_id, "kind", "dir") if path.endswith(":") or path.endswith(":\\"): img = self.hard_drive_icon else: img = self.folder_icon else: self.tree.set(node_id, "kind", "file") if path.lower().endswith(".py"): img = self.python_file_icon elif path.lower().endswith(".txt") or path.lower().endswith( ".csv"): img = self.text_file_icon else: img = self.generic_file_icon # compute caption text = os.path.basename(path) if text == "": # in case of drive roots text = path self.tree.item(node_id, text=" " + text, image=img) self.tree.set(node_id, "path", path)
def write_image(image, path, overwrite=True): """Writes an image represented by a tensor to a PNG or JPG file.""" if not os.path.basename(path): raise ValueError(f'The given path doesn\'t represent a file: {path}') if tf.io.gfile.exists(path): if tf.io.gfile.isdir(path): raise ValueError( f'The given path is an existing directory: {path}') if not overwrite: print(f'Not overwriting an existing file at {path}') return False tf.io.gfile.remove(path) else: tf.io.gfile.makedirs(os.path.dirname(path)) image_u8 = tf.image.convert_image_dtype(image, tf.uint8, saturate=True) if path.lower().endswith('.png'): encoded = tf.io.encode_png(image_u8) elif path.lower().endswith('.jpg') or path.lower().endswith('.jpeg'): encoded = tf.io.encode_jpeg(image_u8, progressive=True) else: raise ValueError(f'Unsupported image format: {os.path.basename(path)}') with tf.io.gfile.GFile(path, 'wb') as f: f.write(encoded.numpy()) return True
def readLevels(root): global start_buffer global credits_buffer global levels global level_list start_buffer = None credits_buffer = None levels = {} level_list = [] for x in os.listdir(root): path = os.path.join(root, x) if os.path.isdir(path): level_list.append(path) print('Found Level: {}'.format(x)) if os.path.isfile(path): if 'start' in path.lower(): start_buffer = processTASFile(path) elif 'credit' in path.lower(): credits_buffer = processTASFile(path) level_list.sort() for level in level_list: level_data = processLevel(level) level_data2 = { 'start': level_data[0], 'end': level_data[1], 'polls': level_data[2] } levels[level] = level_data2 assert start_buffer != None, 'Failed to find game start input data!' assert credits_buffer != None, 'Failed to find credits input data!'
def get_metadata(path): """Retrieve metadata from a file or directory specified by path, or from the name of a distribution that happens to be installed. `path` can be an installed egg, a zipped egg file, or a zipped or unzipped tar file of a Python distutils or setuptools source distribution. Returns a dict. """ dist = None if os.path.isdir(path): dists = [x for x in find_distributions(path, only=True)] if len(dists) == 0: raise RuntimeError( '%s is not a zipped egg or an installed distribution' % path) dist = dists[0] if os.path.abspath(path).lower() != os.path.abspath( dist.location).lower(): raise RuntimeError( '%s is not a valid distribution (dist.location=%s)' % (os.path.abspath(path), dist.location)) metadata = get_dist_metadata(dist) elif os.path.isfile(path): if path.lower().endswith('.tar') or '.tar.gz' in path.lower(): # it's a tar file or gzipped tar file return _meta_from_tarfile(path) # getting access to metadata in a zipped egg doesn't seem to work # right, so just use a ZipFile to access files under the EGG-INFO # directory to retrieve the metadata. if path.lower().endswith('.egg'): # it's a zip file metadata = _meta_from_zipped_egg(path) elif path.lower().endswith('.zip'): metadata = _meta_from_zipfile(path) else: raise RuntimeError('cannot process file %s: unknown file type' % path) else: # look for an installed dist with the given name for d in working_set: if path == d.egg_name().split('-')[0]: dist = d metadata = get_dist_metadata(dist) break else: raise RuntimeError("Could not locate distribution '%s'" % path) if dist is not None: metadata['py_version'] = dist.py_version if 'platform' not in metadata or metadata['platform'] == 'UNKNOWN': metadata['platform'] = dist.platform metadata['entry_points'] = {} for gname, group in get_entry_map(dist, group=None).items(): metadata['entry_points'][gname] = [ep for ep in group] return metadata
def is_executable(p, *path): path = os.path.join(p, *path) if not os.path.exists(path) or os.path.isdir(path): return False if platform.IS_WINDOWS: return path.lower().endswith('.exe') or \ path.lower().endswith('.dll') else: return os.stat(path)[stat.ST_MODE] & stat.S_IXUSR
def open_file(self, dummy=None, path=None, add_to_recent=True): """ Open a .opensesame or .opensesame.tar.gz file Keyword arguments: dummy -- An unused argument which is passed by the signal (default=None) path -- The path to the file. If None, a file dialog is presented (default=None) """ if not self.save_unsaved_changes(): self.ui.tabwidget.open_general() return if path == None: path = unicode( QtGui.QFileDialog.getOpenFileName( self.ui.centralwidget, _(u"Open file"), filter=self.file_type_filter, directory=cfg.file_dialog_path)) if path == None or path == u'' or ( not path.lower().endswith(u'.opensesame') and not path.lower().endswith(u'.opensesame.tar.gz')): return self.set_status(u"Opening ...", status=u'busy') self.ui.tabwidget.close_all() cfg.file_dialog_path = os.path.dirname(path) try: exp = experiment.experiment(self, u"Experiment", path, experiment_path=os.path.dirname(path)) except Exception as e: if not isinstance(e, osexception): e = osexception(msg=u'Failed to open file', exception=e) self.print_debug_window(e) self.experiment.notify(e.html(), title=u'Exception') return libopensesame.experiment.clean_up(verbose=debug.enabled, keep=[exp.pool_folder]) self.experiment = exp self.experiment.build_item_tree() self.ui.tabwidget.open_general() if add_to_recent: self.current_path = path self.window_message(self.current_path) self.update_recent_files() cfg.default_logfile_folder = os.path.dirname(self.current_path) else: self.window_message(u"New experiment") self.current_path = None self.set_auto_response() self.set_unsaved(False) self.ui.pool_widget.refresh() self.ui.variable_inspector.refresh() self.extension_manager.fire(u'open_experiment', path=path) self.set_status(u"Opened %s" % path)
def get_metadata(path): """Retrieve metadata from a file or directory specified by path, or from the name of a distribution that happens to be installed. path can be an installed egg, a zipped egg file, or a zipped or unzipped tar file of a python distutils or setuptools source distribution. Returns a dict. """ dist = None if os.path.isdir(path): dists = [x for x in find_distributions(path, only=True)] if len(dists) == 0: raise RuntimeError('%s is not a zipped egg or an installed distribution'%path) dist = dists[0] if os.path.abspath(path).lower() != os.path.abspath(dist.location).lower(): raise RuntimeError('%s is not a valid distribution (dist.location=%s)'% (os.path.abspath(path),dist.location)) metadata = get_dist_metadata(dist) elif os.path.isfile(path): if path.lower().endswith('.tar') or '.tar.gz' in path.lower(): # it's a tar file or gzipped tar file return _meta_from_tarfile(path) # getting access to metadata in a zipped egg doesn't seem to work # right, so just use a ZipFile to access files under the EGG-INFO # directory to retrieve the metadata. if path.lower().endswith('.egg'): # it's a zip file metadata = _meta_from_zipped_egg(path) elif path.lower().endswith('.zip'): metadata = _meta_from_zipfile(path) else: raise RuntimeError('cannot process file %s: unknown file type' % path) else: # look for an installed dist with the given name for d in working_set: if path == d.egg_name().split('-')[0]: dist = d metadata = get_dist_metadata(dist) break else: raise RuntimeError("Could not locate distribution '%s'" % path) if dist is not None: metadata['py_version'] = dist.py_version if 'platform' not in metadata or metadata['platform']=='UNKNOWN': metadata['platform'] = dist.platform metadata['entry_points'] = {} for gname,group in get_entry_map(dist, group=None).items(): metadata['entry_points'][gname] = [ep for ep in group] return metadata
def getExpandedPath(path): if(os.path.isfile(path)): if(path.lower().endswith(u'mpc-hc.exe'.lower()) or path.lower().endswith(u'mpc-hc64.exe'.lower())): return path if(os.path.isfile(path + u"\\mpc-hc.exe")): path += u"\\mpc-hc.exe" return path if(os.path.isfile(path + u"\\mpc-hc64.exe")): path += u"\\mpc-hc64.exe" return path
def read_nt6_entries(bin_data, entry): try: entry_list = [] exec_flag = "" entry_size = entry.size() num_entries = struct.unpack('<L', bin_data[4:8])[0] if num_entries == 0: return None # Walk each entry in the data structure. for offset in range(CACHE_HEADER_SIZE_NT6_1, num_entries * entry_size + CACHE_HEADER_SIZE_NT6_1, entry_size): entry.update(bin_data[offset:offset + entry_size]) last_mod_date = convert_filetime(entry.dwLowDateTime, entry.dwHighDateTime) if not last_mod_date: continue try: last_mod_date = last_mod_date.strftime("%Y-%m-%d %H:%M:%S.%f") except ValueError as e: logging.info('[Error] AppCompatCache: {}'.format(e)) continue path = ( bin_data.decode("unicode-escape")[entry.Offset:entry.Offset + entry.wLength])[8:].replace( "\x00", "") from modules.constant import SYSTEMROOT, LOCALAPPDATA if path[-3:].lower() == "exe": head = grayHead elif SYSTEMROOT.lower() in path.lower( ) or LOCALAPPDATA in path.lower(): head = grayHead else: continue if (entry.FileFlags & CSRSS_FLAG): exec_flag = 'True' else: exec_flag = 'False' row = [ head, last_mod_date, path, 'N/A', exec_flag, "AppCompatCache" ] if row not in entry_list: entry_list.append(row) return entry_list except (RuntimeError, ValueError, NameError) as err: logging.info('[Error] reading Shim Cache data: {}...'.format(err)) return None
def update_node_data(self, node_id, name, data): assert node_id != "" path = self.tree.set(node_id, "path") if data.get("modified"): try: # modification time is Unix epoch time_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(data["modified"]))) except Exception: time_str = "" else: time_str = "" self.tree.set(node_id, "modified", time_str) if data["isdir"]: self.tree.set(node_id, "kind", "dir") self.tree.set(node_id, "size", "") # Ensure that expand button is visible # unless we know it doesn't have children children_ids = self.tree.get_children(node_id) if ( self.show_expand_buttons and len(children_ids) == 0 and (path not in self._cached_child_data or self._cached_child_data[path]) ): self.tree.insert(node_id, "end", text=_dummy_node_text) if path.endswith(":") or path.endswith(":\\"): img = self.hard_drive_icon else: img = self.folder_icon else: self.tree.set(node_id, "kind", "file") self.tree.set(node_id, "size", data["size"]) # Make sure it doesn't have children self.tree.set_children(node_id) if ( path.lower().endswith(".py") or path.lower().endswith(".pyw") or path.lower().endswith(".pyi") ): img = self.python_file_icon elif self.should_open_name_in_thonny(name): img = self.text_file_icon else: img = self.generic_file_icon self.tree.set(node_id, "name", name) self.tree.item(node_id, text=" " + data["label"], image=img)
def get_dut_MTP_sd_card_host_path(): host_mtp_path = EnvironmentUtils.get_dut_MTP_host_path() if host_mtp_path is None: return None dut_storage_mtp_host_paths = os.listdir(host_mtp_path) if ANDROID_VERSION in ["M", "L", "N"]: for path in dut_storage_mtp_host_paths: if "sd" in path.lower() and "card" in path.lower(): return os.path.join(host_mtp_path, os.path.normpath(path)) else: LOG.info("Android version is not recognized")
def load_content (path) : transcripts.printf_information ('Parsing file [%s]...', path) stream = file (path, 'rt') if path.lower () .endswith ('.pdf') : content = execute_load_content (['/usr/bin/pdftotext', path, '-']) elif path.lower () .endswith ('.ps') : content = execute_load_content (['/usr/bin/pstotext', path]) else : transcripts.printf_error ('File extension is unknown; ignoring.') content = None return content
def open_file(self, dummy=None, path=None, add_to_recent=True): """ Open a .opensesame or .opensesame.tar.gz file Keyword arguments: dummy -- An unused argument which is passed by the signal (default=None) path -- The path to the file. If None, a file dialog is presented (default=None) """ if not self.save_unsaved_changes(): self.ui.tabwidget.open_general() return if path == None: path = unicode(QtGui.QFileDialog.getOpenFileName( self.ui.centralwidget, _(u"Open file"), filter=self.file_type_filter, directory=cfg.file_dialog_path)) if path == None or path == u'' or (not path.lower().endswith( u'.opensesame') and not path.lower().endswith( u'.opensesame.tar.gz')): return self.set_status(u"Opening ...", status=u'busy') self.ui.tabwidget.close_all() cfg.file_dialog_path = os.path.dirname(path) try: exp = experiment.experiment(self, u"Experiment", path, experiment_path=os.path.dirname(path)) except Exception as e: if not isinstance(e, osexception): e = osexception(msg=u'Failed to open file', exception=e) self.print_debug_window(e) self.experiment.notify(e.html(), title=u'Exception') return libopensesame.experiment.clean_up(verbose=debug.enabled, keep=[exp.pool_folder]) self.experiment = exp self.experiment.build_item_tree() self.ui.tabwidget.open_general() if add_to_recent: self.current_path = path self.window_message(self.current_path) self.update_recent_files() cfg.default_logfile_folder = os.path.dirname(self.current_path) else: self.window_message(u"New experiment") self.current_path = None self.set_auto_response() self.set_unsaved(False) self.refresh_pool() self.refresh_variable_inspector() self.extension_manager.fire(u'open_experiment', path=path) self.set_status(u"Opened %s" % path)
def update_node_data(self, node_id, name, data): assert node_id != "" path = self.tree.set(node_id, "path") if data.get("time"): try: dtime = datetime.datetime.fromtimestamp(int(data["time"])) except Exception: time_str = "" else: time_str = dtime.isoformat().replace("T", " ") else: time_str = "" self.tree.set(node_id, "time", time_str) if data["isdir"]: self.tree.set(node_id, "kind", "dir") self.tree.set(node_id, "size", "") # Ensure that expand button is visible # unless we know it doesn't have children children_ids = self.tree.get_children(node_id) if ( self.show_expand_buttons and len(children_ids) == 0 and (path not in self._cached_child_data or self._cached_child_data[path]) ): self.tree.insert(node_id, "end", text=_dummy_node_text) if path.endswith(":") or path.endswith(":\\"): img = self.hard_drive_icon else: img = self.folder_icon else: self.tree.set(node_id, "kind", "file") self.tree.set(node_id, "size", data["size"]) # Make sure it doesn't have children self.tree.set_children(node_id) if path.lower().endswith(".py"): img = self.python_file_icon elif path.lower().endswith(".txt") or path.lower().endswith(".csv"): img = self.text_file_icon else: img = self.generic_file_icon self.tree.set(node_id, "name", name) self.tree.item(node_id, text=" " + data["label"], image=img)
async def move( db_client: DBClient, namespace: Namespace, path: StrOrPath, next_path: StrOrPath, ) -> File: """ Move a file or folder to a different location in the target Namespace. If the source path is a folder all its contents will be moved. Args: db_client (DBClient): Database client. namespace (Namespace): Namespace, where file/folder should be moved. path (StrOrPath): Path to be moved. next_path (StrOrPath): Path that is the destination. Raises: errors.FileNotFound: If source path does not exists. errors.FileAlreadyExists: If some file already in the destination path. errors.MissingParent: If 'next_path' parent does not exists. errors.NotADirectory: If one of the 'next_path' parents is not a folder. Returns: File: Moved file/folder. """ path = str(path) next_path = str(next_path) assert path.lower() not in (".", config.TRASH_FOLDER_NAME.lower()), ( "Can't move Home or Trash folder.") assert not next_path.lower().startswith(f"{path.lower()}/"), ( "Can't move to itself.") if not await crud.file.exists(db_client, namespace.path, path): raise errors.FileNotFound() from None next_parent = os.path.normpath(os.path.dirname(next_path)) if not await crud.file.exists(db_client, namespace.path, next_parent): raise errors.MissingParent() from None if path.lower() != next_path.lower(): if await crud.file.exists(db_client, namespace.path, next_path): raise errors.FileAlreadyExists() from None await storage.move(namespace.path, path, next_path) async for tx in db_client.transaction(): # pragma: no branch async with tx: file = await crud.file.move(tx, namespace.path, path, next_path) return file
def ask_for_path(): checkagain = True while checkagain: path = input("TYPE FILE TO CONVERT TO MD: ") if (path.lower() == "exit"): print('\nThanks for using EasyMD! Bye!') exit() elif ((os.path.exists(path)) == False): print("\nFILE DOESN'T EXIST, TRY AGAIN! | TO EXIT, TYPE EXIT\n") elif (path.lower().endswith('.txt') == False): print("\nFILE IS NOT .TXT, TRY AGAIN! | TO EXIT, TYPE EXIT\n") else: checkagain = False return path
def multisend(): print 'Note: you must exit the GTS before sending each Pokemon' print '4th Gen Pokemon files are currently unsupported.\n' print 'Enter the path or drag the pkm file here, then\npress Enter, and enter another path. Finish by typing\nDone then press Enter.' print '(Type Back to go back)' multi = list() while True: path = raw_input().strip() if path == "Back" or path == "back": return path = os.path.normpath(path) if system() != 'Windows': path = path.replace('\\', '') if path == 'done' or path == 'Done': multisender(multi) break if path.startswith('"') or path.startswith("'"): path = path[1:] if path.endswith('"') or path.endswith("'"): path = path[:-1] if os.path.exists(path) and path.lower().endswith('.pkm'): multi.append(path) else: print 'Invalid file name, try again' continue
def from_url(url): """Assumes a valid URL if the scheme is specified. For example, 'file:///C:/My%20Documents/test.vt'. If only a filename is specified, it converts the filename to a URL. """ if '://' in url: scheme = url.split('://', 1)[0] elif url.startswith('untitled:'): scheme = 'untitled' else: scheme = 'file' url = BaseLocator.convert_filename_to_url(url) if scheme == 'untitled': return UntitledLocator.from_url(url) elif scheme == 'db': return DBLocator.from_url(url) elif scheme == 'file': old_uses_query = urlparse.uses_query urlparse.uses_query = urlparse.uses_query + ['file'] scheme, host, path, query, fragment = urlparse.urlsplit(str(url)) urlparse.uses_query = old_uses_query path = url2pathname(path) if path.lower().endswith(".xml"): return XMLFileLocator.from_url(url) else: return ZIPFileLocator.from_url(url) return None
def resolve(self, path): for suffix in self._suffixes: if suffix in path.lower(): if not self.exists(path): raise FileNotFoundError(self.scheme + path) return super().resolve(path) return self._fs.resolve(as_url(path))
def __HasValidExtensionToUpload(path, extensions): tempPath = path.lower() for extension in extensions: if fnmatch.fnmatch(tempPath, "*." + extension): return True return False
def IsFileOnIgnoreList(path): path = os.path.basename(path) # We only filter the filenames. path = path.lower() for ignoreFile in Settings.IgnoreFile: if re.match(ignoreFile, path) is not None: return True return False
def load_classes(self, path): # Load from coco.names classes specified in __init__ if path.lower().endswith('.names') and path in self.model.values(): with open(path, 'rt') as f: return f.read().rstrip('\n').split('\n') print("No classes loaded") return None
def install_bundle(self, path): if not self.install_predicate(self, path): return [] path = path.rstrip("/") if not path.lower().endswith(".sketchplugin"): self._check_signature(path, TYPE_BUNDLE) bundle_name = os.path.basename(path) ext = os.path.splitext(bundle_name)[1].lower() dst_dir = self._dst_dir_for_bundle(ext) dst_bundle = os.path.join(dst_dir, bundle_name) if os.path.exists(dst_bundle): raise Exception("%r already exists, will not overwrite" % (dst_bundle, )) real_temp_dir = os.path.realpath(self._temp_dir) real_bundle_path = os.path.realpath(path) can_move = real_bundle_path.startswith(real_temp_dir + os.sep) if can_move: logger.info("Moving %r to %r", path, dst_bundle) shutil.move(path, dst_bundle) else: logger.info("Copying %r to %r", path, dst_dir) copy_with_tar(path, dst_dir) if self._should_set_owner: change_owner(dst_bundle, self.owner_uid, self.owner_gid) chmod_recursive(dst_bundle) return [bundle_name]
def checkImageType(path): if path: types = ['gif', 'bmp', 'jpg', 'jpeg', 'png'] for imgType in types: if path.lower().endswith('.' + imgType): return imgType return None
def get_songs(): log("Checking for updates") songs = mm.get_all_songs() downloaded_songs = False for song in songs: path = song['artist'][0] + '/' + song['artist'] + '/' + song['album'] path = path.lower().replace(' ', '_') path = download_dir + path track_number = str(song['track_number']) if len(track_number) < 2: track_number = '0' + track_number filename = track_number + ' ' + song['title'] + '.mp3' filename = filename.lower().replace(' ', '_') full_path = path + '/' + filename if not os.path.isfile(full_path): if not os.path.isdir(path): log("Creating directory " + path) os.makedirs(path) log("Downloading " + full_path) suggested_filename, audio = mm.download_song(song['id']) with open(full_path, 'wb') as f: f.write(audio) downloaded_songs = True if downloaded_songs and notify_plex: log("Notifying local Plex Media Server to refresh") r = requests.get('http://localhost:32400/library/sections/3/refresh?force=1') r.raise_for_status()
def tearDown(self): """ Called after each test in this class. """ self.model.pre_delete() # Paranoia. Only needed by NPSS I think. self.model = None os.chdir(self.startdir) SimulationRoot.chroot(self.startdir) if not os.environ.get('OPENMDAO_KEEPDIRS', False): try: shutil.rmtree(self.tempdir) except OSError: pass # Not always added, but we need to ensure the egg is not in sys.path. egg_name = self.egg_name paths = sys.path if egg_name is not None: if sys.platform == "win32": egg_name = egg_name.lower() paths = [path.lower() for path in sys.path] for i, path in enumerate(paths): if path.endswith(egg_name) or egg_name in path: del sys.path[i] break
def __init__(self, json=None, path=None, verify=True): ''' Creates a new attachment class, optionally from existing JSON. Keyword Arguments: json -- json to create the class from. this is mostly used by the class internally when an attachment is downloaded from the cloud. If you want to create a new attachment, leave this empty. (default = None) path -- a string giving the path to a file. it is cross platform as long as you break windows convention and use '/' instead of '\'. Passing this argument will tend to the rest of the process of making an attachment. Note that passing in json as well will cause this argument to be ignored. ''' if json: self.json = json self.isPDF = '.pdf' in self.json['Name'].lower() elif path: with open(path, 'rb') as val: self.json = { '@odata.type': '#Microsoft.OutlookServices.FileAttachment' } self.isPDF = '.pdf' in path.lower() self.setByteString(val.read()) try: self.setName(path[path.rindex('/') + 1:]) except: self.setName(path) else: self.json = { '@odata.type': '#Microsoft.OutlookServices.FileAttachment' } self.verify = verify
def is_image(path): """OpenCV supported image formats""" extensions = [ 'bmp', 'dib', 'jpeg', 'jpg', 'jpe', 'jp2', 'png', 'webp' 'pbm', 'pgm', 'ppm', 'pxm', 'pnm', 'pfm', 'sr', 'ras', 'tiff', 'tif', 'exr', 'hdr', 'pic', ] return any(path.lower().endswith('.' + i) for i in extensions)
def install(directory, name): print "Installing %s"%name from distutils import sysconfig inst = sysconfig.get_python_lib() if raw_input("The default directory for installation is '%s' Accept this location? [y/N]: "%(inst+os.sep)) == 'y': inst = choosePath(inst, directory) else: inst = choosePath(raw_input('Enter install directory: '), directory) paths = [] if os.name == "nt": for path in sys.path: paths.append(path.lower()) if inst.lower() not in paths and inst.lower()+os.sep not in sys.path: print "The installation directory '%s' is not on your sys.path. This means that if the modules were to be installed there you would not be able to import them unless you modified your path with code as follows:"%inst print "import sys; sys.path.append('%s')\n"%inst else: if inst not in sys.path and inst+os.sep not in sys.path: print "The installation directory '%s' is not on your sys.path. This means that if the modules were to be installed there you would not be able to import them unless you modified your path with code as follows:"%inst print "import sys; sys.path.append('%s')\n"%inst if raw_input('Continue with installation? [y/N]: ') == 'y': print "Installing the modules to '%s'..."%(inst+os.sep+directory) shutil.copytree(directory, inst+os.sep+directory) print "%s successfully installed."%name else: print "Install aborted." raw_input('Press ENTER to exit.')
def getFileList(path, language, silent=False): if not silent: print(" checking %s" % path) files = [] dirs = [] dirListing = os.listdir(path + "/") dirListing.sort(key=lambda filename: [ int(match) if match.isdigit() else match for match in re.split('(\d+)', filename) ]) for f in dirListing: if f == ".svn" or f == "." or f == "..": continue name = path + "/" + f try: os.listdir(name) dirs.append(name) except: if name.lower().endswith(LocParser.EXTENSION.lower()) and ( language == "" or path.lower().endswith("/" + language.lower())): files.append(name) if not silent: print(" -> %s" % LocParser._getBasename(name, path)) if len(files) > 0: return files result = [] for dir in dirs: result.extend(LocParser.getFileList(dir, language, silent)) return result
def sendpkm(): print 'Note: you must exit the GTS before sending a pkm' print '4th Gen Pokemon files are currently unsupported.' print 'Enter the path or drag the pkm file here' print '(Type Back to go back)' while True: path = raw_input().strip() if path == "Back" or path == "back": return path = os.path.normpath(path) if system() != 'Windows': path = path.replace('\\', '') if path.startswith('"') or path.startswith("'"): path = path[1:] if path.endswith('"') or path.endswith("'"): path = path[:-1] if os.path.exists(path) and path.lower().endswith('.pkm'): break else: print 'Invalid file name, try again' continue sendingpkm(path)
def createRequest(self, op, request, device = None ): global block_list,TMP_DIR try: urlLnk = (request.url()).toString() path = (request.url().toString()) except UnicodeEncodeError: path = (request.url().path()) lower_path = path.lower() block_list = ["doubleclick.net" ,"ads",'.jpg','.png','.gif','.css','facebook','.aspx', r"||youtube-nocookie.com/gen_204?", r"youtube.com###watch-branded-actions", "imagemapurl","b.scorecardresearch.com","rightstuff.com","scarywater.net","popup.js","banner.htm","_tribalfusion","||n4403ad.doubleclick.net^$third-party",".googlesyndication.com","graphics.js","fonts.googleapis.com/css","s0.2mdn.net","server.cpmstar.com","||banzai/banner.$subdocument","@@||anime-source.com^$document","/pagead2.","frugal.gif","jriver_banner.png","show_ads.js",'##a[href^="http://billing.frugalusenet.com/"]',"http://jriver.com/video.html","||animenewsnetwork.com^*.aframe?","||contextweb.com^$third-party",".gutter",".iab",'http://www.animenewsnetwork.com/assets/[^"]*.jpg'] block = False for l in block_list: if l in lower_path: block = True break if block: #print ("Skipping") #print (request.url().path()) return QNetworkAccessManager.createRequest(self, QNetworkAccessManager.GetOperation, QtNetwork.QNetworkRequest(QtCore.QUrl())) else: if 'itag=' in urlLnk and 'redirector' not in urlLnk: print('*********') f = open(os.path.join(TMP_DIR,'lnk.txt'),'w') f.write(urlLnk) f.close() return QNetworkAccessManager.createRequest(self, op, request, device) else: return QNetworkAccessManager.createRequest(self, op, request, device)
def info_hash(path): if not path.lower().endswith('.torrent'): print '[WARN] Is it really a .torrent file? '+path if os.path.getsize(path) > 1000*1000: raise NotImplementedError('Torrent file too big') with open(path, 'rb') as stream: return info_hash_from_content(stream.read())
def get_file(self, dummy, path): path = path.lower() if path in self.content_dict: return FakeConnection(self.content_dict[path]) else: logging.debug('Request for non-existing file!') return FakeConnection('', 404)
def execute(self, context): path = context.get_path() size = context.get_size() # if the file has a candidate extension if any([path.lower().endswith(x) for x in self._extensions]): self.log.debug("Trying to get ID3 data for %s" % path) # Fetch the data from the server if self._fetch_data(path, size): id3_map = {"album": None, "artist": None, "title": None, "track": None, "year": None, "genre": None} # Look for tags try: tags = tinytag.ID3(self._buffer, None) tags.load(tags=True, duration=False, image=False) for tag in ["album", "artist", "title", "track", "year", "genre"]: value = getattr(tags, tag) if value is not None: id3_map[tag] = value # add the tag in the context object context.set_extra_data("audio_%s" % tag, value) except (UnicodeDecodeError, struct.error) as e: self.log.error("%s : %r" % (path, e)) # Whatever the outcome of this stage, # continue the execution of the pipeline return True
def pathkey(path): if os.path.isdir(os.path.join(self.root_path, path)): prefix = '0_' else: prefix = '1_' path = prefix + path return path.lower()
def createRequest(self, op, request, device = None ): global block_list,TMP_DIR try: urlLnk = (request.url()).toString() path = (request.url().toString()) except UnicodeEncodeError: path = (request.url().path()) if '9anime.to' in path and 'episode/info?' in path: f = open(os.path.join(TMP_DIR,'lnk.txt'),'w') f.write(path) f.close() lower_path = path.lower() #block_list = [] block_list = ["doubleclick.net" ,"ads",'.gif','.css','facebook','.aspx', r"||youtube-nocookie.com/gen_204?", r"youtube.com###watch-branded-actions", "imagemapurl","b.scorecardresearch.com","rightstuff.com","scarywater.net","popup.js","banner.htm","_tribalfusion","||n4403ad.doubleclick.net^$third-party",".googlesyndication.com","graphics.js","fonts.googleapis.com/css","s0.2mdn.net","server.cpmstar.com","||banzai/banner.$subdocument","@@||anime-source.com^$document","/pagead2.","frugal.gif","jriver_banner.png","show_ads.js",'##a[href^="http://billing.frugalusenet.com/"]',"http://jriver.com/video.html","||animenewsnetwork.com^*.aframe?","||contextweb.com^$third-party",".gutter",".iab",'http://www.animenewsnetwork.com/assets/[^"]*.jpg','revcontent'] block = False for l in block_list: if l in lower_path: block = True break if block: return QNetworkAccessManager.createRequest(self, QNetworkAccessManager.GetOperation, QtNetwork.QNetworkRequest(QtCore.QUrl())) else: if 'itag=' in urlLnk and 'redirector' not in urlLnk: print('*********') #f = open(os.path.join(TMP_DIR,'lnk.txt'),'w') #f.write(urlLnk) #f.close() return QNetworkAccessManager.createRequest(self, op, request, device) else: return QNetworkAccessManager.createRequest(self, op, request, device)