Beispiel #1
0
def fix_let_scope_bustage_in_xpi(xpi_path):
    """Rewrite all the top level `let` to `var` in an XPI."""
    files_to_fix = []
    with repack(xpi_path) as folder:
        for root, dirs, files in os.walk(folder):
            for file_ in files:
                if file_.endswith('.js'):
                    # We only want to fix javascript files.
                    files_to_fix.append(os.path.join(root, file_))
        fix_let_scope_bustage(*files_to_fix)
Beispiel #2
0
def fix_let_scope_bustage_in_xpi(xpi_path):
    """Rewrite all the top level `let` to `var` in an XPI."""
    files_to_fix = []
    with repack(xpi_path) as folder:
        for root, dirs, files in os.walk(folder):
            for file_ in files:
                if file_.endswith('.js'):
                    # We only want to fix javascript files.
                    files_to_fix.append(os.path.join(root, file_))
        fix_let_scope_bustage(*files_to_fix)
Beispiel #3
0
def test_repack():
    # Warning: context managers all the way down. Because they're awesome.
    extension_file = 'apps/files/fixtures/files/extension.xpi'
    # We don't want to overwrite our fixture, so use a copy.
    with amo.tests.copy_file_to_temp(extension_file) as temp_filename:
        # This is where we're really testing the repack helper.
        with utils.repack(temp_filename) as folder_path:
            # Temporary folder contains the unzipped XPI.
            assert os.listdir(folder_path) == [
                'install.rdf', 'chrome.manifest', 'chrome']
            # Add a file, which should end up in the repacked file.
            with open(os.path.join(folder_path, 'foo.bar'), 'w') as file_:
                file_.write('foobar')
        # Once we're done with the repack, the temporary folder is removed.
        assert not os.path.exists(folder_path)
        # And the repacked file has the added file.
        assert os.path.exists(temp_filename)
        with zipfile.ZipFile(temp_filename, mode='r') as zf:
            assert 'foo.bar' in zf.namelist()
            assert zf.read('foo.bar') == 'foobar'
Beispiel #4
0
def test_repack():
    # Warning: context managers all the way down. Because they're awesome.
    extension_file = 'apps/files/fixtures/files/extension.xpi'
    # We don't want to overwrite our fixture, so use a copy.
    with amo.tests.copy_file_to_temp(extension_file) as temp_filename:
        # This is where we're really testing the repack helper.
        with utils.repack(temp_filename) as folder_path:
            # Temporary folder contains the unzipped XPI.
            assert os.listdir(folder_path) == [
                'install.rdf', 'chrome.manifest', 'chrome'
            ]
            # Add a file, which should end up in the repacked file.
            with open(os.path.join(folder_path, 'foo.bar'), 'w') as file_:
                file_.write('foobar')
        # Once we're done with the repack, the temporary folder is removed.
        assert not os.path.exists(folder_path)
        # And the repacked file has the added file.
        assert os.path.exists(temp_filename)
        with zipfile.ZipFile(temp_filename, mode='r') as zf:
            assert 'foo.bar' in zf.namelist()
            assert zf.read('foo.bar') == 'foobar'