def fnmatch_filter(names, pat, casesensitive): """Return the subset of the list NAMES that match PAT""" result = [] if casesensitive: if not pat in _casecache: res = translate(pat) if len(_casecache) >= 100: _casecache.clear() _casecache[pat] = re.compile(res) match = _casecache[pat].match for name in names: if match(name): result.append(name) else: if not pat in _nocasecache: res = translate(pat) if len(_nocasecache) >= 100: _nocasecache.clear() _nocasecache[pat] = re.compile(res, re.IGNORECASE) match = _nocasecache[pat].match pat = ntpath.normcase(pat) for name in names: if match(ntpath.normcase(name)): result.append(name) return result
def find_existing_win32_subst_for_path( path: str, subst_mapping: Mapping[str, str], ) -> Optional[str]: path = ntpath.normcase(ntpath.normpath(path)) for letter, target in subst_mapping.items(): if ntpath.normcase(target) == path: return letter return None
def find_existing_win32_subst_for_path( path, # type: str subst_mapping, # type: typing.Mapping[str, str] ): # type: (...) -> typing.Optional[str] path = ntpath.normcase(ntpath.normpath(path)) for letter, target in subst_mapping.items(): if ntpath.normcase(target) == path: return letter return None
def makeFolder(): ## Normalize input global inputDataPath, workingFolder, fileName, fileName, ext, startTime global saveFolder, logsFileName, outputFileName, serializeFileName global outputDataPath, logsDataPath, serializeDataPath inputDataPath = ntpath.normcase(inputDataPath) ## Folder/File/Ext Names workingFolder, fileName = ntpath.split(inputDataPath) fileName, ext = ntpath.splitext(fileName) # startTime = time.strftime("%x_%X") <= probleme sur win avec : dans le nom de fichier startTime = time.strftime("%Y-%m-%d_%Hh%Mm%Ss") saveFolder = ntpath.join(workingFolder, fileName) + "Results" logsFileName = startTime + "_Logs" outputFileName = startTime + "_Load" serializeFileName = startTime + "_Serialize" outputDataPath = ntpath.join(saveFolder, logsFileName) logsDataPath = ntpath.join(saveFolder, outputFileName) serializeDataPath = ntpath.join(saveFolder, serializeFileName) ## Make dir if not ntpath.isdir(saveFolder): os.makedirs(saveFolder) a = open(outputDataPath, 'w+') a = open(logsDataPath, 'w+')
def FindMediaTableIDFromUNCSpec(db_con, unc_spec_filename): """ Searches media_table for a file with the specified unc_spec_filename and returns the media_id of it (or None if not found) :param db_con Open database connection to Adobe Elements 6.0 SQLite Catalog database file :param unc_spec_filename: Full UNC filespec of file to locate [NB: use raw string literals to avoid slash problems] :return: media_id of located file or None if not found. """ # lc_base_filename = ntpath.normcase(unc_spec_filename) drive, remainder = ntpath.splitdrive(lc_base_filename) lc_base_filename = (ntpath.basename(remainder)).lower() dir = str.replace(ntpath.dirname(remainder), '\\', '/') if dir[-1] != '/': # Add trailing forward slash dir += '/' with db_con: cur = db_con.cursor() # Find tag 'user_ns' first which is at the top of the treee query = """ SELECT id FROM media_table WHERE filepath_search_index = "{}" AND filename_search_index = "{}"; """.format(dir, lc_base_filename) cur.execute(query) row = cur.fetchone() if row: media_id = row[0] else: media_id = None return media_id
def fnmatch_filter(names, pat, casesensitive): # Return the subset of the list NAMES that match PAT """ Parameters ---------- names : array_like A list of names pat : str A pattern casesensitive : bool True if case sensitive, False if not. Returns ------- array_like The subset of the list NAMES that match PAT """ result=[] if casesensitive: if not pat in _casecache: res = translate(pat) if len(_casecache) >= 100: _casecache.clear() _casecache[pat] = re.compile(res) match=_casecache[pat].match for name in names: if match(name): result.append(name) else: if not pat in _nocasecache: res = translate(pat) if len(_nocasecache) >= 100: _nocasecache.clear() _nocasecache[pat] = re.compile(res, re.IGNORECASE) match=_nocasecache[pat].match pat=ntpath.normcase(pat) for name in names: if match(ntpath.normcase(name)): result.append(name) return result
def AsBatch(self, expandvars=False, nodep=False): ''' :param bool expandvars: If True expand environment variables references in the returning value. If False platformize environment variables references. ''' if expandvars: result = os.path.expandvars(self.__path) elif nodep: result = ntpath.normpath(self.__path) else: result = ntpath.normpath(self.__path) result = ntpath.normcase(result) result = self._PlatformizeEnvVarsReferences(result) return result
def map2platform(self, path, target_platform=None): """Map paths of from the source i.e. current platform to the target platform. Supported plaforms are linux, win32 and darwin. The method does not perform any sanity checks wether the path exists on the current or target platform. It simply replaces the substrings of the current path, defined in mapping table. The new path is normalized using the xx.normcase method (x is replaced either by ntpath or posixpath). """ if target_platform is None: target_platform = self.target_platform if target_platform not in ("linux", "linux2", "darwin", "win32"): raise RuntimeError("Target platform not supported!") platform = sys.platform if platform == target_platform: return path mapping = AppPreferences().mapping path_mapped = None for k, v in mapping[platform].iteritems(): if platform == target_platform: path_mapped = path break elif path.find(k) == 0: path_mapped = path.replace(k, v[target_platform]) break if path_mapped is None: pass elif target_platform.startswith("win"): path_mapped = ntpath.normcase(path_mapped) # OSX 10.X and linux else: path_mapped = posixpath.normcase(path_mapped) path_mapped = path_mapped.replace(ntpath.sep, posixpath.sep) return path_mapped
def win_path_to_wsl(path: str) -> str: path = ntpath.normcase(path) if path.startswith(r"\\") or path.startswith(r'\?'): raise NotImplementedError( f"Network or Object Manager paths on WSL are not supported: '{path}'" ) if not path.startswith('\\') and path[1:2] != ":\\": raise NotImplementedError( f"Relative Windows paths on WSL are not supported: '{path}'") if path.startswith('\\'): letter = win_env('SystemDrive')[0] else: letter, path = path.split(":", 1) letter = letter.lower() path = path.replace('\\', '/') unixpath = f'/mnt/{letter}/{path}' return posixpath.normpath(unixpath)
def data2update(self, dataset, no_data=-999.9, varcol=-1, header=True, save=True, par_path=None): """Try to update the parameters according to a data set in the PointSet format. """ if isinstance(dataset, gr.PointSet): pset = dataset else: pset = gr.PointSet() pset.load(dataset, no_data, header) keywords = ['datapath', 'columns', 'trimming', 'tails', 'lowert', 'uppert', 'nd'] hdpath = ntpath.normcase(pset.path) ncols = pset.values.shape[1] psetvalues = pset.values.iloc[:, varcol].replace(no_data, np.nan) datamin = psetvalues.min() datamax = psetvalues.max() values = [hdpath, ncols, [datamin, datamax], [datamin, datamax], [1, datamin], [1, datamax], pset.nodata] self.update(keywords, values, save, par_path)
def makeFolder(self): ## Normalize input self.inputDataPath = ntpath.normcase(self.inputDataPath) ## Folder/File/Ext Names self.workingFolder, self.fileName = ntpath.split(self.inputDataPath) self.fileName, self.ext = ntpath.splitext(self.fileName) # self.startTime = time.strftime("%x_%X") <= probleme sur win avec : dans le nom de fichier self.startTime = time.strftime("%Y-%m-%d_%Hh%Mm%Ss") self.saveFolder = ntpath.join(self.workingFolder, self.fileName) + "Results" self.logsFile = self.startTime + "_Logs" self.outputFile = self.startTime + "_Load" self.outputDataPath = ntpath.join(self.saveFolder, self.logsFile) self.logDataPath = ntpath.join(self.saveFolder, self.outputFile) ## Make dir if not ntpath.isdir(self.saveFolder): os.makedirs(self.saveFolder) test = open(self.outputDataPath, 'w+') self.debugAll() self.train(self.inputDataPath)
def module_path(self, mod): # Normalised directory path holding module # FIXME: should we be performing any shell expansion here (e.g. SystemRoot == c:\\WINDOWS)? return ntpath.normpath( ntpath.normcase(ntpath.dirname(str(mod.FullDllName))))
def module_name(self, mod): # Normalised module name (without base directory) return ntpath.normpath( ntpath.normcase(ntpath.basename(str(mod.BaseDllName))))
def _cmpkey(self): ''' Implements Comparable._cmpkey ''' return StandardizePath(ntpath.normcase(self.__path))
def test_path_normcase(self): self._check_function(self.path.normcase) if sys.platform == 'win32': self.assertEqual(ntpath.normcase('\u03a9\u2126'), 'ωΩ')
import lief #flags and constants DEBUG = False #DEBUG = True VERBOSE = True import_blacklist = [ # "ntdll.dll", # "wow64cpu.dll", # "wow64.dll", # "wow64win.dll", # "kernelbase.dll", ] _nc = lambda path: ntpath.normcase(path) buf_to_uint32 = lambda buf: struct.unpack("I", bytes(buf))[0] uint32_to_buf = lambda n: struct.pack("I", n) def debug_print(msg): if DEBUG: print(msg) def verbose_print(msg): if VERBOSE: print(msg) def parse_volatility_json(fn):
def update_event(self, inp=-1): self.set_output_val(0, ntpath.normcase(self.input(0)))
import lief from lief import Logger # flags and constants DEBUG = False # DEBUG = True VERBOSE = True import_blacklist = [ # "ntdll.dll", # "wow64cpu.dll", # "wow64.dll", # "wow64win.dll", # "kernelbase.dll", ] _nc = lambda path: ntpath.normcase(path) # noqa: E731 buf_to_uint32 = lambda buf: struct.unpack("I", bytes(buf))[0] # noqa: E731 uint32_to_buf = lambda n: struct.pack("I", n) # noqa: E731 def debug_print(msg): if DEBUG: print(msg) def verbose_print(msg): if VERBOSE: print(msg) def parse_volatility_json(fn):
def _norm(path): if isinstance(path, (bytes, str, os.PathLike)): return ntpath.normcase(os.fsdecode(path)) elif hasattr(path, "__iter__"): return tuple(ntpath.normcase(os.fsdecode(p)) for p in path) return path
def module_name(self, mod): # Normalised module name (without base directory) return ntpath.normpath(ntpath.normcase(ntpath.basename(str(mod.BaseDllName))))
def update_dsspar(self, save=False, dsspar_path=None): """Update the DSS parameters file according to the set of parameters given in the GSIMCLI parameters file. """ if hasattr(self, 'dss_par'): dsspar = pdss.DssParam.load_old(self.dss_par) # TODO: old arg else: dsspar = pdss.DssParam() dsspar.path = os.path.join(os.path.dirname(self.path), 'DSSim.par') pset = gr.PointSet(psetpath=self.data, header=self.data_header) if hasattr(self, 'name'): name = self.name else: self.name = pset.name name = pset.name if hasattr(self, 'variables'): varnames = self.variables # map(str.strip, self.variables.split(',')) else: self.variables = pset.varnames varnames = pset.varnames columns_set = [varnames.index('x') + 1, varnames.index('y') + 1, varnames.index('time') + 1, varnames.index('clim') + 1, 0, 0] gsc_grid = ['XX_nodes_number', 'XX_minimum', 'XX_spacing', 'YY_nodes_number', 'YY_minimum', 'YY_spacing', 'ZZ_nodes_number', 'ZZ_minimum', 'ZZ_spacing'] dss_grid = [dsspar.xx[0], dsspar.xx[1], dsspar.xx[2], dsspar.yy[0], dsspar.yy[1], dsspar.yy[2], dsspar.zz[0], dsspar.zz[1], dsspar.zz[2]] grid_specs = list() for i in xrange(len(dss_grid)): if hasattr(self, gsc_grid[i]): grid_specs.append(getattr(self, gsc_grid[i])) else: grid_specs.append(dss_grid[i]) if hasattr(self, 'search_radius'): radius = self.search_radius else: radius = [grid_specs[0] * grid_specs[2], grid_specs[3] * grid_specs[5], grid_specs[6] * grid_specs[8]] keywords = ['datapath', 'columns_set', 'nd', 'output', 'srchradius', 'xx', 'yy', 'zz'] values = [ntpath.normcase(self.data), columns_set, self.no_data, (name + '.prn').replace(' ', '_'), radius, [grid_specs[0], grid_specs[1], grid_specs[2]], [grid_specs[3], grid_specs[4], grid_specs[5]], [grid_specs[6], grid_specs[7], grid_specs[8]]] if hasattr(self, 'krig_type'): if self.krig_type.lower() == 'ok': krig = 0 elif self.krig_type.lower() == 'sk': krig = 1 # TODO: other kriging types missing keywords.append('krig') values.append([krig, 0]) if hasattr(self, 'max_search_nodes'): keywords.append('nsamples') values.append([1, self.max_search_nodes]) if hasattr(self, 'nugget'): keywords.append('nstruct') values.append([dsspar.nstruct[0], self.nugget]) if hasattr(self, 'ranges'): keywords.append('ranges') values.append([self.ranges]) if hasattr(self, 'model'): if self.model.lower() == 's': model = 1 elif self.model.lower() == 'e': model = 2 elif self.model.lower() == 'g': model = 3 else: model = dsspar.struct[0] if hasattr(self, 'sill'): sill = self.sill else: sill = dsspar.struct[1] if hasattr(self, 'angles'): angles = self.angles else: angles = dsspar.struct[2:] keywords.append('struct') values.append([[model, sill] + angles]) other_keys = ['nsim', 'srchangles', 'maxsim'] other_values = ['number_simulations', 'angles', 'max_search_nodes'] for i in xrange(len(other_keys)): if hasattr(self, other_values[i]): keywords.append(other_keys[i]) values.append(getattr(self, other_values[i])) dsspar.update(keywords, values) dsspar.data2update(self.data, self.no_data, varnames.index('clim'), self.data_header, save, dsspar_path) return dsspar
def module_path(self, mod): # Normalised directory path holding module # FIXME: should we be performing any shell expansion here (e.g. SystemRoot == c:\\WINDOWS)? return ntpath.normpath(ntpath.normcase(ntpath.dirname(str(mod.FullDllName))))