rem
stringlengths 0
322k
| add
stringlengths 0
2.05M
| context
stringlengths 8
228k
|
---|---|---|
ops.extend( controller.update_annotation_ops(new_module, [(annotation_key, annotation.value)])) local_port_specs = {} | new_annotation = \ Annotation(id=controller.id_scope.getNewId(Annotation.vtType), key=annotation_key, value=annotation.value) new_module.add_annotation(new_annotation) | def replace_generic(controller, pipeline, old_module, new_module, function_remap={}, src_port_remap={}, dst_port_remap={}, annotation_remap={}): ops = [] ops.extend(controller.delete_module_list_ops(pipeline, [old_module.id])) ops.append(('add', new_module)) for annotation in old_module.annotations: if annotation.key not in annotation_remap: annotation_key = annotation.key else: remap = annotation_remap[annotation.key] if remap is None: # don't add the annotation back in continue elif type(remap) != type(""): ops.extend(remap(annotation)) continue else: annotation_key = remap |
local_port_specs[(new_spec.name, new_spec.type)] = new_spec ops.append(('add', new_spec, 'module', new_module.id)) print local_port_specs | new_module.add_port_spec(new_spec) | def replace_generic(controller, pipeline, old_module, new_module, function_remap={}, src_port_remap={}, dst_port_remap={}, annotation_remap={}): ops = [] ops.extend(controller.delete_module_list_ops(pipeline, [old_module.id])) ops.append(('add', new_module)) for annotation in old_module.annotations: if annotation.key not in annotation_remap: annotation_key = annotation.key else: remap = annotation_remap[annotation.key] if remap is None: # don't add the annotation back in continue elif type(remap) != type(""): ops.extend(remap(annotation)) continue else: annotation_key = remap |
ops.extend(controller.update_function_ops(new_module, | new_function = controller.create_function(new_module, | def replace_generic(controller, pipeline, old_module, new_module, function_remap={}, src_port_remap={}, dst_port_remap={}, annotation_remap={}): ops = [] ops.extend(controller.delete_module_list_ops(pipeline, [old_module.id])) ops.append(('add', new_module)) for annotation in old_module.annotations: if annotation.key not in annotation_remap: annotation_key = annotation.key else: remap = annotation_remap[annotation.key] if remap is None: # don't add the annotation back in continue elif type(remap) != type(""): ops.extend(remap(annotation)) continue else: annotation_key = remap |
new_param_vals)) | new_param_vals) new_module.add_function(new_function) ops.append(('add', new_module)) | def replace_generic(controller, pipeline, old_module, new_module, function_remap={}, src_port_remap={}, dst_port_remap={}, annotation_remap={}): ops = [] ops.extend(controller.delete_module_list_ops(pipeline, [old_module.id])) ops.append(('add', new_module)) for annotation in old_module.annotations: if annotation.key not in annotation_remap: annotation_key = annotation.key else: remap = annotation_remap[annotation.key] if remap is None: # don't add the annotation back in continue elif type(remap) != type(""): ops.extend(remap(annotation)) continue else: annotation_key = remap |
if ((src_port, 'output')) in local_port_specs: output_port_spec = local_port_specs[(src_port, 'output')] else: output_port_spec = \ src_module.get_port_spec(src_port, 'output') | output_port_spec = src_module.get_port_spec(src_port, 'output') | def create_new_connection(src_module, src_port, dst_module, dst_port): # spec -> name, type, signature output_port_id = controller.id_scope.getNewId(Port.vtType) if type(src_port) == type(""): if ((src_port, 'output')) in local_port_specs: output_port_spec = local_port_specs[(src_port, 'output')] else: output_port_spec = \ src_module.get_port_spec(src_port, 'output') output_port = Port(id=output_port_id, spec=output_port_spec, moduleId=src_module.id, moduleName=src_module.name) else: output_port = Port(id=output_port_id, name=src_port.name, type=src_port.type, signature=src_port.signature, moduleId=src_module.id, moduleName=src_module.name) |
if ((dst_port, 'input')) in local_port_specs: input_port_spec = local_port_specs[(dst_port, 'input')] else: input_port_spec = \ dst_module.get_port_spec(dst_port, 'input') | input_port_spec = dst_module.get_port_spec(dst_port, 'input') | def create_new_connection(src_module, src_port, dst_module, dst_port): # spec -> name, type, signature output_port_id = controller.id_scope.getNewId(Port.vtType) if type(src_port) == type(""): if ((src_port, 'output')) in local_port_specs: output_port_spec = local_port_specs[(src_port, 'output')] else: output_port_spec = \ src_module.get_port_spec(src_port, 'output') output_port = Port(id=output_port_id, spec=output_port_spec, moduleId=src_module.id, moduleName=src_module.name) else: output_port = Port(id=output_port_id, name=src_port.name, type=src_port.type, signature=src_port.signature, moduleId=src_module.id, moduleName=src_module.name) |
self._tf = pickle.loads(param.strValue.decode('hex')) | self._tf = TransferFunction.parse(param.strValue) | def __init__(self, param, parent=None): QtGui.QWidget.__init__(self, parent) ConstantWidgetMixin.__init__(self, param.strValue) if not param.strValue: self._tf = copy.copy(default_tf) else: self._tf = pickle.loads(param.strValue.decode('hex')) self._scene = TransferFunctionScene(self._tf, self) layout = QtGui.QVBoxLayout() self.setLayout(layout) self._view = TransferFunctionView() self._view.setScene(self._scene) self._view.setMinimumSize(200,200) self._view.show() self._view.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) self._view.setMatrix(QtGui.QMatrix(180, 0, 0, -180, 0, 0)) self.setMinimumSize(200,200) caption = QtGui.QLabel("Double-click on the line to add a point") font = QtGui.QFont('Arial', 11) font.setItalic(True) caption.setFont(font) layout.addWidget(self._view) layout.addWidget(caption) |
self._view = TransferFunctionView() | self._view = TransferFunctionView(self) | def __init__(self, param, parent=None): QtGui.QWidget.__init__(self, parent) ConstantWidgetMixin.__init__(self, param.strValue) if not param.strValue: self._tf = copy.copy(default_tf) else: self._tf = pickle.loads(param.strValue.decode('hex')) self._scene = TransferFunctionScene(self._tf, self) layout = QtGui.QVBoxLayout() self.setLayout(layout) self._view = TransferFunctionView() self._view.setScene(self._scene) self._view.setMinimumSize(200,200) self._view.show() self._view.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) self._view.setMatrix(QtGui.QMatrix(180, 0, 0, -180, 0, 0)) self.setMinimumSize(200,200) caption = QtGui.QLabel("Double-click on the line to add a point") font = QtGui.QFont('Arial', 11) font.setItalic(True) caption.setFont(font) layout.addWidget(self._view) layout.addWidget(caption) |
return pickle.dumps(self._scene.get_transfer_function()).encode('hex') | return self._scene.get_transfer_function().serialize() | def contents(self): return pickle.dumps(self._scene.get_transfer_function()).encode('hex') |
self._tf = pickle.loads(strValue.decode('hex')) | self._tf = TransferFunction.parse(strValue) | def setContents(self, strValue, silent=True): if not strValue: self._tf = copy.copy(default_tf) else: self._tf = pickle.loads(strValue.decode('hex')) self._scene.reset_transfer_function(self._tf) if not silent: self.update_parent() |
string_conversion = staticmethod(lambda x: pickle.dumps(x).encode('hex')) conversion = staticmethod(lambda x: pickle.loads(x.decode('hex'))) | string_conversion = staticmethod(lambda x: x.serialize()) conversion = staticmethod(lambda x: TransferFunction.parse(x)) | def compute(self): tf = self.getInputFromPort('TransferFunction') new_tf = copy.copy(tf) if self.hasInputFromPort('Input'): port = self.getInputFromPort('Input') algo = port.vtkInstance.GetProducer() output = algo.GetOutput(port.vtkInstance.GetIndex()) (new_tf._min_range, new_tf._max_range) = output.GetScalarRange() elif self.hasInputFromPort('Dataset'): algo = self.getInputFromPort('Dataset').vtkInstance output = algo (new_tf._min_range, new_tf._max_range) = output.GetScalarRange() else: (new_tf._min_range, new_tf._max_range) = self.getInputFromPort('Range') self.setResult('TransferFunction', new_tf) |
vp = '_%s_void_p' % (hex(display)[2:]) | vp = '_%s_void_p\0x00' % (hex(display)[2:]) | def SetRenderWindow(self,w): """ SetRenderWindow(w: vtkRenderWindow) Set a new render window to QVTKWidget and initialize the interactor as well """ if w == self.mRenWin: return if self.mRenWin: if system.systemType!='Linux': self.mRenWin.SetInteractor(None) if self.mRenWin.GetMapped(): self.mRenWin.Finalize() self.mRenWin = w if self.mRenWin: self.mRenWin.Register(None) if self.mRenWin.GetMapped(): self.mRenWin.Finalize() if system.systemType=='Linux': try: vp = '_%s_void_p' % (hex(int(QtGui.QX11Info.display()))[2:]) except TypeError: #This was change for PyQt4.2 if isinstance(QtGui.QX11Info.display(),QtGui.Display): display = sip.unwrapinstance(QtGui.QX11Info.display()) vp = '_%s_void_p' % (hex(display)[2:]) self.mRenWin.SetDisplayId(vp) self.resizeWindow(1,1) self.mRenWin.SetWindowInfo(str(int(self.winId()))) if self.isVisible(): self.mRenWin.Start() |
def download(url,filename): """download(url:string, filename: string) -> Boolean Downloads a binary file from url to filename and returns True (success) or False (failure) """ try: furl = urllib2.urlopen(url) f = file(filename,'wb') f.write(furl.read()) f.close() return True except: return False def download_as_text(url): """download_as_text(url: string) -> string Downloads a url as text. It will return None if it failed. """ try: furl = urllib2.urlopen(url) s = furl.read() return s except: return None def _download_content(url, request, path_to_figures): """_download_images(url:string, request:string, path_to_figures:string) -> (Boolean, message) Downloads all images and pdf files listed in url and saves them to path_to_figures """ website = url url = request try: page = download_as_text(url) re_imgs = re.compile('<img[^>]*/>') re_src = re.compile('(.*src=")([^"]*)"') re_a = re.compile('<a[^>]*>[^<]*</a>') re_href = re.compile('(.*href=")([^"]*)"') images = re_imgs.findall(page) files = re_a.findall(page) failed = False msg = '' if len(images) > 0 or len(files) > 0: for i in images: pngfile = re_src.match(i).groups()[1] if not check_url(pngfile): img = website + pngfile else: img = pngfile if not download(img, os.path.join(path_to_figures, os.path.basename(img))): msg += "Error when downloading image: %s. <return>" %img failed = True for f in files: otherfile = re_href.match(f).groups()[1] if not check_url(otherfile): filename = website + otherfile else: filename = otherfile if not download(filename, os.path.join(path_to_figures, os.path.basename(filename))): msg += "Error when downloading file: %s. <return>"%filename failed = True if not failed : return (True, "") else: return (False, msg) else: msg = "Web server returned: %s" % page return (False, msg) except Exception, e: return (False, str(e)) | def path_exists_and_not_empty(path): """path_exists_and_not_empty(path:str) -> boolean Returns True if given path exists and it's not empty, otherwise returns False. """ if os.path.exists(path): for root, dirs, file_names in os.walk(path): break if len(file_names) > 0: return True return False |
|
port, path_to_figures): | port, path_to_figures, pdf=False, graph=False): | def build_vistrails_cmd_line(path_to_vistrails, host, db_name, vt_id, version, port, path_to_figures): """ build_vistrails_cmd_line(path_to_vistrails: str, host: str, db_name: str, vt_id: str, version: str, path_to_figures: str) -> str Build the command line to run vistrails with the given parameters. """ cmd_line = 'python "%s" -b -e "%s" -t %s -f %s -r %s -u %s "%s:%s" > \ |
cmd_line = 'python "%s" -b -e "%s" -t %s -f %s -r %s -u %s "%s:%s" > \ vistrails.log' % (vt_user, path_to_vistrails, | if pdf: pdfoption = "-p" else: pdfoption = "" if graph: graphoption = '-I %s'%path_to_figures else: graphoption = "" if version is not None: voption = ":%s"%version else: voption = '' cmd_line = 'python "%s" -b -e "%s" -t %s -f %s -r %s %s %s "%s%s" > \ vistrails.log' % (path_to_vistrails, | def build_vistrails_cmd_line(path_to_vistrails, host, db_name, vt_id, version, port, path_to_figures): """ build_vistrails_cmd_line(path_to_vistrails: str, host: str, db_name: str, vt_id: str, version: str, path_to_figures: str) -> str Build the command line to run vistrails with the given parameters. """ cmd_line = 'python "%s" -b -e "%s" -t %s -f %s -r %s -u %s "%s:%s" > \ |
version) | voption) | def build_vistrails_cmd_line(path_to_vistrails, host, db_name, vt_id, version, port, path_to_figures): """ build_vistrails_cmd_line(path_to_vistrails: str, host: str, db_name: str, vt_id: str, version: str, path_to_figures: str) -> str Build the command line to run vistrails with the given parameters. """ cmd_line = 'python "%s" -b -e "%s" -t %s -f %s -r %s -u %s "%s:%s" > \ |
def generate_latex(host, db_name, vt_id, version, port, tag, execute, showspreadsheetonly, path_to_figures, graphics_options): | def generate_latex(download_url, host, db_name, vt_id, version, port, tag, execute, showspreadsheetonly, path_to_figures, graphics_options): | def generate_latex(host, db_name, vt_id, version, port, tag, execute, showspreadsheetonly, path_to_figures, graphics_options): """generate_latex(host: str, db_name:str, vt_id: str, version: str, port:str, tag: str, execute: bool, showspreadsheetonly: bool, path_to_figures: str, graphics_options: str) -> str This generates a piece of latex code containing the \href command and a \includegraphics command for each image generated. """ url_params = "getvt=%s&version=%s&db=%s&host=%s&port=%s&tag=%s&\ |
url_params = "getvt=%s&version=%s&db=%s&host=%s&port=%s&tag=%s&\ | if download_url is not None and download_url != "": url_params = "getvt=%s&db=%s&host=%s&port=%s&tag=%s&\ | def generate_latex(host, db_name, vt_id, version, port, tag, execute, showspreadsheetonly, path_to_figures, graphics_options): """generate_latex(host: str, db_name:str, vt_id: str, version: str, port:str, tag: str, execute: bool, showspreadsheetonly: bool, path_to_figures: str, graphics_options: str) -> str This generates a piece of latex code containing the \href command and a \includegraphics command for each image generated. """ url_params = "getvt=%s&version=%s&db=%s&host=%s&port=%s&tag=%s&\ |
urllib2.quote(version), | def generate_latex(host, db_name, vt_id, version, port, tag, execute, showspreadsheetonly, path_to_figures, graphics_options): """generate_latex(host: str, db_name:str, vt_id: str, version: str, port:str, tag: str, execute: bool, showspreadsheetonly: bool, path_to_figures: str, graphics_options: str) -> str This generates a piece of latex code containing the \href command and a \includegraphics command for each image generated. """ url_params = "getvt=%s&version=%s&db=%s&host=%s&port=%s&tag=%s&\ |
|
url_params = url_params.replace("%","\%") url = "http://www.vistrails.org/extensions/download.php?%s"% url_params href = "\href{%s}{" % url | if version is not None: url_params += "&version=%s"%urllib2.quote(version) url_params = url_params.replace("%","\%") url = "%s?%s"%(download_url, url_params) href = "\href{%s}{" % url | def generate_latex(host, db_name, vt_id, version, port, tag, execute, showspreadsheetonly, path_to_figures, graphics_options): """generate_latex(host: str, db_name:str, vt_id: str, version: str, port:str, tag: str, execute: bool, showspreadsheetonly: bool, path_to_figures: str, graphics_options: str) -> str This generates a piece of latex code containing the \href command and a \includegraphics command for each image generated. """ url_params = "getvt=%s&version=%s&db=%s&host=%s&port=%s&tag=%s&\ |
s += "}" return href+s | if download_url is not None and download_url != "": return href + s + "}" else: return s | def generate_latex(host, db_name, vt_id, version, port, tag, execute, showspreadsheetonly, path_to_figures, graphics_options): """generate_latex(host: str, db_name:str, vt_id: str, version: str, port:str, tag: str, execute: bool, showspreadsheetonly: bool, path_to_figures: str, graphics_options: str) -> str This generates a piece of latex code containing the \href command and a \includegraphics command for each image generated. """ url_params = "getvt=%s&version=%s&db=%s&host=%s&port=%s&tag=%s&\ |
tag='', execute=False, showspreadsheetonly=False): | tag='', execute=False, showspreadsheetonly=False, pdf=False): | def run_vistrails_locally(path_to_vistrails, host, db_name, vt_id, version, port, path_to_figures, build_always=False, tag='', execute=False, showspreadsheetonly=False): """run_vistrails_locally(path_to_vistrails: str, host: str, db_name: str, vt_id: str, version: str, port: str, path_to_figures: str) -> tuple(bool, str) Run vistrails and returns a tuple containing a boolean saying if it was successful or not and the latex code. """ cmd_line = build_vistrails_cmd_line(path_to_vistrails, host, db_name, vt_id, version, port, path_to_figures) if not os.path.exists(path_to_figures): os.makedirs(path_to_figures) result = os.system(cmd_line) if result != 0: os.rmdir(path_to_figures) msg = "See vistrails.log for more information." return (False, generate_latex_error(msg)) else: if build_always or not path_exists_and_not_empty(path_to_figures): result = os.system(cmd_line) if result != 0: os.rmdir(path_to_figures) msg = "See vistrails.log for more information." return (False, generate_latex_error(msg)) return (True, generate_latex(host, db_name, vt_id, version, port, tag, execute, showspreadsheetonly, path_to_figures, graphics_options)) |
version, port, path_to_figures) | version, port, path_to_figures, pdf) | def run_vistrails_locally(path_to_vistrails, host, db_name, vt_id, version, port, path_to_figures, build_always=False, tag='', execute=False, showspreadsheetonly=False): """run_vistrails_locally(path_to_vistrails: str, host: str, db_name: str, vt_id: str, version: str, port: str, path_to_figures: str) -> tuple(bool, str) Run vistrails and returns a tuple containing a boolean saying if it was successful or not and the latex code. """ cmd_line = build_vistrails_cmd_line(path_to_vistrails, host, db_name, vt_id, version, port, path_to_figures) if not os.path.exists(path_to_figures): os.makedirs(path_to_figures) result = os.system(cmd_line) if result != 0: os.rmdir(path_to_figures) msg = "See vistrails.log for more information." return (False, generate_latex_error(msg)) else: if build_always or not path_exists_and_not_empty(path_to_figures): result = os.system(cmd_line) if result != 0: os.rmdir(path_to_figures) msg = "See vistrails.log for more information." return (False, generate_latex_error(msg)) return (True, generate_latex(host, db_name, vt_id, version, port, tag, execute, showspreadsheetonly, path_to_figures, graphics_options)) |
def run_vistrails_remotely(path_to_vistrails, host, db_name, vt_id, | def get_vt_graph_locally(path_to_vistrails, host, db_name, vt_id, port, path_to_figures, build_always=False, pdf=False): """get_vt_graph_locally(path_to_vistrails: str, host: str, db_name: str, vt_id: str, port: str, path_to_figures: str, build_always: bool, pdf:bool) -> tuple(bool, str) Run vistrails for loading a vistrail and dump the tree to a file and returns a tuple containing a boolean saying if it was successful or not and the latex code. """ cmd_line = build_vistrails_cmd_line(path_to_vistrails, host, db_name, vt_id, None, port, path_to_figures, pdf, graph=True) if not os.path.exists(path_to_figures): os.makedirs(path_to_figures) if build_always or not path_exists_and_not_empty(path_to_figures): result = os.system(cmd_line) if result != 0: os.rmdir(path_to_figures) msg = "See vistrails.log for more information." return (False, generate_latex_error(msg)) return (True, generate_latex(host, db_name, vt_id, None, port, '', False, False, path_to_figures, graphics_options)) def get_wf_graph_locally(path_to_vistrails, host, db_name, vt_id, version, port, path_to_figures, build_always=False, tag='', pdf=False): """run_vistrails_locally(path_to_vistrails: str, host: str, db_name: str, vt_id: str, version: str, port: str, path_to_figures: str,build_always: bool, tag: str, pdf:bool) -> tuple(bool, str) Run vistrails for loading a workflow and dump the graph to a file and returns a tuple containing a boolean saying if it was successful or not and the latex code. """ cmd_line = build_vistrails_cmd_line(path_to_vistrails, host, db_name, vt_id, version, port, path_to_figures, pdf, graph) if not os.path.exists(path_to_figures): os.makedirs(path_to_figures) result = os.system(cmd_line) if result != 0: os.rmdir(path_to_figures) msg = "See vistrails.log for more information." return (False, generate_latex_error(msg)) else: if build_always or not path_exists_and_not_empty(path_to_figures): result = os.system(cmd_line) if result != 0: os.rmdir(path_to_figures) msg = "See vistrails.log for more information." return (False, generate_latex_error(msg)) return (True, generate_latex(host, db_name, vt_id, version, port, tag, execute, showspreadsheetonly, path_to_figures, graphics_options)) def run_vistrails_remotely(path_to_vistrails, download_url, host, db_name, vt_id, | def run_vistrails_remotely(path_to_vistrails, host, db_name, vt_id, version, port, path_to_figures, build_always=False, tag='', execute=False, showspreadsheetonly=False, pdf=False): """run_vistrails_remotely(path_to_vistrails: str, host: str, db_name: str, vt_id: str, version: str, port: str, path_to_figures: str, build_always: bool, tag:str, execute: bool, showspreadsheetonly: bool, pdf: bool) -> tuple(bool, str) Run vistrails and returns a tuple containing a boolean saying if it was successful or not and the latex code. """ def download(url,filename): try: furl = urllib2.urlopen(url) f = file(filename,'wb') f.write(furl.read()) f.close() return True except: return False def download_as_text(url): try: furl = urllib2.urlopen(url) s = furl.read() return s except: return None if not path_exists_and_not_empty(path_to_figures) or build_always: if not os.path.exists(path_to_figures): os.makedirs(path_to_figures) if check_url(path_to_vistrails): website = "://".join(urlparse(path_to_vistrails)[:2]) request = "?host=%s&db=%s&vt=%s&version=%s&port=%s&pdf=%s" % (host, db_name, vt_id, urllib2.quote(version), port, pdf) url = path_to_vistrails + request #print url try: page = download_as_text(url) # we will look for images and other files embedded in the html re_imgs = re.compile('<img[^>]*/>') re_src = re.compile('(.*src=")([^"]*)"') re_a = re.compile('<a[^>]*>[^<]*</a>') re_href = re.compile('(.*href=")([^"]*)"') images = re_imgs.findall(page) files = re_a.findall(page) failed = False msg = '' if len(images) > 0 or len(files) > 0: for i in images: pngfile = re_src.match(i).groups()[1] if not check_url(pngfile): img = website + pngfile else: img = pngfile if not download(img, os.path.join(path_to_figures, os.path.basename(img))): msg += "Error when downloading image: %s. <return>" %\ img failed = True for f in files: otherfile = re_href.match(f).groups()[1] if not check_url(otherfile): filename = website + otherfile else: filename = otherfile if not download(filename, os.path.join(path_to_figures, os.path.basename(filename))): msg += "Error when downloading file: %s. <return>" %\ filename failed = True if not failed : return (True, generate_latex(host, db_name, vt_id, version, port, tag, execute, showspreadsheetonly, path_to_figures, graphics_options)) else: return (False, generate_latex_error(msg)) else: msg = "Web server returned: %s" % page return (False, generate_latex_error(msg)) except Exception, e: return (False, generate_latex_error(str(e))) else: msg = "Invalid url: %s" % path_to_vistrails return (False, generate_latex_error(msg)) else: return (True, generate_latex(host, db_name, vt_id, version, port, tag, execute, showspreadsheetonly, path_to_figures, graphics_options)) |
"""run_vistrails_remotely(path_to_vistrails: str, host: str, | """run_vistrails_remotely(path_to_vistrails: str, download_url: str host: str, | def run_vistrails_remotely(path_to_vistrails, host, db_name, vt_id, version, port, path_to_figures, build_always=False, tag='', execute=False, showspreadsheetonly=False, pdf=False): """run_vistrails_remotely(path_to_vistrails: str, host: str, db_name: str, vt_id: str, version: str, port: str, path_to_figures: str, build_always: bool, tag:str, execute: bool, showspreadsheetonly: bool, pdf: bool) -> tuple(bool, str) Run vistrails and returns a tuple containing a boolean saying if it was successful or not and the latex code. """ def download(url,filename): try: furl = urllib2.urlopen(url) f = file(filename,'wb') f.write(furl.read()) f.close() return True except: return False def download_as_text(url): try: furl = urllib2.urlopen(url) s = furl.read() return s except: return None if not path_exists_and_not_empty(path_to_figures) or build_always: if not os.path.exists(path_to_figures): os.makedirs(path_to_figures) if check_url(path_to_vistrails): website = "://".join(urlparse(path_to_vistrails)[:2]) request = "?host=%s&db=%s&vt=%s&version=%s&port=%s&pdf=%s" % (host, db_name, vt_id, urllib2.quote(version), port, pdf) url = path_to_vistrails + request #print url try: page = download_as_text(url) # we will look for images and other files embedded in the html re_imgs = re.compile('<img[^>]*/>') re_src = re.compile('(.*src=")([^"]*)"') re_a = re.compile('<a[^>]*>[^<]*</a>') re_href = re.compile('(.*href=")([^"]*)"') images = re_imgs.findall(page) files = re_a.findall(page) failed = False msg = '' if len(images) > 0 or len(files) > 0: for i in images: pngfile = re_src.match(i).groups()[1] if not check_url(pngfile): img = website + pngfile else: img = pngfile if not download(img, os.path.join(path_to_figures, os.path.basename(img))): msg += "Error when downloading image: %s. <return>" %\ img failed = True for f in files: otherfile = re_href.match(f).groups()[1] if not check_url(otherfile): filename = website + otherfile else: filename = otherfile if not download(filename, os.path.join(path_to_figures, os.path.basename(filename))): msg += "Error when downloading file: %s. <return>" %\ filename failed = True if not failed : return (True, generate_latex(host, db_name, vt_id, version, port, tag, execute, showspreadsheetonly, path_to_figures, graphics_options)) else: return (False, generate_latex_error(msg)) else: msg = "Web server returned: %s" % page return (False, generate_latex_error(msg)) except Exception, e: return (False, generate_latex_error(str(e))) else: msg = "Invalid url: %s" % path_to_vistrails return (False, generate_latex_error(msg)) else: return (True, generate_latex(host, db_name, vt_id, version, port, tag, execute, showspreadsheetonly, path_to_figures, graphics_options)) |
Run vistrails and returns a tuple containing a boolean saying if it was successful or not and the latex code. | Call vistrails remotely to execute a workflow and returns a tuple containing a boolean saying whether it was successful and the latex code. | def run_vistrails_remotely(path_to_vistrails, host, db_name, vt_id, version, port, path_to_figures, build_always=False, tag='', execute=False, showspreadsheetonly=False, pdf=False): """run_vistrails_remotely(path_to_vistrails: str, host: str, db_name: str, vt_id: str, version: str, port: str, path_to_figures: str, build_always: bool, tag:str, execute: bool, showspreadsheetonly: bool, pdf: bool) -> tuple(bool, str) Run vistrails and returns a tuple containing a boolean saying if it was successful or not and the latex code. """ def download(url,filename): try: furl = urllib2.urlopen(url) f = file(filename,'wb') f.write(furl.read()) f.close() return True except: return False def download_as_text(url): try: furl = urllib2.urlopen(url) s = furl.read() return s except: return None if not path_exists_and_not_empty(path_to_figures) or build_always: if not os.path.exists(path_to_figures): os.makedirs(path_to_figures) if check_url(path_to_vistrails): website = "://".join(urlparse(path_to_vistrails)[:2]) request = "?host=%s&db=%s&vt=%s&version=%s&port=%s&pdf=%s" % (host, db_name, vt_id, urllib2.quote(version), port, pdf) url = path_to_vistrails + request #print url try: page = download_as_text(url) # we will look for images and other files embedded in the html re_imgs = re.compile('<img[^>]*/>') re_src = re.compile('(.*src=")([^"]*)"') re_a = re.compile('<a[^>]*>[^<]*</a>') re_href = re.compile('(.*href=")([^"]*)"') images = re_imgs.findall(page) files = re_a.findall(page) failed = False msg = '' if len(images) > 0 or len(files) > 0: for i in images: pngfile = re_src.match(i).groups()[1] if not check_url(pngfile): img = website + pngfile else: img = pngfile if not download(img, os.path.join(path_to_figures, os.path.basename(img))): msg += "Error when downloading image: %s. <return>" %\ img failed = True for f in files: otherfile = re_href.match(f).groups()[1] if not check_url(otherfile): filename = website + otherfile else: filename = otherfile if not download(filename, os.path.join(path_to_figures, os.path.basename(filename))): msg += "Error when downloading file: %s. <return>" %\ filename failed = True if not failed : return (True, generate_latex(host, db_name, vt_id, version, port, tag, execute, showspreadsheetonly, path_to_figures, graphics_options)) else: return (False, generate_latex_error(msg)) else: msg = "Web server returned: %s" % page return (False, generate_latex_error(msg)) except Exception, e: return (False, generate_latex_error(str(e))) else: msg = "Invalid url: %s" % path_to_vistrails return (False, generate_latex_error(msg)) else: return (True, generate_latex(host, db_name, vt_id, version, port, tag, execute, showspreadsheetonly, path_to_figures, graphics_options)) |
def download(url,filename): try: furl = urllib2.urlopen(url) f = file(filename,'wb') f.write(furl.read()) f.close() return True except: return False def download_as_text(url): try: furl = urllib2.urlopen(url) s = furl.read() return s except: return None | log("run_vistrails_remotely") | def download(url,filename): try: furl = urllib2.urlopen(url) f = file(filename,'wb') f.write(furl.read()) f.close() return True except: return False |
try: page = download_as_text(url) re_imgs = re.compile('<img[^>]*/>') re_src = re.compile('(.*src=")([^"]*)"') re_a = re.compile('<a[^>]*>[^<]*</a>') re_href = re.compile('(.*href=")([^"]*)"') images = re_imgs.findall(page) files = re_a.findall(page) failed = False msg = '' if len(images) > 0 or len(files) > 0: for i in images: pngfile = re_src.match(i).groups()[1] if not check_url(pngfile): img = website + pngfile else: img = pngfile if not download(img, os.path.join(path_to_figures, os.path.basename(img))): msg += "Error when downloading image: %s. <return>" %\ img failed = True for f in files: otherfile = re_href.match(f).groups()[1] if not check_url(otherfile): filename = website + otherfile else: filename = otherfile if not download(filename, os.path.join(path_to_figures, os.path.basename(filename))): msg += "Error when downloading file: %s. <return>" %\ filename failed = True if not failed : return (True, generate_latex(host, db_name, vt_id, version, port, tag, execute, showspreadsheetonly, path_to_figures, graphics_options)) else: return (False, generate_latex_error(msg)) else: msg = "Web server returned: %s" % page return (False, generate_latex_error(msg)) | log("will download from: " + url) | def download_as_text(url): try: furl = urllib2.urlopen(url) s = furl.read() return s except: return None |
except Exception, e: return (False, generate_latex_error(str(e))) | (result, msg) = _download_content(website, url, path_to_figures) if result == True: log("success") return (result, generate_latex(download_url, host, db_name, vt_id, version, port, tag, execute, showspreadsheetonly, path_to_figures, graphics_options)) else: log("Error: " + msg) return (result, generate_latex_error(msg)) | def download_as_text(url): try: furl = urllib2.urlopen(url) s = furl.read() return s except: return None |
return (True, generate_latex(host, db_name, vt_id, version, port, tag, execute, | log("using cached files") return (True, generate_latex(download_url, host, db_name, vt_id, version, port, tag, execute, | def download_as_text(url): try: furl = urllib2.urlopen(url) s = furl.read() return s except: return None |
def get_vt_graph_remotely(path_to_vistrails, download_url, host, db_name, vt_id, port, path_to_figures, build_always=False, pdf=False): """get_vt_graph_remotely(path_to_vistrails: str, download_url: str, host: str, db_name: str, vt_id: str, port: str, path_to_figures: str, build_always: bool, pdf: bool) -> tuple(bool, str) Get the version tree image of a vistrail and returns a tuple containing a boolean saying whether it was successful and the latex code. """ log("get_vt_graph_remotely") if not path_exists_and_not_empty(path_to_figures) or build_always: if not os.path.exists(path_to_figures): os.makedirs(path_to_figures) if check_url(path_to_vistrails): website = "://".join(urlparse(path_to_vistrails)[:2]) request = "?host=%s&db=%s&vt=%s&port=%s&pdf=%s&showtree=True" % (host, db_name, vt_id, port, pdf) url = path_to_vistrails + request log("will download from: " + url) (result, msg) = _download_content(website, url, path_to_figures) if result == True: log("success") return (result, generate_latex(download_url, host, db_name, vt_id, None, port, '', False, False, path_to_figures, graphics_options)) else: log("Error: " + msg) return (result, generate_latex_error(msg)) else: msg = "Invalid url: %s" % path_to_vistrails log("Error: " + msg) return (False, generate_latex_error(msg)) else: log("using cached files") return (True, generate_latex(download_url, host, db_name, vt_id, None, port, '', False, False, path_to_figures, graphics_options)) def get_wf_graph_remotely(path_to_vistrails, download_url, host, db_name, vt_id, version, port, path_to_figures, build_always=False, tag='', pdf=False): """get_wf_graph_remotely(path_to_vistrails: str, download_url:str, host: str, db_name: str, vt_id: str, version: str, port: str, path_to_figures: str, build_always: bool, tag:str, pdf: bool) -> tuple(bool, str) Get the graph of a workflow and returns a tuple containing a boolean saying whether it was successful and the latex code. """ log("get_wf_graph_remotely") if not path_exists_and_not_empty(path_to_figures) or build_always: if not os.path.exists(path_to_figures): os.makedirs(path_to_figures) if check_url(path_to_vistrails): website = "://".join(urlparse(path_to_vistrails)[:2]) request = "?host=%s&db=%s&vt=%s&version=%s&port=%s&pdf=%s&showworkflow=True" % (host, db_name, vt_id, urllib2.quote(version), port, pdf) url = path_to_vistrails + request log("will download from: " + url) (result, msg) = _download_content(website, url, path_to_figures) if result == True: log("success") return (result, generate_latex(download_url, host, db_name, vt_id, version, port, tag, False, False, path_to_figures, graphics_options)) else: log("Error: " + msg) return (result, generate_latex_error(msg)) else: msg = "Invalid url: %s" % path_to_vistrails log("Error: " + msg) return (False, generate_latex_error(msg)) else: log("using cached files") return (True, generate_latex(download_url, host, db_name, vt_id, version, port, tag, False, False, path_to_figures, graphics_options)) | def download_as_text(url): try: furl = urllib2.urlopen(url) s = furl.read() return s except: return None |
|
if tree: path_to_figures = os.path.join("vistrails_images", "%s_%s_%s_%s_%s" % (host, db_name, port, vt_id, out_type)) elif wgraph: path_to_figures = os.path.join("vistrails_images", "%s_%s_%s_%s_%s_%s_graph" % (host, db_name, port, vt_id, version, out_type)) | def check_url(url): try: p = urlparse(url) h = HTTP(p[1]) h.putrequest('HEAD', p[2]) h.endheaders() if h.getreply()[0] == 200: return True else: return False except: return False |
|
result, latex = run_vistrails_locally(path_to_vistrails, host, db_name, vt_id, version, port, path_to_figures, build_always, version_tag, execute, showspreadsheetonly,pdf) | if tree: result, latex = get_vt_graph_locally(path_to_vistrails, host, db_name, vt_id, port, path_to_figures, build_always, pdf) elif wgraph: result, latex = get_wf_graph_locally(path_to_vistrails, host, db_name, vt_id, version, port, path_to_figures, version_tag, pdf) else: result, latex = run_vistrails_locally(path_to_vistrails, host, db_name, vt_id, version, port, path_to_figures, build_always, version_tag, execute, showspreadsheetonly,pdf) | def check_url(url): try: p = urlparse(url) h = HTTP(p[1]) h.putrequest('HEAD', p[2]) h.endheaders() if h.getreply()[0] == 200: return True else: return False except: return False |
result, latex = run_vistrails_remotely(path_to_vistrails, host, db_name, vt_id, version, port, path_to_figures, build_always, version_tag, execute, showspreadsheetonly,pdf) | if tree: result, latex = get_vt_graph_remotely(path_to_vistrails, download_url, host, db_name, vt_id, port, path_to_figures, build_always, pdf) elif wgraph: result, latex = get_wf_graph_remotely(path_to_vistrails, download_url, host, db_name, vt_id, version, port, path_to_figures, build_always,version_tag, pdf) else: result, latex = run_vistrails_remotely(path_to_vistrails, download_url, host, db_name, vt_id, version, port, path_to_figures, build_always, version_tag, execute, showspreadsheetonly,pdf) | def check_url(url): try: p = urlparse(url) h = HTTP(p[1]) h.putrequest('HEAD', p[2]) h.endheaders() if h.getreply()[0] == 200: return True else: return False except: return False |
"%s is not a valid url nor a valid path to vistrails.py" %\ (path_to_vistrails)) | generate_latex_error("%s is not a valid url nor a valid path to vistrails.py" %\ (path_to_vistrails))) | def check_url(url): try: p = urlparse(url) h = HTTP(p[1]) h.putrequest('HEAD', p[2]) h.endheaders() if h.getreply()[0] == 200: return True else: return False except: return False |
reg.get_descriptor_by_name('edu.utah.sci.vistrails.persistence.exp', | reg.get_descriptor_by_name('edu.utah.sci.vistrails.persistence', | def set_values(self): from core.modules.module_registry import get_module_registry reg = get_module_registry() PersistentRef = \ reg.get_descriptor_by_name('edu.utah.sci.vistrails.persistence.exp', 'PersistentRef').module |
reg.get_descriptor_by_name('edu.utah.sci.vistrails.persistence.exp', | reg.get_descriptor_by_name('edu.utah.sci.vistrails.persistence', | def get_values(self): from core.modules.module_registry import get_module_registry reg = get_module_registry() PersistentRef = \ reg.get_descriptor_by_name('edu.utah.sci.vistrails.persistence.exp', 'PersistentRef').module |
'vistrails_1_3.log') | 'vistrails_%s.log'%(get_version())) | def setupLogFile(self): if not self.temp_configuration.check('logFile'): s = os.path.join(self.temp_configuration.dotVistrails, 'vistrails_1_3.log') self.temp_configuration.logFile = s if not self.configuration.check('logFile'): # if this was not set before, it should point to the # value in temp_configuration s = os.path.join(self.temp_configuration.dotVistrails, 'vistrails_1_3.log') self.configuration.logFile = s if not os.path.lexists(self.temp_configuration.dotVistrails): self.create_default_directory() debug.DebugPrint.getInstance().set_logfile(self.temp_configuration.logFile) |
zipcmd = os.path.join(cur_dir,'zip.exe') | zipcmd = os.path.join(os.getcwd(),'zip.exe') | def save_vistrail_bundle_to_zip_xml(save_bundle, filename, vt_save_dir=None, version=None): """save_vistrail_bundle_to_zip_xml(save_bundle: SaveBundle, filename: str, vt_save_dir: str, version: str) -> (save_bundle: SaveBundle, vt_save_dir: str) save_bundle: a SaveBundle object containing vistrail data to save filename: filename to save to vt_save_dir: directory storing any previous files Generates a zip compressed version of vistrail. It raises an Exception if there was an error. """ core.requirements.require_executable('zip') if save_bundle.vistrail is None: raise VistrailsDBException('save_vistrail_bundle_to_zip_xml failed, ' 'bundle does not contain a vistrail') if not vt_save_dir: vt_save_dir = tempfile.mkdtemp(prefix='vt_save') # saving zip files flat so we'll do without this dir for now # abstraction_dir = os.path.join(vt_save_dir, 'abstractions') thumbnail_dir = os.path.join(vt_save_dir, 'thumbs') # Save Vistrail xml_fname = os.path.join(vt_save_dir, 'vistrail') save_vistrail_to_xml(save_bundle.vistrail, xml_fname, version) # Save Log if save_bundle.vistrail.db_log_filename is not None: xml_fname = os.path.join(vt_save_dir, 'log') if save_bundle.vistrail.db_log_filename != xml_fname: shutil.copyfile(save_bundle.vistrail.db_log_filename, xml_fname) save_bundle.vistrail.db_log_filename = xml_fname if save_bundle.log is not None: xml_fname = os.path.join(vt_save_dir, 'log') save_log_to_xml(save_bundle.log, xml_fname, version, True) save_bundle.vistrail.db_log_filename = xml_fname # Save Abstractions saved_abstractions = [] for obj in save_bundle.abstractions: if type(obj) == type(""): # FIXME we should have an abstraction directory here instead # of the abstraction_ prefix... if not os.path.basename(obj).startswith('abstraction_'): obj_fname = 'abstraction_' + os.path.basename(obj) else: obj_fname = os.path.basename(obj) # xml_fname = os.path.join(abstraction_dir, obj_fname) xml_fname = os.path.join(vt_save_dir, obj_fname) saved_abstractions.append(xml_fname) # if not os.path.exists(abstraction_dir): # os.mkdir(abstraction_dir) # print "obj:", obj # print "xml_fname:", xml_fname if obj != xml_fname: # print 'copying %s -> %s' % (obj, xml_fname) try: shutil.copyfile(obj, xml_fname) except Exception, e: saved_abstractions.pop() debug.critical('copying %s -> %s failed: %s' % \ (obj, xml_fname, str(e))) else: raise VistrailsDBException('save_vistrail_bundle_to_zip_xml failed, ' 'abstraction list entry must be a filename') # Save Thumbnails saved_thumbnails = [] for obj in save_bundle.thumbnails: if type(obj) == type(""): obj_fname = os.path.basename(obj) png_fname = os.path.join(thumbnail_dir, obj_fname) saved_thumbnails.append(png_fname) if not os.path.exists(thumbnail_dir): os.mkdir(thumbnail_dir) #print 'copying %s -> %s' %(obj, png_fname) try: shutil.copyfile(obj, png_fname) except Exception, e: saved_thumbnails.pop() debug.warning('copying thumbnail %s -> %s failed: %s' % \ (obj, png_fname, str(e))) else: raise VistrailsDBException('save_vistrail_bundle_to_zip_xml failed, ' 'thumbnail list entry must be a filename') tmp_zip_dir = tempfile.mkdtemp(prefix='vt_zip') tmp_zip_file = os.path.join(tmp_zip_dir, "vt.zip") output = [] rel_vt_save_dir = os.path.split(vt_save_dir)[1] # on windows, we assume zip.exe is in the current directory when # running from the binary install zipcmd = 'zip' if systemType in ['Windows', 'Microsoft']: zipcmd = os.path.join(cur_dir,'zip.exe') if not os.path.exists(zipcmd): zipcmd = 'zip.exe' #assume zip is in path cmdline = [zipcmd, '-r', '-q', tmp_zip_file, '.'] try: #if we want that directories are also stored in the zip file # we need to run from the vt directory with Chdir(vt_save_dir): result = execute_cmdline(cmdline,output) #print result, output if result != 0 or len(output) != 0: for line in output: if line.find('deflated') == -1: raise VistrailsDBException(" ".join(output)) shutil.copyfile(tmp_zip_file, filename) finally: os.unlink(tmp_zip_file) os.rmdir(tmp_zip_dir) save_bundle = SaveBundle(save_bundle.bundle_type, save_bundle.vistrail, save_bundle.log, thumbnails=saved_thumbnails, abstractions=saved_abstractions) return (save_bundle, vt_save_dir) |
new_locator = ZIPFileLocator(fname).load() | new_locator = ZIPFileLocator(fname) | def merge_vt(self, host, port, db_name, user, new_vt_filepath, old_db_vt_id, is_local=True): """ Merge new_vt (new_vt_filepath) with current vt (old_db_vt_id) |
self.server_logger.info("get_vt_graph_png(%s, %d, %s, %d)" % (host, port, db_name, vt_id)) | self.server_logger.info("get_vt_graph_png(%s, %s, %s, %s)" % (host, port, db_name, vt_id)) | def get_vt_graph_png(self, host, port, db_name, vt_id, is_local=True): """get_vt_graph_png(host:str, port: str, db_name: str, vt_id:str) -> str Returns the relative url of the generated image """ |
port=port, | port=int(port), | def get_vt_graph_png(self, host, port, db_name, vt_id, is_local=True): """get_vt_graph_png(host:str, port: str, db_name: str, vt_id:str) -> str Returns the relative url of the generated image """ |
def get_vt_graph_pdf(self, host, port, db_name, vt_id, is_local=True): """get_vt_graph_pdf(host:str, port: str, db_name: str, vt_id:str) -> str Returns the relative url of the generated image """ self.server_logger.info("get_vt_graph_pdf(%s, %s, %s, %s)" % (host, port, db_name, vt_id)) try: vt_id = long(vt_id) subdir = 'vistrails' filepath = os.path.join(media_dir, 'graphs', subdir) base_fname = "graph_%s.pdf" % (vt_id) filename = os.path.join(filepath,base_fname) if ((not os.path.exists(filepath) or os.path.exists(filepath) and not os.path.exists(filename)) and self.proxies_queue is not None): proxy = self.proxies_queue.get() try: self.server_logger.info("Sending request to %s" % proxy) result = proxy.get_vt_graph_pdf(host, port, db_name, vt_id, is_local) self.proxies_queue.put(proxy) self.server_logger.info("returning %s" % result) return result except Exception, e: self.server_logger.error(str(e)) return (str(e), 0) if not os.path.exists(filepath): os.mkdir(filepath) if not os.path.exists(filename): locator = DBLocator(host=host, port=int(port), database=db_name, user=db_read_user, passwd=db_read_pass, obj_id=vt_id, obj_type=None, connection_id=None) (v, abstractions , thumbnails) = io.load_vistrail(locator) controller = VistrailController() controller.set_vistrail(v, locator, abstractions, thumbnails) from gui.version_view import QVersionTreeView version_view = QVersionTreeView() version_view.scene().setupScene(controller) version_view.scene().saveToPDF(filename) del version_view else: self.server_logger.info("Found cached pdf: %s" % filename) if is_local: return (os.path.join(subdir,base_fname), 1) else: f = open(filename, 'rb') contents = f.read() f.close() return (xmlrpclib.Binary(contents), 1) except Exception, e: self.server_logger.error("Error when saving pdf: %s" % str(e)) return (str(e), 0) | def get_vt_graph_png(self, host, port, db_name, vt_id, is_local=True): """get_vt_graph_png(host:str, port: str, db_name: str, vt_id:str) -> str Returns the relative url of the generated image """ |
|
port.find_port_types() | def remap(): port_type = \ PortSpec.port_type_map.inverse[port.type] pspec = reg.get_port_spec(m.package, m.name, m.namespace, port.name, port_type) all_ports = reg.all_source_ports(d) # print "pspec", pspec # First try to find a perfect match for (klass_name, ports) in all_ports: for candidate_port in ports: if (candidate_port.type_equals(pspec) and candidate_port.name == port.name): #print "found perfect match" port.spec = candidate_port port.find_port_types() return True # Now try to find an imperfect one for (klass_name, ports) in all_ports: for candidate_port in ports: print candidate_port if candidate_port.type_equals(pspec): #print "found imperfect match" port.name = candidate_port.name port.spec = candidate_port port.find_port_types() return True return False |
|
port.find_port_types() | def remap(): port_type = \ PortSpec.port_type_map.inverse[port.type] pspec = reg.get_port_spec(m.package, m.name, m.namespace, port.name, port_type) |
|
self._port_type = port_type.lower() | self._port_type = port_type.lower() if port_type else None | def __init__(self, msg, module=None, port_name=None, port_type=None): Exception.__init__(self, msg) self._msg = msg self._module = module self._port_name = port_name self._port_type = port_type.lower() |
version=None, pdf=False, vt_tag='',parameters='', is_local=True): self.server_logger.info("Request: run_vistrail_from_db(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" % \ | version=None, pdf=False, vt_tag='', build_always=False, parameters='', is_local=True): self.server_logger.info("Request: run_vistrail_from_db(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" % \ | def run_from_db(self, host, port, db_name, vt_id, path_to_figures, version=None, pdf=False, vt_tag='',parameters='', is_local=True): self.server_logger.info("Request: run_vistrail_from_db(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" % \ (host, port, db_name, vt_id, path_to_figures, version, pdf, vt_tag, parameters, is_local)) |
vt_tag, parameters, is_local)) | vt_tag, build_always, parameters, is_local)) | def run_from_db(self, host, port, db_name, vt_id, path_to_figures, version=None, pdf=False, vt_tag='',parameters='', is_local=True): self.server_logger.info("Request: run_vistrail_from_db(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" % \ (host, port, db_name, vt_id, path_to_figures, version, pdf, vt_tag, parameters, is_local)) |
if (not self.path_exists_and_not_empty(path_to_figures) and self.proxies_queue is not None): | if ((not self.path_exists_and_not_empty(path_to_figures) or build_always) and self.proxies_queue is not None): | def run_from_db(self, host, port, db_name, vt_id, path_to_figures, version=None, pdf=False, vt_tag='',parameters='', is_local=True): self.server_logger.info("Request: run_vistrail_from_db(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" % \ (host, port, db_name, vt_id, path_to_figures, version, pdf, vt_tag, parameters, is_local)) |
parameters, is_local) | build_always, parameters, is_local) | def run_from_db(self, host, port, db_name, vt_id, path_to_figures, version=None, pdf=False, vt_tag='',parameters='', is_local=True): self.server_logger.info("Request: run_vistrail_from_db(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" % \ (host, port, db_name, vt_id, path_to_figures, version, pdf, vt_tag, parameters, is_local)) |
traceback.print_exc() | def run_from_db(self, host, port, db_name, vt_id, path_to_figures, version=None, pdf=False, vt_tag='',parameters=''): self.server_logger.info("Request: run_vistrail_from_db(%s,%s,%s,%s,%s,%s,%s,%s,%s)" % \ (host, port, db_name, vt_id, path_to_figures, version, pdf, vt_tag, parameters)) |
|
""" | def get_wf_datasets(self, host, port, db_name, vt_id, version): self.server_logger.info("Request: get_wf_datasets(%s,%s,%s,%s,%s)" % \ (host, port, db_name, vt_id, version)) try: locator = DBLocator(host=host, port=int(port), database=db_name, user=db_read_user, passwd=db_read_pass, obj_id=int(vt_id), obj_type=None, connection_id=None) |
|
""" | def index_workflow(self, host, port, db_name, vt_id, wf_info): self.server_logger.info("Request: index_workflow(%s,%s,%s,%s,%s)" % \ (host, port, db_name, vt_id, wf_info)) try: locator = DBLocator(host=host, port=int(port), database=db_name, user=db_read_user, passwd=db_read_pass, obj_id=int(vt_id), obj_type=None, connection_id=None) |
|
'\n '.join(str(e) for e in self._exception_set) | '\n '.join(line for e in self._exception_set for line in str(e).splitlines()) def get_exception_set(self): return self._exception_set | def __str__(self): return "Pipeline cannot be instantiated:\n " + \ '\n '.join(str(e) for e in self._exception_set) |
return True | return False | def versions_increasing(v1, v2): v1_list = v1.split('.') v2_list = v2.split('.') try: while len(v1_list) > 0 and len(v2_list) > 0: v1_num = int(v1_list.pop()) v2_num = int(v2_list.pop()) if v1_num < v2_num: return True elif v1_num > v2_num: return False if len(v1_list) < len(v2_list): return True elif len(v1_list) > len(v2_list): return False except ValueError: print "ERROR: cannot compare versions whose components " \ "are not integers" return True |
info = socket.getaddrinfo(socket.gethostname(), None) for i in info: if len(i[4][0]) <= 15: return i[4][0] else: | try: info = socket.getaddrinfo(socket.gethostname(), None) for i in info: if len(i[4][0]) <= 15: return i[4][0] else: return '0.0.0.0' except: | def current_ip(): """ current_ip() -> str Gets current IP address trying to avoid the IPv6 interface """ info = socket.getaddrinfo(socket.gethostname(), None) for i in info: if len(i[4][0]) <= 15: return i[4][0] else: return '0.0.0.0' |
_hash = self.hash() | def load(self, type, tmp_dir=None): self._hash = self.hash() if DBLocator.cache.has_key(self._hash): save_bundle = DBLocator.cache[self._hash] obj = save_bundle.get_primary_obj() ts = io.get_db_object_modification_time(self.get_connection(), obj.db_id, obj.vtType) ts = datetime(*strptime(str(ts).strip(), '%Y-%m-%d %H:%M:%S')[0:6]) #print DBLocator.cache_timestamps[self._hash],ts if DBLocator.cache_timestamps[self._hash] == ts: # If thumbnail cache was cleared, get thumbs from db if tmp_dir is not None: for absfname in save_bundle.thumbnails: if not os.path.isfile(absfname): save_bundle.thumbnails = io.open_thumbnails_from_db(self.get_connection(), type, self.obj_id, tmp_dir) break return save_bundle connection = self.get_connection() save_bundle = io.open_bundle_from_db(type, connection, self.obj_id, tmp_dir) primary_obj = save_bundle.get_primary_obj() self._name = primary_obj.db_name for obj in save_bundle.get_db_objs(): obj.locator = self #The problem of computing the hash again is that will always be #different from what the locator is created because we don't know #the name of the locator before it is loaded. So we will use the #one that was created before loading the vistrail #_hash = self.hash() DBLocator.cache[self._hash] = save_bundle.do_copy() DBLocator.cache_timestamps[self._hash] = primary_obj.db_last_modified return save_bundle |
|
if self._hash != '': self_hash = self.hash() | self_hash = self.hash() | def save(self, save_bundle, do_copy=False, version=None): connection = self.get_connection() for obj in save_bundle.get_db_objs(): obj.db_name = self._name save_bundle = io.save_bundle_to_db(save_bundle, connection, do_copy, version) primary_obj = save_bundle.get_primary_obj() self._obj_id = primary_obj.db_id self._obj_type = primary_obj.vtType for obj in save_bundle.get_db_objs(): obj.locator = self #update the cache with a copy of the new bundle if self._hash != '': self_hash = self.hash() DBLocator.cache[self._hash] = save_bundle.do_copy() DBLocator.cache_timestamps[self._hash] = primary_obj.db_last_modified return save_bundle |
childnode = ElementTree.SubElement(node,'name') childnode.text = str(self._name) | def to_xml(self, node=None): """to_xml(node: ElementTree.Element) -> ElementTree.Element Convert this object to an XML representation. """ if node is None: node = ElementTree.Element('locator') |
|
for child in node.getchildren(): if child.tag == 'name': name = str(child.text).strip(" \n\t") return DBLocator(host, port, database, user, passwd, name, vt_id, None) return None return None | return DBLocator(host, port, database, user, passwd, name, vt_id, None) else: return None | def bool_conv(x): s = str(x).upper() if s == 'TRUE': return True if s == 'FALSE': return False |
self.perm_download = QtGui.QCheckBox("download") | def __init__(self, parent, status_bar, dialog): QtGui.QWidget.__init__(self, parent) self._status_bar = status_bar self.dialog = dialog |
|
top_layout.addWidget(self.perm_download) | self.perm_view.setEnabled(True) | def __init__(self, parent, status_bar, dialog): QtGui.QWidget.__init__(self, parent) self._status_bar = status_bar self.dialog = dialog |
vistrail_link = "%s/vistrails/details/%s" % \ | vt_id_url = "%s/vistrails/get_id/%s" % \ | def check_dependencies(self): """ determines if current VisTrail will be supported by the repository's VisTrail server """ |
self.loginUser = QtGui.QLineEdit(self.config.webRepositoryLogin) | self.dialog.loginUser = QtGui.QLineEdit(self.config.webRepositoryLogin) | def __init__(self, parent, status_bar, dialog): QtGui.QWidget.__init__(self, parent) self._status_bar = status_bar self.dialog = dialog |
self.loginUser = QtGui.QLineEdit("") self.loginUser.setFixedWidth(200) self.loginUser.setSizePolicy(QtGui.QSizePolicy.Fixed, | self.dialog.loginUser = QtGui.QLineEdit("") self.dialog.loginUser.setFixedWidth(200) self.dialog.loginUser.setSizePolicy(QtGui.QSizePolicy.Fixed, | def __init__(self, parent, status_bar, dialog): QtGui.QWidget.__init__(self, parent) self._status_bar = status_bar self.dialog = dialog |
base_layout.addWidget(self.loginUser) | base_layout.addWidget(self.dialog.loginUser) | def __init__(self, parent, status_bar, dialog): QtGui.QWidget.__init__(self, parent) self._status_bar = status_bar self.dialog = dialog |
self.loginUser.setEnabled(True) | self.dialog.loginUser.setEnabled(True) | def __init__(self, parent, status_bar, dialog): QtGui.QWidget.__init__(self, parent) self._status_bar = status_bar self.dialog = dialog |
self.loginUser.setEnabled(False) | self.dialog.loginUser.setEnabled(False) | def __init__(self, parent, status_bar, dialog): QtGui.QWidget.__init__(self, parent) self._status_bar = status_bar self.dialog = dialog |
params = urllib.urlencode({'username':self.loginUser.text(), | params = urllib.urlencode({'username':self.dialog.loginUser.text(), | def clicked_on_login(self): """ Attempts to log into web repository stores auth cookie for session """ from gui.application import VistrailsApplication |
self.loginUser.setEnabled(False) | self.dialog.loginUser.setEnabled(False) | def clicked_on_login(self): """ Attempts to log into web repository stores auth cookie for session """ from gui.application import VistrailsApplication |
self.config.webRepositoryLogin == self.loginUser.text(): | self.config.webRepositoryLogin == self.dialog.loginUser.text(): | def clicked_on_login(self): """ Attempts to log into web repository stores auth cookie for session """ from gui.application import VistrailsApplication |
self.config.webRepositoryLogin = str(self.loginUser.text()) | self.config.webRepositoryLogin = str(self.dialog.loginUser.text()) | def clicked_on_login(self): """ Attempts to log into web repository stores auth cookie for session """ from gui.application import VistrailsApplication |
self.loginUser.setEnabled(True) | self.dialog.loginUser.setEnabled(True) | def clicked_on_logout(self): """ Reset cookie, text fields and gui buttons """ self.loginUser.setEnabled(True) self.loginPassword.setEnabled(True) self._logout_button.setEnabled(False) self._login_button.setEnabled(True) self.saveLogin.setEnabled(True) self.dialog.cookiejar = None |
elements = parameters.split("&") | elements = parameters.split("&&") | def run_and_get_results(w_list, parameters='', workflow_info=None, update_vistrail=False, extra_info=None): """run_and_get_results(w_list: list of (locator, version), parameters: str, workflow_info:str, update_vistrail: boolean) Run all workflows in w_list, and returns an interpreter result object. version can be a tag name or a version id. """ elements = parameters.split("&") aliases = {} result = [] for locator, workflow in w_list: (v, abstractions , thumbnails) = load_vistrail(locator) controller = VistrailController() controller.set_vistrail(v, locator, abstractions, thumbnails) if type(workflow) == type("str"): version = v.get_version_number(workflow) elif type(workflow) in [ type(1), long]: version = workflow elif workflow is None: version = controller.get_latest_version_in_graph() else: msg = "Invalid version tag or number: %s" % workflow raise VistrailsInternalError(msg) controller.change_selected_version(version) for e in elements: pos = e.find("=") if pos != -1: key = e[:pos].strip() value = e[pos+1:].strip() if controller.current_pipeline.has_alias(key): aliases[key] = value if workflow_info is not None and controller.current_pipeline is not None: from gui.pipeline_view import QPipelineView pipeline_view = QPipelineView() pipeline_view.scene().setupScene(controller.current_pipeline) base_fname = "%s_%s_pipeline.pdf" % (locator.short_name, version) filename = os.path.join(workflow_info, base_fname) pipeline_view.scene().saveToPDF(filename) del pipeline_view base_fname = "%s_%s_pipeline.xml" % (locator.short_name, version) filename = os.path.join(workflow_info, base_fname) core.db.io.save_workflow(controller.current_pipeline, filename) if not update_vistrail: conf = get_vistrails_configuration() if conf.has('thumbs'): conf.thumbs.autoSave = False (results, _) = controller.execute_current_workflow(aliases, extra_info) run = results[0] run.workflow_info = (locator.name, version) run.pipeline = controller.current_pipeline #not sure if you need to add the abstractions back #but just to be safe if update_vistrail: controller.write_vistrail(locator) result.append(run) return result |
CurrentTheme.DEBUG_INFO_COLOR.name()) | CurrentTheme.DEBUG_INFO_COLOR.name() + ';background-color: | def __init__(self, parent = None): QtGui.QDialog.__init__(self, parent) core.debug.DebugPrint.getInstance().set_stream(debugStream(self.write)) self.setWindowTitle('VisTrails Messages') layout = QtGui.QVBoxLayout() self.setLayout(layout) |
CurrentTheme.DEBUG_WARNING_COLOR.name()) | CurrentTheme.DEBUG_WARNING_COLOR.name() + ';background-color: | def __init__(self, parent = None): QtGui.QDialog.__init__(self, parent) core.debug.DebugPrint.getInstance().set_stream(debugStream(self.write)) self.setWindowTitle('VisTrails Messages') layout = QtGui.QVBoxLayout() self.setLayout(layout) |
CurrentTheme.DEBUG_CRITICAL_COLOR.name()) | CurrentTheme.DEBUG_CRITICAL_COLOR.name() + ';background-color: | def __init__(self, parent = None): QtGui.QDialog.__init__(self, parent) core.debug.DebugPrint.getInstance().set_stream(debugStream(self.write)) self.setWindowTitle('VisTrails Messages') layout = QtGui.QVBoxLayout() self.setLayout(layout) |
visible == True | visible = True | def toggleType(self, s, visible): if visible == QtCore.Qt.Unchecked: visible = False elif visible == QtCore.Qt.Checked: visible == True for item in [self.list.item(i) for i in xrange(self.list.count())]: if str(item.data(32).toString()).split('\n')[0] == s: self.list.setItemHidden(item, not visible) |
pattern = re.compile(r"(^r[0-9]+ \| )(\S+ \| )", re.MULTILINE) | pattern = re.compile(r"(^\s*?def vistrails_revision\(\):.*?release = ['\"])([0-9]+?)(['\"].*?return release)", re.DOTALL | re.MULTILINE) |
|
expected_count = int(REVISION) - int(last_revision) | pattern = re.compile(r"(^\s*?def vistrails_revision\(\):.*?release = ['\"])([0-9]+?)(['\"].*?return release)", re.DOTALL | re.MULTILINE) |
|
if self.db_type and self.db_type.find(':') != -1: (self._identifier, name) = self.db_type.split(':', 1) if name.find('|') != -1: (self._namespace, self._type) = name.rsplit('|', 1) else: self._namespace = None self._type = name else: | if self.db_type: k = self.db_type.split(':', 2) else: k = [] if len(k) < 2: | def parse_db_type(self): if self.db_type and self.db_type.find(':') != -1: (self._identifier, name) = self.db_type.split(':', 1) if name.find('|') != -1: (self._namespace, self._type) = name.rsplit('|', 1) else: self._namespace = None self._type = name else: # FIXME don't hardcode this self._identifier = "edu.utah.sci.vistrails.basic" self._namespace = None self._type = self.db_type |
self.db_type = self._identifier + ':' + self._namespace + \ '|' + self._type else: self.db_type = self._identifier + ':' + self._type | type_list.append(self._namespace) self.db_type = ':'.join([self._identifier, self._type, self._namespace]) | def update_db_type(self): if not self._type: self.db_type = None else: if not self._identifier: # FIXME don't hardcode this self._identifier = "edu.utah.sci.vistrails.basic" if self._namespace: self.db_type = self._identifier + ':' + self._namespace + \ '|' + self._type else: self.db_type = self._identifier + ':' + self._type |
msg = "Web server returned: %s" % page | msg = "url: '%s' \n returned: %s" % (url,page.strip()) | def _download_content(url, request, path_to_figures): """_download_images(url:string, request:string, path_to_figures:string) -> (Boolean, message) Downloads all images and pdf files listed in url and saves them to path_to_figures """ website = url url = request try: page = download_as_text(url) # we will look for images and other files embedded in the html re_imgs = re.compile('<img[^>]*/>') re_src = re.compile('(.*src=")([^"]*)"') re_a = re.compile('<a[^>]*>[^<]*</a>') re_href = re.compile('(.*href=")([^"]*)"') images = re_imgs.findall(page) files = re_a.findall(page) failed = False msg = '' if len(images) > 0 or len(files) > 0: for i in images: pngfile = re_src.match(i).groups()[1] if not check_url(pngfile): img = website + pngfile else: img = pngfile if not download(img, os.path.join(path_to_figures, os.path.basename(img))): msg += "Error when downloading image: %s. <return>" %img failed = True for f in files: otherfile = re_href.match(f).groups()[1] if not check_url(otherfile): filename = website + otherfile else: filename = otherfile if not download(filename, os.path.join(path_to_figures, os.path.basename(filename))): msg += "Error when downloading file: %s. <return>"%filename failed = True if not failed : return (True, "") else: return (False, msg) else: msg = "Web server returned: %s" % page return (False, msg) except Exception, e: return (False, str(e)) |
}{vistrails}""" % error_msg | }{}""" % error_msg | def generate_latex_error(error_msg): """ generate_latex_error(error_msg: str) -> str this generates a piece of latex code with an error message. """ s = """\\PackageError{vistrails}{ An error occurred when executing vistrails. \\MessageBreak |
if use_filename and os.path.isfile(str(data[0])): | if use_filename: if os.path.isfile(str(data[0])): | def _parse_vtinfo(self, info, use_filename=True): name = None version = None if use_filename and os.path.isfile(info): name = info else: data = info.split(":") if len(data) >= 2: if use_filename and os.path.isfile(str(data[0])): name = str(data[0]) elif not use_filename: name = str(data[0]) # will try to convert version to int # if it fails, it's a tag name try: #maybe a tag name contains ':' in its name #so we need to bring it back together rest = ":".join(data[1:]) version = int(rest) except ValueError: version = str(rest) elif len(data) == 1: if use_filename and os.path.isfile(str(data[0])): name = str(data[0]) elif not use_filename: name = str(data[0]) return (name, version) |
url = self.getInputFromPort('url') | url = self.getInputFromPort("url") self._parse_url(url) | def is_cacheable(self): self.checkInputPort('url') url = self.getInputFromPort('url') local_filename = self._local_filename(url) # If file is not in cache, then we must re-run if not self._file_is_in_local_cache(local_filename): return False conn = httplib.HTTPConnection(self.host) try: conn.request("GET", self.filename) except socket.gaierror, e: # We could not get to the net, but file exists in local # cache, so we'll simply reuse it return True response = conn.getresponse() mod_header = response.msg.getheader('last-modified') if not mod_header: # server did not return a last-modified, assume cannot cache return False if self._is_outdated(mod_header, local_filename): return False return True |
if not self._file_is_in_local_cache(local_filename): return False conn = httplib.HTTPConnection(self.host) try: conn.request("GET", self.filename) except socket.gaierror, e: return True response = conn.getresponse() mod_header = response.msg.getheader('last-modified') if not mod_header: return False if self._is_outdated(mod_header, local_filename): return False return True | return self._file_is_in_local_cache(local_filename) | def is_cacheable(self): self.checkInputPort('url') url = self.getInputFromPort('url') local_filename = self._local_filename(url) # If file is not in cache, then we must re-run if not self._file_is_in_local_cache(local_filename): return False conn = httplib.HTTPConnection(self.host) try: conn.request("GET", self.filename) except socket.gaierror, e: # We could not get to the net, but file exists in local # cache, so we'll simply reuse it return True response = conn.getresponse() mod_header = response.msg.getheader('last-modified') if not mod_header: # server did not return a last-modified, assume cannot cache return False if self._is_outdated(mod_header, local_filename): return False return True |
conn = httplib.HTTPConnection(self.host) | opener = urllib2.build_opener() | def compute(self): self.checkInputPort('url') url = self.getInputFromPort("url") self._parse_url(url) conn = httplib.HTTPConnection(self.host) local_filename = self._local_filename(url) self.setResult("local_filename", local_filename) try: conn.request("GET", self.filename) except socket.gaierror, e: if self._file_is_in_local_cache(local_filename): debug.warning(('A network error occurred. HTTPFile will use' ' cached version of file')) result = core.modules.basic_modules.File() result.name = local_filename self.setResult("file", result) else: raise ModuleError(self, e[1]) else: response = conn.getresponse() mod_header = response.msg.getheader('last-modified') result = core.modules.basic_modules.File() result.name = local_filename if (not self._file_is_in_local_cache(local_filename) or not mod_header or self._is_outdated(mod_header, local_filename)): try: urllib.urlretrieve(url, local_filename) except IOError, e: raise ModuleError(self, ("Invalid URL: %s" % e)) except: raise ModuleError(self, ("Could not create local file '%s'" % local_filename)) conn.close() self.setResult("file", result) |
conn.request("GET", self.filename) except socket.gaierror, e: | request = urllib2.Request(url) except (socket.gaierror, socket.error), e: | def compute(self): self.checkInputPort('url') url = self.getInputFromPort("url") self._parse_url(url) conn = httplib.HTTPConnection(self.host) local_filename = self._local_filename(url) self.setResult("local_filename", local_filename) try: conn.request("GET", self.filename) except socket.gaierror, e: if self._file_is_in_local_cache(local_filename): debug.warning(('A network error occurred. HTTPFile will use' ' cached version of file')) result = core.modules.basic_modules.File() result.name = local_filename self.setResult("file", result) else: raise ModuleError(self, e[1]) else: response = conn.getresponse() mod_header = response.msg.getheader('last-modified') result = core.modules.basic_modules.File() result.name = local_filename if (not self._file_is_in_local_cache(local_filename) or not mod_header or self._is_outdated(mod_header, local_filename)): try: urllib.urlretrieve(url, local_filename) except IOError, e: raise ModuleError(self, ("Invalid URL: %s" % e)) except: raise ModuleError(self, ("Could not create local file '%s'" % local_filename)) conn.close() self.setResult("file", result) |
response = conn.getresponse() mod_header = response.msg.getheader('last-modified') | f1 = opener.open(url) mod_header = f1.info().getheader('last-modified') | def compute(self): self.checkInputPort('url') url = self.getInputFromPort("url") self._parse_url(url) conn = httplib.HTTPConnection(self.host) local_filename = self._local_filename(url) self.setResult("local_filename", local_filename) try: conn.request("GET", self.filename) except socket.gaierror, e: if self._file_is_in_local_cache(local_filename): debug.warning(('A network error occurred. HTTPFile will use' ' cached version of file')) result = core.modules.basic_modules.File() result.name = local_filename self.setResult("file", result) else: raise ModuleError(self, e[1]) else: response = conn.getresponse() mod_header = response.msg.getheader('last-modified') result = core.modules.basic_modules.File() result.name = local_filename if (not self._file_is_in_local_cache(local_filename) or not mod_header or self._is_outdated(mod_header, local_filename)): try: urllib.urlretrieve(url, local_filename) except IOError, e: raise ModuleError(self, ("Invalid URL: %s" % e)) except: raise ModuleError(self, ("Could not create local file '%s'" % local_filename)) conn.close() self.setResult("file", result) |
urllib.urlretrieve(url, local_filename) | mode = 'w' f2 = open(local_filename, mode) f2.write(f1.read()) f2.close() f1.close() | def compute(self): self.checkInputPort('url') url = self.getInputFromPort("url") self._parse_url(url) conn = httplib.HTTPConnection(self.host) local_filename = self._local_filename(url) self.setResult("local_filename", local_filename) try: conn.request("GET", self.filename) except socket.gaierror, e: if self._file_is_in_local_cache(local_filename): debug.warning(('A network error occurred. HTTPFile will use' ' cached version of file')) result = core.modules.basic_modules.File() result.name = local_filename self.setResult("file", result) else: raise ModuleError(self, e[1]) else: response = conn.getresponse() mod_header = response.msg.getheader('last-modified') result = core.modules.basic_modules.File() result.name = local_filename if (not self._file_is_in_local_cache(local_filename) or not mod_header or self._is_outdated(mod_header, local_filename)): try: urllib.urlretrieve(url, local_filename) except IOError, e: raise ModuleError(self, ("Invalid URL: %s" % e)) except: raise ModuleError(self, ("Could not create local file '%s'" % local_filename)) conn.close() self.setResult("file", result) |
conn.close() | result.name = local_filename | def compute(self): self.checkInputPort('url') url = self.getInputFromPort("url") self._parse_url(url) conn = httplib.HTTPConnection(self.host) local_filename = self._local_filename(url) self.setResult("local_filename", local_filename) try: conn.request("GET", self.filename) except socket.gaierror, e: if self._file_is_in_local_cache(local_filename): debug.warning(('A network error occurred. HTTPFile will use' ' cached version of file')) result = core.modules.basic_modules.File() result.name = local_filename self.setResult("file", result) else: raise ModuleError(self, e[1]) else: response = conn.getresponse() mod_header = response.msg.getheader('last-modified') result = core.modules.basic_modules.File() result.name = local_filename if (not self._file_is_in_local_cache(local_filename) or not mod_header or self._is_outdated(mod_header, local_filename)): try: urllib.urlretrieve(url, local_filename) except IOError, e: raise ModuleError(self, ("Invalid URL: %s" % e)) except: raise ModuleError(self, ("Could not create local file '%s'" % local_filename)) conn.close() self.setResult("file", result) |
remote_time = datetime.datetime.strptime(remoteHeader, "%a, %d %b %Y %H:%M:%S %Z") | try: remote_time = datetime.datetime.strptime(remoteHeader, "%a, %d %b %Y %H:%M:%S %Z") except: remote_time = datetime.datetime.strptime(remoteHeader, "%a, %d %B %Y %H:%M:%S %Z") | def _is_outdated(self, remoteHeader, localFile): """Checks whether local file is outdated.""" local_time = \ datetime.datetime.utcfromtimestamp(os.path.getmtime(localFile)) remote_time = datetime.datetime.strptime(remoteHeader, "%a, %d %b %Y %H:%M:%S %Z") return remote_time > local_time |
def mouseReleaseEvent(self, e): """mousePressEvent(e) -> None Keep the cursor after the last prompt. """ if e.button() == QtCore.Qt.LeftButton: self.copy() cursor = self.textCursor() cursor.movePosition(QtGui.QTextCursor.End) self.setTextCursor(cursor) return | def mouseReleaseEvent(self, e): """mousePressEvent(e) -> None Keep the cursor after the last prompt. """ if e.button() == QtCore.Qt.LeftButton: # copy selection to clipboard self.copy() cursor = self.textCursor() cursor.movePosition(QtGui.QTextCursor.End) self.setTextCursor(cursor) return |
|
except MissingDependency, e: | except self._current_package.MissingDependency, e: | def enable_current_package(self): av = self._available_packages_list inst = self._enabled_packages_list item = av.currentItem() pos = av.indexFromItem(item).row() codepath = str(item.text()) pm = get_package_manager() |
str(e), QtGuiQMessageBox.Ok, self) | str(e), QtGui.QMessageBox.Ok, self) | def enable_current_package(self): av = self._available_packages_list inst = self._enabled_packages_list item = av.currentItem() pos = av.indexFromItem(item).row() codepath = str(item.text()) pm = get_package_manager() |
""" dumpToFile() -> None | """ dumpToFile(filename: str, dump_as_pdf: bool) -> None | def dumpToFile(self, filename): """ dumpToFile() -> None Dumps itself as an image to a file, calling grabWindowPixmap """ pixmap = self.grabWindowPixmap() pixmap.save(filename,"PNG") |
pixmap = self.grabWindowPixmap() pixmap.save(filename,"PNG") | if not dump_as_pdf: pixmap = self.grabWindowPixmap() pixmap.save(filename,"PNG") | def dumpToFile(self, filename): """ dumpToFile() -> None Dumps itself as an image to a file, calling grabWindowPixmap """ pixmap = self.grabWindowPixmap() pixmap.save(filename,"PNG") |
pixmap = self.grabWindowPixmap() size = pixmap.size() | def saveToPDF(self, filename): printer = QtGui.QPrinter() printer.setOutputFormat(QtGui.QPrinter.PdfFormat) printer.setOutputFileName(filename) painter = QtGui.QPainter() painter.begin(printer) rect = painter.viewport() pixmap = self.grabWindowPixmap() size = pixmap.size() size.scale(rect.size(), QtCore.Qt.KeepAspectRatio) painter.setViewport(rect.x(), rect.y(), size.width(), size.height()) painter.setWindow(pixmap.rect()) painter.drawPixmap(0, 0, pixmap) painter.end() |
|
def create_dict(modules, ns, m, mdesc): md = {} if len(ns) == 0: d = {'_module_desc': mdesc, '_package': pkg,} modules[m] = type('module', (vistrails_module,), d) else: if ns[0] in modules: md = create_dict(modules[ns[0]], ns[1:], m, mdesc) else: md = create_dict(md, ns[1:], m, mdesc) modules[ns[0]] = md return modules def create_namespace_path(root, modules): for k,v in modules.iteritems(): if type(v) == type({}): d = create_namespace_path(k,v) modules[k] = d if root is not None: modules['_package'] = pkg return type(root, (object,), modules)() else: return modules | def load_package(self, pkg_name): reg = core.modules.module_registry.get_module_registry() package = reg.get_package_by_name(pkg_name) |
Subsets and Splits