def register_algorithm(self): storage = QSAlgorithmSource(config) existing_folders = [tup[0] for tup in Session.query(ReprocessConfig.original_folder).all()] errors = dict() src_dir = self.form_result['src_dir'] if src_dir in existing_folders: errors['src_dir'] = 'This algorithm has already been registered.' elif not storage.source_path_exists(src_dir): errors['src_dir'] = 'This algorithm is not accessible in the file system.' if self.form_result['peak_detection_version'] == (0,0): # this is arbitrary peak_detection_version = (0, QUANTASOFT_DIR_VERSION_RE.search(src_dir).group(1).split('_')[-1]) else: peak_detection_version = self.form_result['peak_detection_version'] if self.form_result['peak_quantitation_version'] == (0,0): peak_quantitation_version = (0, QUANTASOFT_DIR_VERSION_RE.search(src_dir).group(1).split('_')[-1]) else: peak_quantitation_version = self.form_result['peak_quantitation_version'] if errors: resp = self._algorithms_base() defaults = AlgorithmRegisterForm.from_python(self.form_result) return h.render_bootstrap_form(resp, defaults=defaults, errors=errors, error_formatters=h.tw_bootstrap_error_formatters) try: rp = ReprocessConfig(name=src_dir.split(os.path.sep)[0], code=self.form_result['code'], peak_detection_major=peak_detection_version[0], peak_detection_minor=peak_detection_version[1], peak_quant_major=peak_quantitation_version[0], peak_quant_minor=peak_quantitation_version[1], trigger_fixed_width=100, active=True, cluster_mode=ReprocessConfig.CLUSTER_MODE_CLUSTER, original_folder=src_dir) storage.add_reprocessor(src_dir, self.form_result['code']) Session.add(rp) Session.commit() session['flash'] = 'New algorithm reprocessor created.' session.save() return redirect(url(controller='product', action='algorithms')) except shutil.Error: session['flash'] = 'Could not copy source algorithm to destination.' session['flash_class'] = 'error' session.save() return redirect(url(controller='product', action='algorithms')) except IOError: session['flash'] = "Could not access the algorithm's file system." session['flash_class'] = 'error' session.save() return redirect(url(controller='product', action='algorithms'))
def _algorithms_base(self): storage = QSAlgorithmSource(config) existing_folders = [tup[0] for tup in Session.query(ReprocessConfig.original_folder).all()] new_folders = [folder for folder in storage.algorithm_folder_iter() if folder not in existing_folders] c.folder_opts = {'value': '', 'options': [(fld, fld.split('/')[0]) for fld in sorted(new_folders)]} return render('/product/algorithms/register.html')