def tearDown(self): from invenio import config config.CFG_TMPDIR = self.original_tmpdir if self.stdout: self.unredirect() from invenio.legacy.bibclassify import config as bconfig bconfig.set_global_level(self.log_level)
def setUp(self): """Initialize stuff""" from invenio import config self.original_tmpdir = config.CFG_TMPDIR config.CFG_TMPDIR = tempfile.gettempdir() self.oldstdout = sys.stdout self.oldstderr = sys.stderr self.stdout = None self.stderr = None self.taxonomy_name = "test" from invenio.legacy.bibclassify import config as bconfig self.log = bconfig.get_logger("bibclassify.tests") self.log_level = bconfig.logging_level bconfig.set_global_level(bconfig.logging.CRITICAL) self.app.extensions['registry']['classifierext.taxonomies'] = \ taxonomies_registry()
def setUp(self): """Initialize stuff.""" from invenio import config self.original_tmpdir = config.CFG_TMPDIR config.CFG_TMPDIR = tempfile.gettempdir() self.oldstdout = sys.stdout self.oldstderr = sys.stderr self.stdout = None self.stderr = None self.taxonomy_name = "test" from invenio.legacy.bibclassify import config as bconfig self.log = bconfig.get_logger("bibclassify.tests") self.log_level = bconfig.logging_level bconfig.set_global_level(bconfig.logging.CRITICAL) self.app.extensions['registry']['classifierext.taxonomies'] = \ taxonomies_registry()
def setUp(self): """Initialize stuff""" ## NOTE next time please make sure that you change global variables ## back to initial values in tearDown. Thank you!!! from invenio import config self.__CFG_TMPDIR = config.CFG_TMPDIR config.CFG_TMPDIR = tempfile.gettempdir() self.oldstdout = sys.stdout self.oldstderr = sys.stderr self.stdout = None self.stderr = None self.taxonomy_name = "test" from invenio.legacy.bibclassify import config as bconfig self.log = bconfig.get_logger("bibclassify.tests") self.log_level = bconfig.logging_level bconfig.set_global_level(bconfig.logging.CRITICAL) self.app.extensions['registry']['classifierext.taxonomies'] = \ taxonomies_registry()
def _read_options(options_string): """Read the options. Test if the specified values are consistent and populates the options dictionary.""" options = { "check_taxonomy": False, "spires": False, "output_limit": 20, "text_files": [], "taxonomy": "", "output_mode": "text", "match_mode": "full", "output_prefix": None, "rebuild_cache": False, "no_cache": False, "with_author_keywords": False, "extract_acronyms": False, "acronyms_file": "", "only_core_tags": False, } try: short_flags = "m:f:k:o:n:m:v:rsqhVde" long_flags = ["taxonomy=", "output-mode=", "verbose=", "spires", "keywords-number=", "matching-mode=", "help", "version", "file", "rebuild-cache", "no-limit", "no-cache", "check-taxonomy", "detect-author-keywords", "id:", "collection:", "modified:", "extract-acronyms", "acronyms-file=", "only-core-tags"] opts, args = getopt.gnu_getopt(options_string, short_flags, long_flags) except getopt.GetoptError as err1: print("Options problem: %s" % err1, file=sys.stderr) _display_help() # 2 dictionaries containing the option linked to its destination in the # options dictionary. with_argument = { "-k": "taxonomy", "--taxonomy": "taxonomy", "-o": "output_mode", "--output-mode": "output_mode", "-m": "match_mode", "--matching-mode": "match_mode", "-n": "output_limit", "--keywords-number": "output_limit", "--acronyms-file": "acronyms_file", } without_argument = { "-s": "spires", "--spires": "spires", "-q": "spires", "--rebuild-cache": "rebuild_cache", "--no-cache": "no_cache", "--check-taxonomy": "check_taxonomy", "--detect-author-keywords": "with_author_keywords", "-d": "with_author_keywords", "--extract-acronyms": "extract_acronyms", "-e": "extract_acronyms", "--only-core-tags": "only_core_tags", } for option, argument in opts: if option in ("-h", "--help"): _display_help() elif option in ("-V", "--version"): _display_version() elif option in ("-v", "--verbose"): log.setLevel(int(argument)) bconfig.set_global_level(int(argument)) elif option in ("-f", "--file"): options["text_files"].append(argument) elif option in with_argument: options[with_argument[option]] = argument elif option in without_argument: options[without_argument[option]] = True else: # This shouldn't happen as gnu_getopt should already handle # that case. log.error("option unrecognized -- %s" % option) # Collect the text inputs. options["text_files"] = args # Test if the options are consistent. # No file input. Checking the taxonomy or using old-style text # input? if not args: if not options["check_taxonomy"] and not options["text_files"]: log.error("Please specify a file or directory.") sys.exit(0) # No taxonomy input. elif not options["taxonomy"]: log.error("Please specify a taxonomy file.") sys.exit(0) # Output mode is correct? elif options["output_mode"]: options["output_mode"] = options["output_mode"].lower() # sanity options["output_mode"] = options["output_mode"].split(",") if not isinstance(options["output_mode"], list): if options["output_mode"] not in ("text", "marcxml", "html", "raw", "dict"): log.error("Output (-o) should be TEXT, MARCXML or HTML.") sys.exit(0) else: for i in options["output_mode"]: i = i.lower() if i not in ("text", "marcxml", "html", "raw", "dict"): log.error("Output (-o) should be TEXT, MARCXML or HTML.") sys.exit(0) # Match mode is correct? elif options["match_mode"]: options["match_mode"] = options["match_mode"].lower() # sanity if options["match_mode"] not in ("full", "partial"): log.error("Mode (-m) should be FULL or PARTIAL.") sys.exit(0) # Output limit is correct? try: options["output_limit"] = int(options["output_limit"]) if options["output_limit"] < 0: log.error("Output limit must be a positive integer.") sys.exit(0) except ValueError: log.error("Output limit must be a positive integer.") sys.exit(0) return options