def checkLabel(self, label, dlg): """ Validate catalog's label entered by the user. Arguments: label (str): Catalog's label. dlg (QDialog): Calling dialog. Returns: bool: *True* if label is valid; *False* otherwise. """ for internal in ['stable', 'testing']: if label == internal: title = translate("CatalogsView", "Error") message = translate("CatalogsView", "Label '{}' is reserved for internal use") Q.QMessageBox.critical(dlg, title, message.format(label)) return False items = self._items() items += [(i, CFG.get('Versions', i)) for i in CFG.options('Versions')] item = [i for i in items if i[0] == label] if item: title = translate("CatalogsView", "Error") message = translate("CatalogsView", "Label '{}' is already in use") Q.QMessageBox.critical(dlg, title, message.format(label)) return False return True
def _selectionChanged(self, command): """ Called when a command is selected in any category. Arguments: command (str): Command name. """ sender_view = self.sender() for view in self.panel.widgets(): if view != sender_view: view.clearSelection() if command: translation = translate_command(command) description = CATA.get_command_docstring(command) url = self.astergui().doc_url(command) if translation != command: text = italic(translation) + " ({})".format(bold(command)) else: text = bold(command) # add doc url if url: doc = href(image(CFG.rcfile("as_pic_help.png"), width=20, height=20), url) text += " " + doc text = preformat(text) if description: text = text + "<br/>" + description self.info.setText(text) else: self.info.setText("") self.updateButtonStatus()
def _updateState(self): """Update state and current title label.""" disabled = self.command() is None self.setDisabled(disabled) if not disabled: disabled = self.command().gettype(ConversionLevel.NoFail) is None self._name.setDisabled(disabled) txt = [] pview = self.currentParameterView() if pview is not None: txt = pview.path().names() ppath = None txt_list = [] tooltip = "" whats_this = "" while len(txt) > 0: name = txt.pop(0) if ppath is None: ppath = ParameterPath(self.command(), name=name) else: ppath = ppath.absolutePath(name) if ppath.isInSequence(): txt_list.append("[" + name + "]") elif get_cata_typeid(ppath.keyword()) in (IDS.simp, IDS.fact): # translate keyword kwtext = Options.translate_command(ppath.command().title, name) txt_list.append(kwtext) elif get_cata_typeid(ppath.keyword()) == IDS.command: # translate command translation = Options.translate_command(name) txt_list.append(translation) if translation != name: wttext = italic(translation) + " ({})".format(bold(name)) else: wttext = bold(name) tooltip = preformat(wttext) url = self.astergui().doc_url(name) if url: wttext += " " wttext += href( image(CFG.rcfile("as_pic_help.png"), width=20, height=20), url) wttext = preformat(wttext) docs = CATA.get_command_docstring(name) if docs: wttext += "<hr>" wttext += docs whats_this = wttext self.title.setTitle(txt_list) self.title.setToolTip(tooltip) self.title.setWhatsThis(whats_this)
def store(self): """Store user's catalogs to the Preferences file.""" items = self._items() cfg = Configuration(True) old_versions = cfg.options('Versions') \ if cfg.has_section('Versions') else [] new_versions = [i[0] for i in items] for label in old_versions: if label not in new_versions: cfg.remove_option('Versions', label) if CFG.has_option('Versions', label): CFG.remove_option('Versions', label) for label, path in items: if not cfg.has_section('Versions'): cfg.add_section('Versions') cfg.set('Versions', label, path) CFG.set('Versions', label, path) with open(cfg.userrc, 'w') as pref: cfg.write(pref)
def _read_dockeys(self): """Read the file containing the documentation keys.""" template = "clefs_docu_{0}" self._dockeys = {} for name in (self.version, "stable"): filename = CFG.rcfile(template.format(name)) if filename: for line in open(filename, "rb"): cmd, url = line.split(":", 1) self._dockeys[cmd] = url.strip() break
def create_command_job(servcfg, params, prof, stage): """Create the SalomeLauncher job.""" stagedir = stage.folder export = osp.join(stagedir, "export") fname = osp.join(stagedir, "launcher_script") rcdef = servcfg['rc_definition'] with open(fname, "wb") as fobj: fobj.write(os.linesep.join([ "#!/bin/bash", "{} shell -- as_run export", ""]).format(osp.join(rcdef.applipath, 'salome'))) os.chmod(fname, 0755) salome_job = salome.JobParameters() salome_job.job_name = to_str(prof["nomjob"][0]) salome_job.job_type = str("command") salome_job.wckey = to_str(CFG.get_wckey() or '') salome_job.job_file = to_str(fname) salome_job.result_directory = to_str(stagedir) salome_job.work_directory = str(new_directory(servcfg)) salome_job.maximum_duration = str(params['time']) # In files, do not take distant input databases dbtype, _ = prof.get_base('D') local_in_files = [i.path for i in prof.get_data() \ if not (i.host and i.type == dbtype)] local_in_files.append(export) salome_job.in_files = [to_str(i) for i in local_in_files] out_files = [osp.basename(i.path) for i in prof.get_result()] salome_job.out_files = [to_str(i).split(str(":"))[-1] for i in out_files] salome_job.resource_required = resource_parameters(params) # Now, profil methods from asrun are called (see profil.py) # Deepcopy of the profil object exported = prof.copy() # Loop study files for entry in exported.get_collection(): entry.host, entry.user, entry.passwd = '', '', '' entry.path = osp.basename(entry.path) # Warning: despite of the method's name, the entry # (i.e. asrun obj referencing a file) # is updated in place and not added, # because the entry object is already referenced # by the profil (see implementation in asrun/profil.py). # Updating the entry is required to update the export content exported.add(entry) exported.WriteExportTo(export) return salome_job
def version_path(version): """Return the path to a version. Arguments: version (str): Version label. Returns: str: Path to the version. """ try: version_path = CFG.get("Versions", version) except KeyError: version_path = version return version_path