def loadModel(rrName, sedmlDoc, currentModel, path): global modelname global outdir string = currentModel.getSource() if isId(string): # it's the Id of a model originalModel = sedmlDoc.getModel(string) string = originalModel.getSource() # !!! for now, we reuse the original model to which the current model is referring to if string.startswith("../"): # relative location, we trust it but need it trimmed string = string[3:] print rrName + ".load('" + path.replace("\\","/") + string + "')" # SBML model name recovered from "source" attr #from os.path import expanduser #path = expanduser("~") #print(rrName + ".load('" + path + "\\" + string + "')") # SBML model name recovered from "source" attr elif "\\" or "/" not in string: print rrName + ".load('" + path.replace("\\","/") + string + "')" elif string.startswith("urn:miriam"): astr = string.rsplit(':', 1) astr = astr[1] import httplib conn = httplib.HTTPConnection("www.ebi.ac.uk") conn.request("GET", "/biomodels-main/download?mid=" + astr) r1 = conn.getresponse() #print(r1.status, r1.reason) data1 = r1.read() conn.close() string = "SBMLModels/" + modelname + ".xml" f1 = open(outdir + "/" + string, 'w') f1.write(data1); f1.close() print rrName + ".load(roadrunner.testing.get_data('" + string +"'))" else: # assume absolute path pointing to hard disk location string = string.replace("\\", "/") print rrName + ".load('" + string + "')"
def normalise_relative_path(path): """Normalise a path as follows: 1. it has a single leading forward slash, 2. all separators are forward slashes, 3. there are no duplicate separators in the path, 4. there are no trailing separators, 5. an empty path yields /. """ # Requirement 5 if path == '' or path == '.': return SVN_SEP # Requirement 3 while '\\\\' in path: path = path.replace('\\\\', SVN_SEP) # Convert relative path from Windows to POSIX # Requirement 2 path = path.replace('\\', SVN_SEP) # Requirement 3 (again) # If we have e.g. \\\\src, it will now be //src, but we can't # call normpath again, since that will convert the / back to \, # so we need to strip duplicate /'s. while '//' in path: path = path.replace('//', SVN_SEP) # Requirement 4 if path.endswith(SVN_SEP): path = path[:-1] # Requirement 1 if not path.startswith(SVN_SEP): path = '/{0}'.format(path) return path
def load_install_paths(module_info_path): with open(module_info_path, 'r') as fp: data = json.load(fp) result = set() name_path_dict = {} patt = re.compile( '.*[\\\\/]target[\\\\/]product[\\\\/][^\\\\/]+([\\\\/].*)$') for name, module in data.items(): for path in module['installed']: match = patt.match(path) if not match: continue path = match.group(1) path = path.replace(os.path.sep, '/') path = path.replace('/lib/', '/${LIB}/') path = path.replace('/lib64/', '/${LIB}/') path = re.sub('/vndk-sp(?:-[^/$]*)/', '/vndk-sp${VNDK_VER}/', path) path = re.sub('/vndk(?:-[^/$]*)/', '/vndk${VNDK_VER}/', path) result.add(path) if name.endswith('_32'): name = name[0:-3] name_path_dict[name] = path return (result, name_path_dict)
def _path(self, path): if path.startswith('sandbox://'): path = path.replace('sandbox://', 'temp://xbmcup/' + self._sandbox + '/') special = [x for x in self._special if path.startswith(x)] if special: return os.path.normpath(xbmc.translatePath(path.replace(special[0], 'special://' + special[0].replace(':/', '')))) return os.path.normpath(path)
def ExpandSpecial(self, path, product_dir=None): """Expand specials like $!PRODUCT_DIR in |path|. If |product_dir| is None, assumes the cwd is already the product dir. Otherwise, |product_dir| is the relative path to the product dir. """ PRODUCT_DIR = '$!PRODUCT_DIR' if PRODUCT_DIR in path: if product_dir: path = path.replace(PRODUCT_DIR, product_dir) else: path = path.replace(PRODUCT_DIR + '/', '') path = path.replace(PRODUCT_DIR, '.') INTERMEDIATE_DIR = '$!INTERMEDIATE_DIR' if INTERMEDIATE_DIR in path: int_dir = self.GypPathToUniqueOutput('gen') # GypPathToUniqueOutput generates a path relative to the product dir, # so insert product_dir in front if it is provided. path = path.replace(INTERMEDIATE_DIR, os.path.join(product_dir or '', int_dir)) return path
def repo(self, *args): """ Return a file from the repository. We retrive file like that instead of serving them statically so we can use authorization (a project file can only be requested by a valid project user). The path for the projects repository can be configured in the .ini file with the "repository" variable. """ path = request.path path = path.replace(url('/'), '') path = path.replace('repo/', '') path = os.path.join(G.REPOSITORY, path) if not os.path.exists(path): raise HTTPNotFound().exception # set the correct content-type so the browser will know what to do content_type, encoding = mimetypes.guess_type(path) response.headers['Content-Type'] = content_type response.headers['Content-Disposition'] = ( ('attachment; filename=%s' % os.path.basename(path)).encode()) # copy file content in the response body f = open(path) shutil.copyfileobj(f, response.body_file) f.close() return
def __path(self, path): if self.__ns: nspath = '{%s}%s' % ( self.__ns, path.replace('.', '/{%s}' % (self.__ns,))) else: nspath = path.replace('.', '/') return nspath
def get_real_path(path, path_ids): if 'VR_SDK_ROOT' in path: return path.replace('VR_SDK_ROOT', VR_SDK_ROOT) for path_id in path_ids: if path_id in path: return path.replace(path_id, path_ids[path_id])
def _do_record(self, path, dur): self._do_listen(conf.AUDIO_SIGNAL) # Signal! time.sleep(1) p= subprocess.Popen(['rec', '-c', '2', path, 'trim', '0', '00:%02d' % dur]) while p.poll() != 0: time.sleep(0.1) if self.is_file_open(path, 10): # 10 sec for saving the file. QtGui.QMessageBox.question(self, u"Файл занят другим приложением!", u"Достигнут таймаут при попытке записать файл \n%s" % path, QtGui.QMessageBox.Ok) else: p= subprocess.Popen(['sox', path, path.replace('.wav', '.'+conf.AUDIO_FORMAT)]) if self.is_file_open(path.replace('.wav', '.'+conf.AUDIO_FORMAT), 10): # 10 sec for converting. QtGui.QMessageBox.question(self, u"Файл занят другим приложением!", u"При попытке получить доступ достигнут таймаут \n%s" % path.replace('.wav', '.'+conf.AUDIO_FORMAT), QtGui.QMessageBox.Ok) else: self._do_listen(conf.AUDIO_SIGNAL) # Signal after recording. p= subprocess.Popen(['rm', path]) # Remove original wave. if conf.AUTOLISTEN: # Listen to the file just recorded. self.listen() self.lbFileExist.setText( # Change '<p style="font-size:80pt;color:#00208a">+</p>')
def serve_file(self): path = self.file_path # print 'serve %s' % path path = path.replace('//', '/') if path == '/': path = 'bloob.html' elif path == '/editor': path = 'editor.html' # Remove the leading forward slash if path[0] == '/': path = path[1:] # Security, remove the .. path = path.replace('..', '') # Determine the fullpath path = os.path.join(BASE_DIR, path) try: #print "try: ", path data = open(path, 'rb').read() type = self.guess_type(path) self.send_response(data, 200, headers={'Content-Type': type}) except: #print "except: ", path if '/favicon.ico' in path: self.send_response(FAVICON_GIF, 200, headers={'Content-Type': 'image/gif'}) else: #print "ERROR: 404" self.send_response('', 404)
def normalize_pics_root(fix_list, pics_root=None, appl_pics_root=None ): paths = tuple() for path in fix_list: path = path.replace(pics_root + '\\', "") path = path.replace(appl_pics_root + '\\', "") paths = paths + (path, ) return paths
def remote_mkdir(path): """Create a remote directory with the given name. If it already exists, just return with no error. """ return remote_py_cmd(["import os", "if not os.path.exists('%s'):" % path.replace('\\', '/'), " os.makedirs('%s')" % path.replace('\\', '/')])
def difsys_cmd(self, path): path = path.replace(conf('cmd_suffix'), ''); if path.endswith('.piece_created'): path = path.replace('.piece_created', ''); self.locks[path].set(); del self.locks[path]; return;
def _generateDbpath(self, path): if os.name == 'nt': db_folder = re.sub(r'[\\/]', '%', path.replace(':\\', '%', 1)) else: db_folder = path.replace('/', '%') return os.path.join(self._db_location, db_folder)
def SetupPythonPaths(): # Get the path we are in try: import xbmcaddon addon = xbmcaddon.Addon() path = addon.getAddonInfo('path') except: path = os.getcwd() # the XBMC libs return unicode info, so we need to convert this path = path.decode('utf-8') # .encode('latin-1') # insert the path at the start to prevent other lib-add-ons to steal our class names sys.path.insert(0, os.path.join(path.replace(";", ""), 'resources', 'libs')) # SHOULD ONLY BE ENABLED FOR REMOTE DEBUGGING PURPOSES # import remotedebugger # debugger = remotedebugger.RemoteDebugger() import envcontroller envController = envcontroller.EnvController() env = envController.GetEnvironmentFolder() # we do use append here, because it is better to use third party libs # instead of the included ones. sys.path.append(os.path.join(path.replace(";", ""), 'resources', 'libs', env)) return path
def CleanExpired(self): #delete files more than an hour old self.Notification('Hulu Library','Removing Expired Content') #delete old tv show files dir = xbmc.makeLegalFilename(TV_SHOWS_PATH) dirs, trash = xbmcvfs.listdir(dir) for show in dirs: show = xbmc.makeLegalFilename(os.path.join(dir, show)) trash, files = xbmcvfs.listdir(show) for file in files: path = xbmc.makeLegalFilename(os.path.join(show,file)) if (sys.platform == 'win32'): path = path.replace('smb:','') if (time.mktime(time.strptime(time.ctime(os.path.getmtime(path)))) < (time.mktime(time.localtime()) - 3600)): xbmcvfs.delete(path) #delete old movie files dir = xbmc.makeLegalFilename(MOVIE_PATH) trash, movies = xbmcvfs.listdir(dir) for movie in movies: path = xbmc.makeLegalFilename(os.path.join(dir, movie)) if (sys.platform == 'win32'): path = path.replace('smb:','') if time.mktime(time.strptime(time.ctime(os.path.getmtime(path)))) < (time.mktime(time.localtime()) - 3600): xbmcvfs.delete(path) xbmc.log(path) self.Notification('Hulu Library','Expired Content Removed')
def check_original(self): """Compare original path list with mirror""" try: self.logger.info('Indexing watched directory') for path in self.path.iterate_path(self.config.watch_dir): self.logger.debug('Index path: %s'%(path)) #check if path exist in validation list if not path.replace(self.config.watch_dir,self.config.mirror_dir) in self.mirror_validation_paths: self.logger.debug('Path not exist in mirror list validation, path: %s'%(path)) if os.path.isfile(path): self.logger.debug('Path is FILE, path: %s'%(path)) if not self.path.copy_path(path,path.replace(self.config.watch_dir,self.config.mirror_dir)): #failed copy file self.logger.error('Index watched directory error') return False elif os.path.isdir(path): self.logger.debug('Path is DIRECTORY, path: %s'%(path)) if not self.path.make_dir(path.replace(self.config.watch_dir,self.config.mirror_dir)): self.logger.error('Index watched directory error') return False else: #not recognize path self.logger.warning('Not recognize path: %s'%(path)) self.logger.error('Index watched directory error') return False else: #path exist in list validation skip and remove from list self.logger.debug('Path exist in mirror list validation, skiping and removing path from list, path: %s'%(path)) self.mirror_validation_paths.remove(path.replace(self.config.watch_dir,self.config.mirror_dir)) self.logger.info('Index watched directory ok') return True except Exception, e: self.logger.error('Index.check_original, error: %s'%(str(e)),exc_info=True) return False
def get_xpath_transition(self): sampled_urls = self.gold_dict.keys() counts_dict = defaultdict(int) # (cluster_id, xpath) -> int xpath_counts_dict = defaultdict(lambda : defaultdict(float)) # (cluster_id, xpath) - > dict[cluster_id] -> int trans_dict = read_trans_dict(self.dataset,self.date) # [page][xpath] = [url list] ->[cluster][xpath] = {probability list} print "sample_url", sampled_urls for page_path, trans in trans_dict.iteritems(): page_url = page_path.replace(".html","").replace("_","/") if page_url not in self.gold_dict: #print "?" + page_url, " is missing" continue else: cluster_id = self.cluster_dict[page_url] for xpath,url_list in trans.iteritems(): length = len(url_list) count = 0 for path in url_list: url = path.replace(".html","").replace("_","/") if url in sampled_urls: count += 1 #print "for xpath: {0} --- {1} out of {2} have been crawled and have cluster id".format(xpath,count, length) if count == 0: continue else: #if cluster_id == 1: # print page_path, xpath, url_list, "xpath_url_list in train" key = (cluster_id,xpath) #if key == (1,"/html/body/div/div/div/div/div/div/div/div/div/div/ul/li/div/div/div/div/div/div/div/ul/li/div/div/div/h3/a[yt-uix-sessionlink yt-uix-tile-link spf-link yt-ui-ellipsis yt-ui-ellipsis-2]"): # print page_path,url_list, "why 9 not 7???" counts_dict[key] += 1 ratio = float(length)/float(count) for path in url_list: url = path.replace(".html","").replace("_","/") if url in sampled_urls: destination_id = self.cluster_dict[url] #print url, destination_id xpath_counts_dict[key][destination_id] += 1 * ratio #if cluster_id == 1: # print "" # average for key,count in counts_dict.iteritems(): for destination_id in xpath_counts_dict[key]: xpath_counts_dict[key][destination_id] /= count print "Micro average entropy is " + str(self.entropy(xpath_counts_dict)) ''' output for key in xpath_counts_dict: if key[0] == 1: print key, xpath_counts_dict[key] ''' print "=========== end of training ============" self.xpath_counts_dict = xpath_counts_dict return xpath_counts_dict
def build_url(row): place_name = trim_place_name(row['NAME']) state = row['USPS'] state_name = statestyle.get(state).name path = u"%s, %s" % (quote_plus(place_name.encode('utf-8')), state_name) path = path.replace(' ','_') path = path.replace('+','_') return urljoin(BASE_URL,path)
def ExpandRuleVariables(self, path, root, dirname, source, ext, name): path = path.replace(generator_default_variables['RULE_INPUT_ROOT'], root) path = path.replace(generator_default_variables['RULE_INPUT_DIRNAME'], dirname) path = path.replace(generator_default_variables['RULE_INPUT_PATH'], source) path = path.replace(generator_default_variables['RULE_INPUT_EXT'], ext) path = path.replace(generator_default_variables['RULE_INPUT_NAME'], name) return path
def _smile_replacer(data): for smile, path in _SMILES: path = path.replace('/', '##/##') path = path.replace(':', '##:##') data = smile.sub(path, data) data = data.replace('##/##', '/') data = data.replace('##:##', ':') return data
def _listFiles(self,rootDir): for lists in os.listdir(rootDir): path = os.path.join(rootDir, lists) if os.path.isdir(path): self.dirList.append(path.replace('\\', '/')); self._listFiles(path) else: self.fileList.append(path.replace('\\', '/'));
def normalizePath(path, playPath, basedir): basedirParent = os.path.normpath(os.path.join(basedir, "..")) if len(playPath) > 0: path = path.replace(playPath, '${play.path}') path = path.replace(basedir, '${basedir}') path = path.replace(basedirParent, '${basedir}/..') path = path.replace('\\', '/') return path
def pathsinfo(infile,outfile): '''Create the paths info tex file''' ################################################ texpreamble = ['\documentclass[10pt,a5paper,landscape]{book}\n', '\usepackage{graphicx}\n', '\usepackage[a5paper,vmargin={5mm,2mm},hmargin={5mm,5mm}]{geometry}\n', '\usepackage[linktocpage]{hyperref}\n', '\usepackage[titles]{tocloft}\n' '\hypersetup{backref, colorlinks=true}\n', '\setlength{\cftsecnumwidth}{4em}\n' '\\title{ \\textbf{\Huge{HLT Timing Summary}} \\footnote{\large{Documentation at \url{https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideHLTTimingSummary}}} \\\\ Paths Info }\n', '\\author{\Large{CMS Experiment}}\n', '\date{\\today}\n', '\\begin{document}\n', '\maketitle\n', '\\newpage\n', '\\tableofcontents\n', '\\newpage\n'] names1 = {} file = TFile(infile,'read') for k in file.GetListOfKeys(): allnames= k.ReadObj().GetName() mean = 1 if 'moduleInPathScaledTime_' in allnames: pathname = '_'.join(allnames.split('_')[1:-1]) if not pathname in names1: names1[pathname] = mean names = names1.keys() names.sort() texfile = open(outfile+'-paths.tex', 'w') texfile.writelines(texpreamble) texfile.write('\\chapter{Average module (in path) time}\n') for path in names: texfile.write('\\newpage \section{'+ path.replace('_','\_') +'} \centering \includegraphics[scale=0.35]{moduleInPathTimeSummary'+ path.replace('_','') +'temp.png}\n') get_plot2(infile,'moduleInPathTimeSummary_'+path) texfile.write('\\chapter{Average module (in path) running time}\n') for path in names: texfile.write('\\newpage \section{'+ path.replace('_','\_') +'} \centering \includegraphics[scale=0.35]{moduleInPathScaledTimeSummary'+ path.replace('_','') +'temp.png}\n') get_plot2(infile,'moduleInPathScaledTimeSummary_'+path) texfile.write('\\chapter{Failing module (by path)}') for path in names: texfile.write('\\newpage \section{'+ path.replace('_','\_') +'} \centering \includegraphics[scale=0.35]{failedModule'+ path.replace('_','') +'temp.png}\n') get_plot2(infile,'failedModule_'+path) texfile.write('\\chapter{Per event time for path}\n') for path in names: texfile.write('\\newpage \section{'+ path.replace('_','\_') +'} \centering \includegraphics[scale=0.6]{pathTime'+ path.replace('_','') +'temp.png}\n') get_plot1(infile,'pathTime_'+path) texfile.write('\\chapter{Per event incremental time for path}\n') for path in names: texfile.write('\\newpage \section{'+ path.replace('_','\_') +'} \centering \includegraphics[scale=0.6]{incPathTime'+ path.replace('_','') +'temp.png}\n') get_plot1(infile,'incPathTime_'+path) texfile.write('\end{document}') texfile.close()
def _db_path_helper(path=None, lite=True): if lite: assert path.endswith('.dat.gz'), 'Expected .dat.gz extension for {}.'.format( path) return path.replace('.dat.gz', '-lite.db') else: assert path.endswith('.fits'), 'Expected .fits extention for {}.'.format( path) return path.replace('.fits', '.db')
def path_match_platform(path): path = unicode(path) if os.name == 'nt': if '/' in path: path.replace('/', '\\') elif os.name == 'posix': if '\\' in path: path.replace('\\', '/') return os.path.normpath(path)
def cache_base(path): path = trim_base(path).replace('/', '-').replace(' ', '_').replace('(', '').replace('&', '').replace(',', '').replace(')', '').replace('#', '').replace('[', '').replace(']', '').replace('"', '').replace("'", '').replace('_-_', '-').lower() while path.find("--") != -1: path = path.replace("--", "-") while path.find("__") != -1: path = path.replace("__", "_") if len(path) == 0: path = "root" return path
def test_label_to_path(tmpdir, label, attempt): # remove leading // path = label[2:] path = path.replace("/", os.sep) path = path.replace(":", os.sep) if attempt == 0: path = os.path.join(path, "test.log") else: path = os.path.join(path, "attempt_" + str(attempt) + ".log") return os.path.join(tmpdir, path)
def parse(self): try: if not self.m3u: return data = any2utf(self.m3u.read()) data = data.replace('\r\n', '\n').lstrip('\xef\xbb\xbf').split('\n') paths = [os.path.normpath(line).strip('\r\n').strip() for line in data if line.startswith("##") or not line.startswith("#")] dirname = os.path.dirname(self.path) full_paths = [] paths = iter(paths) for path in paths: text = None if path.startswith("##"): def task(path): text = path[2 : ] try: next_path = paths.next() path = next_path if not next_path.startswith("##") else None except StopIteration: path = None next_path = None if not path: full_paths.append( [path, text.strip('\r\n')] ) if next_path: path, text = task(next_path) return path, text path, text = task(path) if not path: break if text: text = text.strip('\r\n') else: new_text = path.rsplit('/', 1)[-1] if path == new_text: text = path.rsplit('\\', 1)[-1] else: text = new_text if (path in "\\/"): full_paths.append( [path.replace("\\", "/"), text] ) elif path.startswith('http'): if not text: text = path.rsplit('/', 1)[-1] full_paths.append( [path.replace('/', '//', 1), text] ) else: full_paths.append([os.path.join(dirname, path).replace("\\", "/"), text] ) return full_paths except IndexError: logging.warn("You try to load empty playlist")
def convert_to_print_link(self, path, is_anchor=False): """Converts a path used for WEB media to a single string (for either anchor or link) for use in PDF media.""" path = path.replace('/', '-').replace('#', '') if path.endswith('.html'): path = path[:-5] else: path = path.replace('.html', '-') if is_anchor: path = '#' + path return path
def convert_path(path): return path.replace('/', os.path.sep)
def enable_modules(self, modules, debug=False, crosscompiling=False): import sys validModules = [ # Qt Essentials 'QtCore', 'QtGui', 'QtMultimedia', 'QtMultimediaQuick_p', 'QtMultimediaWidgets', 'QtNetwork', 'QtPlatformSupport', 'QtQml', 'QtQmlDevTools', 'QtQuick', 'QtQuickParticles', 'QtSql', 'QtQuickTest', 'QtTest', 'QtWebKit', 'QtWebKitWidgets', 'QtWebSockets', 'QtWidgets', # Qt Add-Ons 'QtConcurrent', 'QtDBus', 'QtOpenGL', 'QtPrintSupport', 'QtDeclarative', 'QtScript', 'QtScriptTools', 'QtSvg', 'QtUiTools', 'QtXml', 'QtXmlPatterns', # Qt Tools 'QtHelp', 'QtDesigner', 'QtDesignerComponents', # Other 'QtCLucene', 'QtConcurrent', 'QtV8' ] pclessModules = [] staticModules = [] invalidModules = [] for module in modules: if module not in validModules: invalidModules.append(module) if invalidModules: raise Exception("Modules %s are not Qt5 modules. Valid Qt5 modules " "are: %s" % (invalidModules, validModules)) moduleDefines = { 'QtScript': ['QT_SCRIPT_LIB'], 'QtSvg': ['QT_SVG_LIB'], 'QtSql': ['QT_SQL_LIB'], 'QtXml': ['QT_XML_LIB'], 'QtOpenGL': ['QT_OPENGL_LIB'], 'QtGui': ['QT_GUI_LIB'], 'QtNetwork': ['QT_NETWORK_LIB'], 'QtCore': ['QT_CORE_LIB'], 'QtWidgets': ['QT_WIDGETS_LIB'], } for module in modules: try: self.AppendUnique(CPPDEFINES=moduleDefines[module]) except: pass debugSuffix = '' if sys.platform in ["darwin", "linux2", "linux"] and not crosscompiling: if debug: debugSuffix = '_debug' for module in modules: if module not in pclessModules: continue self.AppendUnique(LIBS=[module.replace('Qt', 'Qt5') + debugSuffix]) self.AppendUnique(LIBPATH=[os.path.join("$QT5DIR", "lib")]) self.AppendUnique(CPPPATH=[os.path.join("$QT5DIR", "include")]) self.AppendUnique( CPPPATH=[os.path.join("$QT5DIR", "include", module)]) pcmodules = [ module.replace('Qt', 'Qt5') + debugSuffix for module in modules if module not in pclessModules ] if 'Qt5DBus' in pcmodules: self.AppendUnique( CPPPATH=[os.path.join("$QT5DIR", "include", "Qt5DBus")]) if "Qt5Assistant" in pcmodules: self.AppendUnique( CPPPATH=[os.path.join("$QT5DIR", "include", "Qt5Assistant")]) pcmodules.remove("Qt5Assistant") pcmodules.append("Qt5AssistantClient") self.AppendUnique(RPATH=[os.path.join("$QT5DIR", "lib")]) self.ParseConfig('pkg-config %s --libs --cflags' % ' '.join(pcmodules)) self["QT5_MOCCPPPATH"] = self["CPPPATH"] return if sys.platform == "win32" or crosscompiling: if crosscompiling: transformedQtdir = transformToWinePath(self['QT5DIR']) self['QT5_MOC'] = "QT5DIR=%s %s" % (transformedQtdir, self['QT5_MOC']) self.AppendUnique(CPPPATH=[os.path.join("$QT5DIR", "include")]) try: modules.remove("QtDBus") except: pass if debug: debugSuffix = 'd' if "QtAssistant" in modules: self.AppendUnique( CPPPATH=[os.path.join("$QT5DIR", "include", "QtAssistant")]) modules.remove("QtAssistant") modules.append("QtAssistantClient") self.AppendUnique(LIBS=['qtmain' + debugSuffix]) self.AppendUnique(LIBS=[ lib.replace("Qt", "Qt5") + debugSuffix for lib in modules if lib not in staticModules ]) self.PrependUnique(LIBS=[ lib + debugSuffix for lib in modules if lib in staticModules ]) if 'QtOpenGL' in modules: self.AppendUnique(LIBS=['opengl32']) self.AppendUnique(CPPPATH=['$QT5DIR/include/']) self.AppendUnique( CPPPATH=['$QT5DIR/include/' + module for module in modules]) if crosscompiling: self["QT5_MOCCPPPATH"] = [ path.replace('$QT5DIR', transformedQtdir) for path in self['CPPPATH'] ] else: self["QT5_MOCCPPPATH"] = self["CPPPATH"] self.AppendUnique(LIBPATH=[os.path.join('$QT5DIR', 'lib')])
def escapePath(path, Config): # Remove escape literals escapeLiterals = Config['escape']['literals'] backslash = '\\' for literal in escapeLiterals: path = path.replace(backslash + literal, '') return path
def getReleaseNum(): path = os.path.dirname(os.path.abspath(__file__)) root = path.replace("tests/scripts", "") verFile = root + "version.txt" ver = readFileIntoArray(verFile)[0].rstrip() return ver
def resolve_relative(self, absolute, path): subs = path.replace('\\', '/').split('/') for sub in subs: if sub != '': absolute = os.path.join(absolute, sub) return absolute.replace('\\', '/')
def pathsinfo(infile, outfile): '''Create the paths info tex file''' ################################################ texpreamble = [ '\documentclass[10pt,a5paper,landscape]{book}\n', '\usepackage{graphicx}\n', '\usepackage[a5paper,vmargin={5mm,2mm},hmargin={5mm,5mm}]{geometry}\n', '\usepackage[linktocpage]{hyperref}\n', '\usepackage[titles]{tocloft}\n' '\hypersetup{backref, colorlinks=true}\n', '\setlength{\cftsecnumwidth}{4em}\n' '\\title{ \\textbf{\Huge{HLT Timing Summary}} \\footnote{\large{Documentation at \url{https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideHLTTimingSummary}}} \\\\ Paths Info }\n', '\\author{\Large{CMS Experiment}}\n', '\date{\\today}\n', '\\begin{document}\n', '\maketitle\n', '\\newpage\n', '\\tableofcontents\n', '\\newpage\n' ] names1 = {} file = TFile(infile, 'read') for k in file.GetListOfKeys(): allnames = k.ReadObj().GetName() mean = 1 if 'moduleInPathScaledTime_' in allnames: pathname = '_'.join(allnames.split('_')[1:-1]) if not pathname in names1: names1[pathname] = mean names = names1.keys() names.sort() texfile = open(outfile + '-paths.tex', 'w') texfile.writelines(texpreamble) texfile.write('\\chapter{Average module (in path) time}\n') for path in names: texfile.write( '\\newpage \section{' + path.replace('_', '\_') + '} \centering \includegraphics[scale=0.35]{moduleInPathTimeSummary' + path.replace('_', '') + 'temp.png}\n') get_plot2(infile, 'moduleInPathTimeSummary_' + path) texfile.write('\\chapter{Average module (in path) running time}\n') for path in names: texfile.write( '\\newpage \section{' + path.replace('_', '\_') + '} \centering \includegraphics[scale=0.35]{moduleInPathScaledTimeSummary' + path.replace('_', '') + 'temp.png}\n') get_plot2(infile, 'moduleInPathScaledTimeSummary_' + path) texfile.write('\\chapter{Failing module (by path)}') for path in names: texfile.write( '\\newpage \section{' + path.replace('_', '\_') + '} \centering \includegraphics[scale=0.35]{failedModule' + path.replace('_', '') + 'temp.png}\n') get_plot2(infile, 'failedModule_' + path) texfile.write('\\chapter{Per event time for path}\n') for path in names: texfile.write('\\newpage \section{' + path.replace('_', '\_') + '} \centering \includegraphics[scale=0.6]{pathTime' + path.replace('_', '') + 'temp.png}\n') get_plot1(infile, 'pathTime_' + path) texfile.write('\\chapter{Per event incremental time for path}\n') for path in names: texfile.write('\\newpage \section{' + path.replace('_', '\_') + '} \centering \includegraphics[scale=0.6]{incPathTime' + path.replace('_', '') + 'temp.png}\n') get_plot1(infile, 'incPathTime_' + path) texfile.write('\end{document}') texfile.close()
def removeRoot(path, root): newpath = path.replace(root, '', 1) if newpath[0] == '/' or newpath[0] == '\\': newpath = newpath[1:] return newpath
def wpath(path): if path.endswith('/') or path.endswith(os.path.sep): path = path[:-1] path = path.replace('/', '\\') return path
def unix_path(path): return path.replace('\\', '/')
def normalize_path(path): path = os.path.abspath(os.path.normpath(path)) return path.replace(os.sep, os.altsep)
def escape_path(path, escape_literals: str): # Remove escape literals backslash = '\\' for literal in escape_literals: path = path.replace(backslash + literal, '') return path
def Unixfy(self, path): return path.replace('\\', '/')
def enable_modules(self, modules, debug=False, crosscompiling=False): import sys validModules = [ 'QtCore', 'QtGui', 'QtOpenGL', 'Qt3Support', 'QtAssistant', # deprecated 'QtAssistantClient', 'QtScript', 'QtDBus', 'QtSql', 'QtSvg', # The next modules have not been tested yet so, please # maybe they require additional work on non Linux platforms 'QtNetwork', 'QtTest', 'QtXml', 'QtXmlPatterns', 'QtUiTools', 'QtDesigner', 'QtDesignerComponents', 'QtWebKit', 'QtHelp', 'QtScript', 'QtScriptTools', 'QtMultimedia', ] pclessModules = [ # in qt <= 4.3 designer and designerComponents are pcless, on qt4.4 they are not, so removed. # 'QtDesigner', # 'QtDesignerComponents', ] staticModules = [ 'QtUiTools', ] invalidModules = [] for module in modules: if module not in validModules: invalidModules.append(module) if invalidModules: raise Exception( "Modules %s are not Qt4 modules. Valid Qt4 modules are: %s" % (str(invalidModules), str(validModules))) moduleDefines = { 'QtScript': ['QT_SCRIPT_LIB'], 'QtSvg': ['QT_SVG_LIB'], 'Qt3Support': ['QT_QT3SUPPORT_LIB', 'QT3_SUPPORT'], 'QtSql': ['QT_SQL_LIB'], 'QtXml': ['QT_XML_LIB'], 'QtOpenGL': ['QT_OPENGL_LIB'], 'QtGui': ['QT_GUI_LIB'], 'QtNetwork': ['QT_NETWORK_LIB'], 'QtCore': ['QT_CORE_LIB'], } for module in modules: try: self.AppendUnique(CPPDEFINES=moduleDefines[module]) except: pass debugSuffix = '' if sys.platform in ["darwin", "linux2"] and not crosscompiling: if debug: debugSuffix = '_debug' for module in modules: if module not in pclessModules: continue self.AppendUnique(LIBS=[module + debugSuffix]) self.AppendUnique(LIBPATH=[os.path.join("$QT4DIR", "lib")]) self.AppendUnique( CPPPATH=[os.path.join("$QT4DIR", "include", "qt4")]) self.AppendUnique( CPPPATH=[os.path.join("$QT4DIR", "include", "qt4", module)]) pcmodules = [ module + debugSuffix for module in modules if module not in pclessModules ] if 'QtDBus' in pcmodules: self.AppendUnique( CPPPATH=[os.path.join("$QT4DIR", "include", "qt4", "QtDBus")]) if "QtAssistant" in pcmodules: self.AppendUnique(CPPPATH=[ os.path.join("$QT4DIR", "include", "qt4", "QtAssistant") ]) pcmodules.remove("QtAssistant") pcmodules.append("QtAssistantClient") self.ParseConfig('pkg-config %s --libs --cflags' % ' '.join(pcmodules)) self["QT4_MOCCPPPATH"] = self["CPPPATH"] return if sys.platform == "win32" or crosscompiling: if crosscompiling: transformedQtdir = transformToWinePath(self['QT4DIR']) self['QT4_MOC'] = "QT4DIR=%s %s" % (transformedQtdir, self['QT4_MOC']) self.AppendUnique(CPPPATH=[os.path.join("$QT4DIR", "include")]) try: modules.remove("QtDBus") except: pass if debug: debugSuffix = 'd' if "QtAssistant" in modules: self.AppendUnique( CPPPATH=[os.path.join("$QT4DIR", "include", "QtAssistant")]) modules.remove("QtAssistant") modules.append("QtAssistantClient") self.AppendUnique(LIBS=['qtmain' + debugSuffix]) self.AppendUnique(LIBS=[ lib + debugSuffix + '4' for lib in modules if lib not in staticModules ]) self.PrependUnique(LIBS=[ lib + debugSuffix for lib in modules if lib in staticModules ]) if 'QtOpenGL' in modules: self.AppendUnique(LIBS=['opengl32']) self.AppendUnique(CPPPATH=['$QT4DIR/include/']) self.AppendUnique( CPPPATH=['$QT4DIR/include/' + module for module in modules]) if crosscompiling: self["QT4_MOCCPPPATH"] = [ path.replace('$QT4DIR', transformedQtdir) for path in self['CPPPATH'] ] else: self["QT4_MOCCPPPATH"] = self["CPPPATH"] self.AppendUnique(LIBPATH=[os.path.join('$QT4DIR', 'lib')]) return """
def generate(self): if not self.copy_buffer: return from ranger.ext import shutil_generatorized as shutil_g # TODO: Don't calculate size when renaming (needs detection) bytes_per_tick = shutil_g.BLOCK_SIZE size = max(1, self._calculate_size(bytes_per_tick)) size_str = " (" + human_readable(self._calculate_size(1)) + ")" done = 0 if self.do_cut: self.original_copy_buffer.clear() if len(self.copy_buffer) == 1: self.description = "moving: " + self.one_file.path + size_str else: self.description = "moving files from: " + self.one_file.dirname + size_str for fobj in self.copy_buffer: for path in self.fm.tags.tags: if path == fobj.path or str(path).startswith(fobj.path): tag = self.fm.tags.tags[path] self.fm.tags.remove(path) self.fm.tags.tags[path.replace( fobj.path, self.original_path + '/' + fobj.basename)] = tag self.fm.tags.dump() n = 0 for n in shutil_g.move(src=fobj.path, dst=self.original_path, overwrite=self.overwrite): self.percent = ((done + n) / size) * 100. yield done += n else: if len(self.copy_buffer) == 1: self.description = "copying: " + self.one_file.path + size_str else: self.description = "copying files from: " + self.one_file.dirname + size_str for fobj in self.copy_buffer: if os.path.isdir(fobj.path) and not os.path.islink(fobj.path): n = 0 for n in shutil_g.copytree( src=fobj.path, dst=os.path.join(self.original_path, fobj.basename), symlinks=True, overwrite=self.overwrite, ): self.percent = ((done + n) / size) * 100. yield done += n else: n = 0 for n in shutil_g.copy2(fobj.path, self.original_path, symlinks=True, overwrite=self.overwrite): self.percent = ((done + n) / size) * 100. yield done += n cwd = self.fm.get_directory(self.original_path) cwd.load_content()
def maininfo(infile, outfile): ''' Creates main info tex file''' ############################################################## texpreamble = [ '\documentclass[10pt,a5paper,landscape]{report}\n', '\usepackage{graphicx}\n', '\usepackage[a5paper,vmargin={5mm,2mm},hmargin={5mm,5mm}]{geometry}\n', '\usepackage[linktocpage]{hyperref}\n', '\hypersetup{backref, colorlinks=true}\n', '\\title{ \\textbf{\Huge{HLT Timing Summary}} \\footnote{\large{Documentation at \url{https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideHLTTimingSummary}}} \\\\ Main Info }\n', '\\author{\Large{CMS Experiment}}\n', '\date{\\today}\n', '\\begin{document}\n', '\maketitle\n', '\\newpage\n', '\clearpage\n' '\\tableofcontents\n', '\\newpage\n', '\\newpage \chapter{Total time for all modules per event} \\newpage \centering \includegraphics[scale=0.6]{totalTimetemp.png}\n' ] names1 = {} names4 = {} specific = {} file1 = TFile(infile, 'read') for k in file1.GetListOfKeys(): allnames = k.ReadObj().GetName() if 'pathTime_' in allnames: pathname = '_'.join(allnames.split('_')[1:]) if not pathname in names1: names1[pathname] = k.ReadObj().GetMean() elif 'incPathTime_' in allnames: pathname = '_'.join(allnames.split('_')[1:]) if not pathname in names4: names4[pathname] = k.ReadObj().GetMean() names2 = dict( sorted(names1.iteritems(), key=operator.itemgetter(1), reverse=True)[:10]) names3 = sorted(names2, key=names2.get, reverse=True) names5 = dict( sorted(names4.iteritems(), key=operator.itemgetter(1), reverse=True)[:10]) names6 = sorted(names5, key=names5.get, reverse=True) texfile = open(outfile + '-main.tex', 'w') texfile.writelines(texpreamble) if os.path.exists(infile.replace('.root', '') + '-summary.txt'): excludefile = open(infile.replace('.root', '') + '-summary.txt', 'r') texfile.write('\\newpage \section{Summary} \n \\begin{verbatim} \n') for line in excludefile.readlines(): texfile.write(line + '\n') excludefile.close() texfile.write('\end{verbatim}') texfile.write('\\newpage \\chapter{10 Slowest Paths}\n') texfile.write('\section{Average module (in path) time}\n') for path in names3: texfile.write( '\\newpage \subsection{' + path.replace('_', '\_') + '} \centering \includegraphics[scale=0.35]{moduleInPathTimeSummary' + path.replace('_', '') + 'temp.png}\n') get_plot2(infile, 'moduleInPathTimeSummary_' + path) texfile.write('\section{Average module (in path) running time}\n') for path in names3: texfile.write( '\\newpage \subsection{' + path.replace('_', '\_') + '} \centering \includegraphics[scale=0.35]{moduleInPathScaledTimeSummary' + path.replace('_', '') + 'temp.png}\n') get_plot2(infile, 'moduleInPathScaledTimeSummary_' + path) texfile.write('\section{Per event time for path}\n') for path in names3: texfile.write('\\newpage \subsection{' + path.replace('_', '\_') + '} \centering \includegraphics[scale=0.6]{pathTime' + path.replace('_', '') + 'temp.png}\n') get_plot1(infile, 'pathTime_' + path) texfile.write('\section{Per event incremental time for path}\n') for path in names6: texfile.write('\\newpage \subsection{' + path.replace('_', '\_') + '} \centering \includegraphics[scale=0.6]{incPathTime' + path.replace('_', '') + 'temp.png}\n') get_plot1(infile, 'incPathTime_' + path) texfile.write('\end{document}') texfile.close() texfile.close() get_plot1(infile, 'totalTime')
def escape(path): return path.replace('//', '/').rstrip('/')
def specificpathinfo(infile, outfile, path): ''' Creates an specific path info tex file''' ############################################################## texpreamble = [ '\documentclass[10pt,a5paper,landscape]{report}\n', '\usepackage{graphicx}\n', '\usepackage[a5paper,vmargin={5mm,2mm},hmargin={5mm,5mm}]{geometry}\n', '\usepackage[linktocpage]{hyperref}\n', '\usepackage[titles]{tocloft}\n' '\hypersetup{backref, colorlinks=true}\n', '\setlength{\cftsubsecnumwidth}{4em}\n' '\\title{ \\textbf{\Huge{HLT Timing Summary}} \\footnote{\large{Documentation at \url{https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideHLTTimingSummary}}} \\\\ Main Info + ' + path.replace('_', '\_') + ' info }\n', '\\author{\Large{CMS Experiment}}\n', '\date{\\today}\n', '\\begin{document}\n', '\maketitle\n', '\\tableofcontents \n' '\\newpage\n \\chapter{Main Info} \n', '\\newpage \centering \section{Total time for all modules per event} \includegraphics[scale=0.6]{totalTimetemp.png}\n' ] texfile = open(outfile + '-' + path + '.tex', 'w') texfile.writelines(texpreamble) get_plot1(infile, 'totalTime') names = {} file1 = TFile(infile, 'read') for k in file1.GetListOfKeys(): allnames = k.ReadObj().GetName() if 'moduleInPathScaledTime_' in allnames: pathname = '_'.join(allnames.split('_')[1:-1]) if not pathname in names: names[pathname] = {} for pathnames in names.keys(): histo = file1.Get('moduleInPathTimeSummary_' + pathnames) for bin in range(histo.GetNbinsX()): label = histo.GetXaxis().GetBinLabel(bin + 1) names[pathnames][bin + 1] = label for pathname in names: if path in pathname: texfile.write('\chapter{' + path.replace('_', '\_') + ' Info} \n') texfile.write( '\\newpage \section{Average module in ' + path.replace('_', '\_') + ' time} \centering \includegraphics[scale=0.35]{moduleInPathTimeSummary' + path.replace('_', '') + 'temp.png}\n') get_plot2(infile, 'moduleInPathTimeSummary_' + path) texfile.write( '\\newpage \section{Average module in ' + path.replace('_', '\_') + ' running time} \centering \includegraphics[scale=0.35]{moduleInPathScaledTimeSummary' + path.replace('_', '') + 'temp.png}\n') get_plot2(infile, 'moduleInPathScaledTimeSummary_' + path) texfile.write('\\newpage \section{Per event time for ' + path.replace('_', '\_') + '} \centering \includegraphics[scale=0.6]{pathTime' + path.replace('_', '') + 'temp.png}\n') get_plot1(infile, 'pathTime_' + path) texfile.write( '\\newpage \section{Per event incremental time for ' + path.replace('_', '\_') + '} \centering \includegraphics[scale=0.6]{incPathTime' + path.replace('_', '') + 'temp.png}\n') get_plot1(infile, 'incPathTime_' + path) texfile.write('\section{Running time per event for ' + path.replace('_', '\_') + '}') for modules in names[path].values(): texfile.write( '\subsection{' + modules + '} \centering \includegraphics[scale=0.6]{moduleInPathScaledTime' + path.replace('_', '') + modules + 'temp.png}\n') get_plot1(infile, 'moduleInPathScaledTime_' + path + '_' + modules) texfile.write('\\end{document}') texfile.close()
def sanitize_log_path(path): # Sanitize the string so that its log path is shell friendly replace_map = {' ': '-', '(': '_', ')': '_'} for s, r in six.iteritems(replace_map): path = path.replace(s, r) return path
def format_local_path(self, path): """Format path for local access to the repository""" if sys.platform != 'win32': return 'file://{}'.format(path) return 'file:///{}'.format(path.replace('\\', '/'))
def execute(self, context): import re, os.path mate = context.material mate_name = common.remove_serial_number(mate.name) output_text = "1000" + "\n" output_text += mate_name.lower() + "\n" output_text += mate_name + "\n" output_text += mate['shader1'] + "\n" output_text += mate['shader2'] + "\n" output_text += "\n" for tex_slot in mate.texture_slots: if not tex_slot: continue tex = tex_slot.texture if tex_slot.use: type = 'tex' else: if tex_slot.use_rgb_to_intensity: type = 'col' else: type = 'f' output_text += type + "\n" output_text += "\t" + common.remove_serial_number(tex.name) + "\n" if type == 'tex': try: img = tex.image except: self.report(type={'ERROR'}, message="texタイプの設定値の取得に失敗しました、中止します") return {'CANCELLED'} if img: output_text += '\ttex2d' + "\n" output_text += "\t" + common.remove_serial_number( img.name) + "\n" if 'cm3d2_path' in img: path = img['cm3d2_path'] else: path = bpy.path.abspath(bpy.path.abspath(img.filepath)) path = path.replace('\\', '/') path = re.sub(r'^[\/\.]*', "", path) if not re.search(r'^assets/texture/', path, re.I): path = "Assets/texture/texture/" + os.path.basename( path) output_text += "\t" + path + "\n" col = tex_slot.color output_text += "\t" + " ".join([ str(col[0]), str(col[1]), str(col[2]), str(tex_slot.diffuse_color_factor) ]) + "\n" else: output_text += "\tnull" + "\n" elif type == 'col': col = tex_slot.color output_text += "\t" + " ".join([ str(col[0]), str(col[1]), str(col[2]), str(tex_slot.diffuse_color_factor) ]) + "\n" elif type == 'f': output_text += "\t" + str(tex_slot.diffuse_color_factor) + "\n" context.window_manager.clipboard = output_text self.report(type={'INFO'}, message="マテリアルテキストをクリップボードにコピーしました") return {'FINISHED'}
def slashify_path(path): return path.replace('\\', '/')
def _classify_files(install_paths, package_data, package_prefixes, py_modules, new_py_modules, scripts, new_scripts, data_files, cmake_source_dir, cmake_install_dir): assert not os.path.isabs(cmake_source_dir) assert cmake_source_dir != "." cmake_source_dir = to_unix_path(cmake_source_dir) install_root = os.path.join(os.getcwd(), CMAKE_INSTALL_DIR) for path in install_paths: found_package = False found_module = False found_script = False # if this installed file is not within the project root, complain and # exit if not to_platform_path(path).startswith(CMAKE_INSTALL_DIR): raise SKBuildError( ("\n CMake-installed files must be within the project root.\n" " Project Root : {}\n" " Violating File: {}\n").format(install_root, to_platform_path(path))) # peel off the 'skbuild' prefix path = to_unix_path(os.path.relpath(path, CMAKE_INSTALL_DIR)) # If the CMake project lives in a sub-directory (e.g src), its # include rules are relative to it. If the project is not already # installed in a directory, we need to prepend # the source directory so that the remaining of the logic # can successfully check if the path belongs to a package or # if it is a module. # TODO(jc) Instead of blindly checking if cmake_install_dir is set # or not, a more elaborated check should be done. if (not cmake_install_dir and cmake_source_dir and not path.startswith(cmake_source_dir)): path = to_unix_path(os.path.join(cmake_source_dir, path)) # check to see if path is part of a package for prefix, package in package_prefixes: if path.startswith(prefix + "/"): # peel off the package prefix path = to_unix_path(os.path.relpath(path, prefix)) package_file_list = package_data.get(package, []) package_file_list.append(path) package_data[package] = package_file_list found_package = True break if found_package: continue # If control reaches this point, then this installed file is not part of # a package. # check if path is a module for module in py_modules: if path.replace("/", ".") == ".".join((module, "py")): new_py_modules[module] = True found_module = True break if found_module: continue # If control reaches this point, then this installed file is not a # module # if the file is a script, mark the corresponding script for script in scripts: if path == script: new_scripts[script] = True found_script = True break if found_script: continue # If control reaches this point, then this installed file is not a # script # If control reaches this point, then we have installed files that are # not part of a package, not a module, nor a script. Without any other # information, we can only treat it as a generic data file. parent_dir = os.path.dirname(path) file_set = data_files.get(parent_dir) if file_set is None: file_set = set() data_files[parent_dir] = file_set file_set.add(os.path.join(CMAKE_INSTALL_DIR, path)) del parent_dir, file_set
def normalize(path): return os.path.normpath(path.replace('\\', '/').replace('\\', '/'))
def format_local_path(self, path): """Format path for local access to the repository.""" if sys.platform != "win32": return "file://{}".format(path) return "file:///{}".format(path.replace("\\", "/"))
def resolve_path(self, window, view, paths, skip_folders=False): global cache if not paths.strip(): return False debug_info('-- original paths --') debug_info(paths) debug_info('-- /original paths --') try: paths_decoded = urllib.unquote(paths.encode('utf8')) paths_decoded = unicode(paths_decoded.decode('utf8')) paths += '\n' + paths_decoded except: try: paths_decoded = urllib.parse.unquote(paths) paths += '\n' + paths_decoded except: pass user_home_path = expanduser("~") paths = re.sub('"|\'|<|>|\(|\)|\{|\}|\[|\]|;', '', paths) for path in paths.split('\n'): if not path.startswith('http'): # remove quotes paths += '\n' + re.sub(';', '', path) # remove :row:col # paths += '\n' + re.sub('(\:[0-9]*)+$', '', path).strip() # replace . for / paths += '\n' + path.replace('./', '.').replace('.', '/') # replace :: for / paths += '\n' + path.replace('::', '/') # replace ~ for the user's home directory if get_setting('expand_tilde', True): paths += '\n' + path.replace('~', user_home_path) if get_setting('expand_env_var', True): paths += '\n' + os.path.expandvars(path) paths = paths.strip().split('\n') if paths[0].startswith('http'): return self.try_open(window, paths[0]) if get_setting('use_strict'): return self.try_open( window, self.resolve_relative(os.path.dirname(view.file_name()), paths[0])) paths, num_added = self.expand_paths_with_extensions( window, view, paths) if cache['look_into_folders'] and not skip_folders: paths = self.expand_paths_with_sub_and_parent_folders( window, view, paths) something_opened = False folder_structure = [] + [ "../" * i for i in range(get_setting('maximum_folder_up', 5)) ] if view.file_name(): view_dirname = os.path.dirname(view.file_name()) view_dirname_dirname = os.path.dirname(view_dirname) paths = unique(paths) debug_info('-- resolved paths --') debug_info(paths) debug_info('-- /resolved paths --') threshold = get_setting('path_len_threshold', 10) + num_added if len(paths) > threshold: print( "-- There are too many paths, probably we shouldn't open! Path count: %d" % len(paths)) return False for path in paths: path = path.strip() path_normalized = normalize(path) if path == '' or path_normalized in cache['done']: continue cache['done'][path_normalized] = True cache['folder_save'] = False # relative to view & view dir name opened = False if view.file_name(): for new_path_prefix in folder_structure: opened = self.create_path_relative_to_folder( window, view, view_dirname, new_path_prefix + path) if not opened: opened = self.create_path_relative_to_folder( window, view, view_dirname_dirname, new_path_prefix + path) if opened: break # relative to project folders if not opened: for maybe_path in sublime.active_window().folders(): for new_path_prefix in folder_structure: if self.create_path_relative_to_folder( window, view, maybe_path, new_path_prefix + path): opened = True break if opened: break cache['folder_save'] = True # absolute if not opened: opened = self.try_open(window, path) if opened: something_opened = True break return something_opened
def found_match(path): # switch matches to use `/` folder sep if necessary (i.e. on Windows) if sep == '\\': path = path.replace('\\', '/') matches.append(path)
def to_java_compatible_path(path): if os.name == 'nt': path = path.replace('\\', '/') return path
def relativize(base, path): """Convert an absolute URL or file path to a relative one""" path = path.replace('\\', '/') return re.sub("^" + base, "", path)
def Sep(path): """Converts slashes in the path to the architecture's path seperator.""" if isinstance(path, str): return path.replace('/', os.sep) return path
def _CheckDartFormat(input_api, output_api): local_root = input_api.change.RepositoryRoot() upstream = input_api.change._upstream utils = imp.load_source('utils', os.path.join(local_root, 'tools', 'utils.py')) prebuilt_dartfmt = os.path.join(utils.CheckedInSdkPath(), 'bin', 'dartfmt') windows = utils.GuessOS() == 'win32' if windows: prebuilt_dartfmt += '.bat' if not os.path.isfile(prebuilt_dartfmt): print('WARNING: dartfmt not found: %s' % (prebuilt_dartfmt)) return [] def HasFormatErrors(filename=None, contents=None): args = [prebuilt_dartfmt, '--set-exit-if-changed'] if not contents: args += [filename, '-n'] process = subprocess.Popen(args, stdout=subprocess.PIPE, stdin=subprocess.PIPE) process.communicate(input=contents) # Check for exit code 1 explicitly to distinguish it from a syntax error # in the file (exit code 65). The repo contains many Dart files that are # known to have syntax errors for testing purposes and which can't be # parsed and formatted. Don't treat those as errors. return process.returncode == 1 unformatted_files = [] for git_file in input_api.AffectedTextFiles(): filename = git_file.AbsoluteLocalPath() if filename.endswith('.dart'): if HasFormatErrors(filename=filename): old_version_has_errors = False try: path = git_file.LocalPath() if windows: # Git expects a linux style path. path = path.replace(os.sep, '/') old_contents = scm.GIT.Capture( ['show', upstream + ':' + path], cwd=local_root, strip_out=False) if HasFormatErrors(contents=old_contents): old_version_has_errors = True except subprocess.CalledProcessError as e: # TODO(jacobr): verify that the error really is that the file was # added for this CL. old_version_has_errors = False if old_version_has_errors: print( "WARNING: %s has existing and possibly new dartfmt issues" % git_file.LocalPath()) else: unformatted_files.append(filename) if unformatted_files: return [ output_api.PresubmitError( 'File output does not match dartfmt.\n' 'Fix these issues with:\n' '%s -w \\\n%s' % (prebuilt_dartfmt, ' \\\n'.join(unformatted_files))) ] return []