Exemplo n.º 1
0
class PdfToPngConverter(object):
    def __init__(self, path):
        self.path = path
        self.temp_dir = TempDir()

    def _page_name_template(self):
        return u"{temp_dir}/{filename}_%03d.png".format(
            temp_dir=self.temp_dir.path, filename=Path.filename(self.path))

    def _convert(self):
        args = [
            'gs', '-sDEVICE=pngalpha', '-o',
            self._page_name_template(), '-r300', self.path
        ]

        subprocess.check_output(args)

    def convert(self):
        self._convert()
        converted_files = self.temp_dir.list()
        return converted_files

    def __enter__(self):
        return self.convert()

    def __exit__(self, type, value, traceback):
        return self.temp_dir.remove()
Exemplo n.º 2
0
def test_build_container(channel, img, gpu):
    assert docker.from_env().ping()
    # Make sure we accept all licenses,
    with TempDir() as tmp:
        args = Arguments(
            channel,
            img,
            tmp,
            None,
            False,
            "",
            gpu,
            True,
            False,
            False,
            "us-docker.pkg.dev/android-emulator-268719/images",
            False,
            False,
        )
        emu_docker.accept_licenses(args)
        devices = emu_docker.create_docker_image(args)
        assert devices
        for device in devices:
            assert device.image_name() is not None
            client = docker.from_env()
            assert client.images.get(device.full_name()) is not None
Exemplo n.º 3
0
def test_build_container(channel, img):
    assert docker.from_env().ping()
    with TempDir() as tmp:
        args = Arguments(channel, img, tmp, None, False, "")
        device = emu_docker.create_docker_image(args)
        assert device.identity is not None
        client = docker.from_env()
        assert client.images.get(device.identity) is not None
Exemplo n.º 4
0
def test_run_container(channel, img, gpu):
    with TempDir() as tmp:
        args = Arguments(
            channel,
            img,
            tmp,
            None,
            False,
            "",
            gpu,
            True,
            False,
            False,
            "us-docker.pkg.dev/android-emulator-268719/images",
            False,
            False,
        )
        emu_docker.accept_licenses(args)
        devices = emu_docker.create_docker_image(args)
        assert devices
        for device in devices:
            port = find_free_port()

            # Launch this thing.
            container = device.launch({"5555/tcp": port})
            # Now we are going to insepct this thing.
            api_client = device.get_api_client()
            status = api_client.inspect_container(container.id)
            state = status["State"]
            assert state["Status"] == "running"

            # Acceptable states:
            # starting --> We are still launching
            # healthy --> Yay, we booted! Good to go..
            health = state["Health"]["Status"]
            while health == "starting":
                health = api_client.inspect_container(
                    container.id)["State"]["Health"]["Status"]

            assert health == "healthy"

            # Good, good.. From an internal perspective things look great.
            # Can we connect with adb from outside the container?
            adb = find_adb()

            # Erase knowledge of existing devices.
            subprocess.check_output([adb, "kill-server"])
            name = "localhost:{}".format(port)
            subprocess.check_output([adb, "connect", name])

            # Boot complete should be true..
            res = subprocess.check_output(
                [adb, "-s", name, "shell", "getprop", "dev.bootcomplete"])
            assert "1" in str(res)

            api_client.stop(container.id)
Exemplo n.º 5
0
def test_build_container(channel, img, gpu):
    assert docker.from_env().ping()
    # Make sure we accept all licenses,
    with TempDir() as tmp:
        args = Arguments(channel, img, tmp, None, False, "", gpu, True, False,
                         False, "aemu", False)
        emu_docker.accept_licenses(args)
        device = emu_docker.create_docker_image(args)
        assert device.identity is not None
        client = docker.from_env()
        assert client.images.get(device.identity) is not None
Exemplo n.º 6
0
def test_build_container():
    assert docker.from_env().ping()
    # Make sure we accept all licenses,
    with TempDir() as tmp:
        args = Arguments("canary", "Q google_apis x86_64", tmp,
                         "us.gcr.io/emu-dev-tst", False)
        cloud_build(args)
        expected_files = [
            "cloudbuild.yaml",
            "README.MD",
            "29-google-x64",
            "29-google-x64-no-metrics",
        ]
        for fname in expected_files:
            assert os.path.exists(os.path.join(tmp, fname))
