def convert(self, data, title): bib_type = self.getType() conv_impl = conv.conv_impl() converter = conv_impl.build_conversion_chain(bib_type, self.model.config.convert_to) out_ext = conv_impl.getExtention(self.model.config.convert_to) if "convert_to" in self.model.config: #Convert Data output, error = converter.convert(data) #Write converted data converted_file_name = "%s.%s" % (os.path.join(self.model.config.output_dir, title), out_ext) backup_if_exists(title, converted_file_name, self.model.config.output_bak_dir, out_ext) out = open(converted_file_name, "wb") out.write(output) out.close() #write filed original data original_file_name = "%s.%s" % (os.path.join(self.model.config.output_dir, title), self.getExtension()) backup_if_exists(title, original_file_name, self.model.config.output_bak_dir, self.getExtension()) out = open(original_file_name, "wb") out.write(data) out.close() print (error)
def write_output(self): """ Generate the bibliographies """ config = self.model.config for bib in config: #Bib's config bib_config = config[bib] #Construct the converter converter = conv.conv_impl().build_conversion_chain(bib_config[input_format], bib_config[output_format]) #Convert the bib and write it output = file(bib, "wb") done = [] for item in bib_config[listing]: item_loc = os.path.join(self.model.config.dir_name, item) item_file = file(item_loc) data = item_file.read() item_file.close() try: if item_loc not in done: (data, error) = converter.convert(data) output.write(data) self.logger.info(error, extra={"location":item_loc}) done.append(item_loc) else: self.logger.info("Already processed: %s"%item_loc) except ConversionError, ce: self.logger.error(output, extra={"code":ce.code, "location":item_loc}) output.close()
def initialise(parser, config): model = Model() model.config = config_helper(config) model.namespace = parser.parse_args() init = config.read_config() ui = simpleui.create_UI(model.namespace, config) if not init: model.config.output_dir =\ ui.prompt_file_selector("Select the output location", type=FileSelectorTypes.SELECT_FOLDER)[0] output_types = conv.conv_impl().get_output_types() model.config.convert_to =\ output_types[ui.prompt_list("Select Output Format", "Please Select the Output Format:", output_types)[0]] model.config.config_delegate.write_config() return model
# You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import logging import os from gRefer import conv from StringIO import StringIO from gdata.client import NotModified from gRefer.config_constants import * from gdata_utils import create_docs_client from gRefer.exceptions import ConversionError from gdata_utils.fs import GoogleDocs from gdata_utils.fs.constants import * from simpleui.utils import serialize_objs, un_serialize_obj input_types = conv.conv_impl().get_input_types() output_types = conv.conv_impl().get_output_types() class impl: mime_types = {"mods": ["text/xml", "application/xml"]} parent_mime_type = "application/grefer+json" bib_config_file_name = "settings.gref" ignore_mime_types = [parent_mime_type, "application/pdf"] class gRefer: logger = logging.getLogger(name="gRefer.gRefer") def __init__(self, model): self.model = model self.fs = GoogleDocs(create_docs_client(model.ui, "gRefer"), model.config.dir_name) def initialize(self):