def generate_translations(suite_id, component_id): global _translations_query from daklib.filewriter import TranslationFileWriter from daklib.dbconn import DBConn, Suite, Component from daklib.dakmultiprocessing import PROC_STATUS_SUCCESS session = DBConn().session() suite = session.query(Suite).get(suite_id) component = session.query(Component).get(component_id) writer_args = { 'archive': suite.archive.path, 'suite': suite.suite_name, 'component': component.component_name, 'language': 'en', } if suite.i18n_compression is not None: writer_args['compression'] = suite.i18n_compression writer = TranslationFileWriter(**writer_args) output = writer.open() r = session.execute(_translations_query, { "suite": suite_id, "component": component_id }) for (stanza, ) in r: print >> output, stanza writer.close() message = [ "generate-translations", suite.suite_name, component.component_name ] session.rollback() return (PROC_STATUS_SUCCESS, message)
def test_writer_test(self): tmpdir = tempfile.mkdtemp() try: dbcfw = BinaryContentsFileWriter(archive=tmpdir, suite=SUITE, component=COMPONENT, architecture=ARCH, debtype='deb') ubcdw = BinaryContentsFileWriter(archive=tmpdir, suite=SUITE, component=COMPONENT, architecture=ARCH, debtype='udeb') scfw = SourceContentsFileWriter(archive=tmpdir, suite=SUITE, component=COMPONENT) sfw = SourcesFileWriter(archive=tmpdir, suite=SUITE, component=COMPONENT) dpfw = PackagesFileWriter(archive=tmpdir, suite=SUITE, component=COMPONENT, architecture=ARCH, debtype='deb') upfw = PackagesFileWriter(archive=tmpdir, suite=SUITE, component=COMPONENT, architecture=ARCH, debtype='udeb') tfw = TranslationFileWriter(archive=tmpdir, suite=SUITE, component=COMPONENT, language=LANG) file_writers = [ dbcfw, ubcdw, scfw, sfw, dpfw, upfw, tfw, ] for writer in file_writers: fd = writer.open() fd.write('hallo world') writer.close() # TODO, verify that it created the correct files. # (currently we just test it does not crash). finally: shutil.rmtree(tmpdir)