Exemplo n.º 7
0
def test_build_cloud_only_sys():
    assert docker.from_env().ping()
    # Make sure we accept all licenses,
    with TempDir() as tmp:
        args = Arguments("canary", "Q google_apis x86_64", tmp,
                         "us-docker.pkg.dev/android-emulator-268719/images",
                         False, True)
        cloud_build(args)
        expected_files = [
            "cloudbuild.yaml",
            "README.MD",
            "sys-29-google-x64",
        ]
        for file_name in expected_files:
            assert os.path.exists(os.path.join(
                tmp,
                file_name)), "cannot find {} in {}".format(file_name, tmp)
Exemplo n.º 8
0
def test_run_container(channel, img):
    assert not "linux" in sys.platform
    assert docker.from_env().ping()
    with TempDir() as tmp:
        args = Arguments(channel, img, tmp, None, False, "")
        device = emu_docker.create_docker_image(args)
        port = find_free_port()

        # Launch this thing.
        device.launch(device.identity, port)
        # Now we are going to insepct this thing.
        api_client = device.get_api_client()
        status = api_client.inspect_container(device.container.id)
        state = status["State"]
        assert state["Status"] == "running"

        # Acceptable states:
        # starting --> We are still launching
        # healthy --> Yay, we booted! Good to go..
        health = state["Health"]["Status"]
        while health == "starting":
            health = api_client.inspect_container(
                device.container.id)["State"]["Health"]["Status"]

        assert health == "healthy"

        # Good, good.. From an internal perspective things look great.
        # Can we connect with adb from outside the container?
        adb = find_adb()

        # Erase knowledge of existing devices.
        subprocess.check_output([adb, "kill-server"])
        name = "localhost:{}".format(port)
        subprocess.check_output([adb, "connect", name])

        # Boot complete should be true..
        res = subprocess.check_output(
            [adb, "-s", name, "shell", "getprop", "dev.bootcomplete"])
        assert "1" in str(res)

        api_client.stop(device.container.id)
Exemplo n.º 9
0
def fetch(git_repo, checkout_dir=None, verbose=0, only=[]):
    """Download all the files managed by Git LFS
    """
    git_dir = git_repo + '/.git' if os.path.isdir(git_repo +
                                                  '/.git') else git_repo
    checkout_dir = checkout_dir or git_repo
    if checkout_dir == git_dir:
        print('Can\'t checkout into a bare repo, please provide a valid '
              'checkout_dir')
        raise SystemExit(1)
    checkout_git_dir = checkout_dir + '/.git'
    if not os.path.isdir(checkout_git_dir):
        with TempDir(dir=checkout_dir) as d:
            check_output(['git', 'clone', '-ns', git_repo, d], stderr=STDOUT)
            os.rename(d + '/.git', checkout_git_dir)
            with in_dir(checkout_dir):
                check_output(['git', 'reset', 'HEAD'])

    # Read the LFS metadata
    found = False
    only_enabled = len(only) > 0
    only = [
        os.path.relpath(os.path.abspath(path), checkout_dir) for path in only
    ]
    oid_list, lfs_files = [], {}
    for path, oid, size in read_lfs_metadata(checkout_dir):
        if only_enabled:
            if path not in only:
                continue
            else:
                only.remove(path)

        found = True
        dst = checkout_dir + '/' + path

        # Skip the file if it looks like it's already there
        with ignore_missing_file():
            if os.stat(dst).st_size == size:
                if verbose > 1:
                    print('Skipping', path, '(already present)')
                continue

        # If we have the file in the cache, link to it
        with ignore_missing_file():
            cached = get_cache_dir(git_dir, oid) + '/' + oid
            if os.stat(cached).st_size == size:
                force_link(cached, dst)
                if verbose > 0:
                    print('Linked', path, 'from the cache')
                continue

        oid_list.append(dict(oid=oid, size=size))
        lfs_files[(oid, size)] = path

    if only_enabled and only:
        print("Couldn't find the following files requested with --only:")
        for path in only:
            print(path)
        return False

    if not found:
        print('This repository does not seem to use LFS.')
        return False

    if not oid_list:
        if verbose > 0:
            print('Nothing to fetch.')
        return True

    # Fetch the URLs of the files from the Git LFS endpoint
    lfs_url, lfs_auth_info = get_lfs_endpoint_url(git_repo, checkout_dir)

    if verbose > 0:
        print('Fetching URLs from %s ...' % lfs_url)
    if verbose > 1:
        print('Authorization info for URL: %s' % lfs_auth_info)
        print('oid_list: %s' % pprint.pformat(oid_list))
    objects = fetch_urls(lfs_url, lfs_auth_info, oid_list)

    # Download the files
    tmp_dir = git_dir + '/lfs/tmp'
    if not os.path.exists(tmp_dir):
        os.makedirs(tmp_dir)
    for obj in objects:
        oid, size = (obj['oid'], obj['size'])
        path = lfs_files[(oid, size)]
        cache_dir = get_cache_dir(git_dir, oid)

        # Download into tmp_dir
        with TempFile(dir=tmp_dir) as f:
            url = obj['actions']['download']['href']
            head = obj['actions']['download']['header']
            print('Downloading %s (%s bytes) from %s...' %
                  (path, size, url if verbose > 0 else url[:40]))
            h = urlretrieve(url, headers=head)
            while True:
                buf = h.read(10240)
                if not buf:
                    break
                f.write(buf)

            # Move to cache_dir
            dst1 = cache_dir + '/' + oid
            if not os.path.exists(cache_dir):
                os.makedirs(cache_dir)
            if verbose > 1:
                print('temp download file: ' + f.name)
                print('cache file name: ' + dst1)
            os.rename(f.name, dst1)

        # Copy into checkout_dir
        dst2 = checkout_dir + '/' + path
        force_link(dst1, dst2)

    return True
