Exemplo n.º 1
0
    def write_package(self):
        zip_file = self.package_name + '.zip'

        try:
            os.remove(zip_file)
        except:
            pass

        with zip.ZipFile(zip_file, 'w', zip.ZIP_DEFLATED,
                         compresslevel=9) as z:
            for root, dirs, files in os.walk(self.build_dir):
                for file in files:
                    fn = pj(root, file)
                    wargs = [fn, fn[len(self.build_dir):]]
                    mime = mime_type(fn)[0]

                    if mime and re.search(r'^image/(?!svg)', mime):
                        wargs.append(zip.ZIP_STORED)

                    z.write(*wargs)

        key = pj('.', 'secret', 'key.pem')

        if not os.path.isfile(key):
            return

        with open(os.devnull) as devnull:
            publickey = subprocess.Popen(
                ['openssl', 'rsa', '-pubout', '-outform', 'DER', '-in', key],
                stdout=subprocess.PIPE,
                stderr=devnull).stdout.read()

            signature = subprocess.Popen(
                ['openssl', 'sha1', '-sign', key, zip_file],
                stdout=subprocess.PIPE,
                stderr=devnull).stdout.read()

        package = self.package_name + '.' + self.ext

        try:
            os.remove(package)
        except:
            pass

        package = open(package, 'wb')
        package.write(b'Cr24')
        package.write(pack('<3I', 2, len(publickey), len(signature)))
        package.write(publickey)
        package.write(signature)
        package.write(open(zip_file, 'rb').read())

        with zip.ZipFile(zip_file, 'a', zip.ZIP_DEFLATED,
                         compresslevel=9) as z:
            z.write(key, os.path.basename(key))
Exemplo n.º 2
0
    def zip_package(self, zip_file, l=None):
        with zip.ZipFile(zip_file, 'w', zip.ZIP_DEFLATED,
                         compresslevel=l) as z:
            for root, dirs, files in os.walk(self.build_dir):
                for file in files:
                    fn = os.path.join(root, file)
                    wargs = [fn, fn[len(self.build_dir):]]
                    mime = mime_type(fn)[0]

                    if mime and re.search(r'^image/(?!svg)', mime):
                        wargs.append(zip.ZIP_STORED)

                    z.write(*wargs)
Exemplo n.º 3
0
    def write_package(self):
        package = self.package_name + '.' + self.ext

        with zip.ZipFile(package, 'w', zip.ZIP_DEFLATED) as z:
            for root, dirs, files in os.walk(self.build_dir):
                for file in files:
                    fn = pj(root, file)
                    wargs = [fn, fn[len(self.build_dir):]]
                    mime = mime_type(fn)[0]

                    if mime and re.search(r'^image/(?!svg)', mime):
                        wargs.append(zip.ZIP_STORED)

                    z.write(*wargs)
Exemplo n.º 4
0
tmp = [
    pj(tmp_dir, browsers['crx']['locales']),
    pj(tmp_dir, browsers['crx']['manifest']), package_name + '.zip'
]

copytree(pj(app_dir, browsers['crx']['locales']), tmp[0], copy_function=copy)
copy(pj(app_dir, browsers['crx']['manifest']), tmp[1])
move(pj(tmp_dir_js, 'app.js'), pj(tmp_dir, 'includes', 'app.js'))
move(pj(tmp_dir_js, 'app_bg.js'), pj(tmp_dir, 'js', 'app_bg.js'))

with zipfile.ZipFile(tmp[2], 'w', zipfile.ZIP_DEFLATED) as z:
    for root, dirs, files in os.walk(tmp_dir):
        for file in files:
            fn = pj(root, file)
            wargs = [fn, fn[len(tmp_dir):]]
            mime = mime_type(fn)[0]

            if mime and re.search(r'^image/(?!svg)', mime):
                wargs.append(zipfile.ZIP_STORED)

            z.write(*wargs)

rmtree(tmp[0])
os.remove(tmp[1])

print(package_name + '.zip')

try:
    rmtree(tmp_dir)
    rmtree(tmp_dir_js)
except: