Пример #1
0
    def set_item_param(self, item, key, value):
        """
		Sets item param, applying additional conversion if needed.
		"""
        if key in config.parser.latex_params:
            validate = config.parser.latex_params[key]
            value = utils.parse_latex(item, key, value, validate)

        try:
            if key in config.parser.list_params:
                value = utils.strip_split_list(value, config.parser.list_sep)
            elif key in config.parser.file_list_params:
                value = utils.strip_split_list(value, config.parser.list_sep)
                filesize_value = []
                for single_filename in value:
                    #filenames start from slash, trimming it
                    abspath = os.path.join(config.www.elibrary_dir,
                                           single_filename[1:])
                    if (os.path.isfile(abspath)):
                        filesize_value.append(os.path.getsize(abspath))
                    else:
                        logging.warn(
                            "File is not accessible: {0}".format(abspath))
                        filesize_value.append(0)
                item.set(const.FILE_SIZE_PARAM, filesize_value)
            elif key in config.parser.keyword_list_params:
                value = utils.strip_split_list(value, config.parser.list_sep)
                useful_keywords = (set(value) <=
                                   config.parser.useless_keywords)
                item.set("useful_" + key, useful_keywords)
            elif key in config.parser.int_params:
                value = int(value)
            elif key in config.parser.year_params:
                (year_from, year_to, year_circa) = utils.parse_year(value)

                item.set(key + config.parser.start_suffix, year_from)
                item.set(key + config.parser.end_suffix, year_to)
                item.set(key + config.parser.circa_suffix, year_circa)
            elif key in config.parser.date_params:
                value = datetime.datetime.strptime(value,
                                                   config.parser.date_format)

        except ValueError:
            self.raise_error()

        item.set(key, value)
Пример #2
0
	def set_item_param(self, item, key, value):
		"""
		Sets item param, applying additional conversion if needed.
		"""
		if key in config.parser.latex_params:
			utils.validate_latex(item, key, value)
			value = utils.parse_latex(value)

		try:
			if key in config.parser.list_params:
				value = utils.strip_split_list(value, config.parser.list_sep)
			elif key in config.parser.file_list_params:
				value = utils.strip_split_list(value, config.parser.list_sep)
				filesize_value = []
				for single_filename in value:
					#filenames start from slash, trimming it
					abspath = os.path.join(config.www.elibrary_dir, single_filename[1:])
					if (os.path.isfile(abspath)):
						filesize_value.append(os.path.getsize(abspath))
					else:
						logging.warn("File is not accessible: {0}".format(abspath))
						filesize_value.append(0)
				item.set(const.FILE_SIZE_PARAM, filesize_value)
			elif key in config.parser.keyword_list_params:
				value = utils.strip_split_list(value, config.parser.list_sep)
				useful_keywords = (set(value) <= config.parser.useless_keywords)
				item.set("useful_" + key, useful_keywords)
			elif key in config.parser.int_params:
				value = int(value)
			elif key in config.parser.year_params:
				(year_from, year_to, year_circa) = utils.parse_year(value)

				item.set(key + config.parser.start_suffix, year_from)
				item.set(key + config.parser.end_suffix, year_to)
				item.set(key + config.parser.circa_suffix, year_circa)
			elif key in config.parser.date_params:
				value = datetime.datetime.strptime(value, config.parser.date_format)

		except ValueError:
			self.raise_error()

		item.set(key, value)
Пример #3
0
	def set_item_param(self, item: BibItem, key: str, value: str):
		"""
		Sets item param, applying additional conversion if needed.
		"""
		value = utils.parse_latex(value)
		
		try:
			if key in config.parser.list_params:
				value = utils.strip_split_list(value, config.parser.list_sep)
			elif key in config.parser.int_params:
				value = int(value)
			elif key in config.parser.year_params:
				(year_from, year_to, year_circa) = utils.parse_year(value)

				item.set(key + config.parser.start_suffix, year_from)
				item.set(key + config.parser.end_suffix, year_to)
				item.set(key + config.parser.circa_suffix, year_circa)
			elif key in config.parser.date_params:
				value = datetime.datetime.strptime(value, config.parser.date_format)
				
		except ValueError:
			self.raise_error()
				
		item.set(key, value)