Exemplo n.º 10
0
    def test_translate_modules(self):
        """
        Test translated strings in the module using the .po and .pot files
        """

        from os.path import join, isdir
        from tools import trans_export
        from six.moves import StringIO
        from utils import compare_pofiles, TempDir

        if not self.config['testing_langs']:
            logger.warning('Configuration variable "DESTRAL_TESTING_LANGS" has'
                           ' not been initialized')
            return

        mod_path = join(self.openerp.config['addons_path'],
                        self.config['module'])
        trad_path = join(mod_path, 'i18n')

        self.assertTrue(
            isdir(trad_path),
            'Module {} has no translations'.format(self.config['module']))

        logger.info('Checking translations for module %s',
                    self.config['module'])
        with Transaction().start(self.database) as txn:
            cursor = txn.cursor

            # Generate POT data from loaded strings
            trans_data = StringIO()
            trans_export(False, [self.config['module']],
                         trans_data,
                         'po',
                         dbname=cursor.dbname)
            trans_obj = self.openerp.pool.get('wizard.module.lang.export')
            trans_data = trans_obj.append_report_translations(
                txn.cursor, txn.user, [self.config['module']], 'pot',
                trans_data)

        with TempDir() as temp:
            tmp_pot = '{}/{}.pot'.format(temp.dir, self.config['module'])
            # Write POT data into temp file
            with open(tmp_pot, 'w') as pot:
                pot.write(trans_data.getvalue())
            pot_path = join(trad_path, '{}.pot'.format(self.config['module']))
            missing_strings, untranslated_strings = compare_pofiles(
                tmp_pot, pot_path)
            # Don't compare untranslated strings in POT
            #   because POT files do not contain translations
            self.assertIsNotNone(
                missing_strings,
                'There is not a POT file for module {}'.format(
                    self.config['module']))
            self.assertItemsEqual(
                [], missing_strings,
                'There are {} missing strings in the POT file'
                ' of the module {}\nThe missing strings are:\n'
                '\n{}\n'.format(len(missing_strings), self.config['module'],
                                '\n'.join(missing_strings)))
            logger.info('Checking translations for langs: {}'.format(
                self.config['testing_langs']))
            for test_lang in self.config['testing_langs']:
                po_path = join(trad_path, '{}.po'.format(test_lang))
                missing_strings, untranslated_strings = compare_pofiles(
                    tmp_pot, po_path)
                self.assertIsNotNone(
                    missing_strings, 'There is not a PO file for module {}'
                    ' with locale: "{}"'.format(self.config['module'],
                                                test_lang))
                self.assertItemsEqual(
                    [], missing_strings,
                    'There are {} missing strings in the PO file'
                    ' of the module {}\nThe missing strings are:\n'
                    '\n{}\n'.format(len(missing_strings),
                                    self.config['module'],
                                    '\n'.join(missing_strings)))
                self.assertItemsEqual(
                    [], untranslated_strings,
                    'There are {} untranslated strings in the PO file'
                    ' of the module {}\nThe untranslated strings are:\n'
                    '\n{}\n'.format(len(untranslated_strings),
                                    self.config['module'],
                                    '\n'.join(untranslated_strings)))
Exemplo n.º 11
0
 def __init__(self, path):
     self.path = path
     self.temp_dir = TempDir()