예제 #1
0
 def add_site_packages(self):
     print('\nAdding site-packages')
     os.makedirs(self.site_packages)
     sys_path = json.loads(subprocess.check_output([
         PYTHON, '-c', 'import sys, json; json.dump(sys.path, sys.stdout)']))
     paths = reversed(tuple(map(abspath, [x for x in sys_path if x.startswith('/') and not x.startswith('/Library/')])))
     upaths = []
     for x in paths:
         if x not in upaths and (x.endswith('.egg') or x.endswith('/site-packages')):
             upaths.append(x)
     upaths.append(join(CALIBRE_DIR, 'src'))
     for x in upaths:
         print('\t', x)
         tdir = None
         try:
             if not os.path.isdir(x):
                 zf = zipfile.ZipFile(x)
                 tdir = tempfile.mkdtemp()
                 zf.extractall(tdir)
                 x = tdir
             self.add_modules_from_dir(x)
             self.add_packages_from_dir(x)
         finally:
             if tdir is not None:
                 shutil.rmtree(tdir)
     fix_pycryptodome(self.site_packages)
     try:
         shutil.rmtree(join(self.site_packages, 'calibre', 'plugins'))
     except OSError as err:
         if err.errno != errno.ENOENT:
             raise
     sp = join(self.resources_dir, 'Python', 'site-packages')
     self.remove_bytecode(sp)
예제 #2
0
def copy_python(env, ext_dir):
    print('Copying python...')
    srcdir = j(PREFIX, 'lib/python' + py_ver)

    for x in os.listdir(srcdir):
        y = j(srcdir, x)
        ext = os.path.splitext(x)[1]
        if os.path.isdir(y) and x not in ('test', 'hotshot', 'site-packages',
                                          'idlelib', 'dist-packages'):
            shutil.copytree(y, j(env.py_dir, x), ignore=ignore_in_lib)
        if os.path.isfile(y) and ext in ('.py', '.so'):
            shutil.copy2(y, env.py_dir)

    srcdir = j(srcdir, 'site-packages')
    dest = j(env.py_dir, 'site-packages')
    import_site_packages(srcdir, dest)

    for x in os.listdir(env.SRC):
        c = j(env.SRC, x)
        if os.path.exists(j(c, '__init__.py')):
            shutil.copytree(c,
                            j(dest, x),
                            ignore=partial(ignore_in_lib, ignored_dirs={}))
        elif os.path.isfile(c):
            shutil.copy2(c, j(dest, x))
    shutil.copytree(j(env.src_root, 'resources'), j(env.base, 'resources'))
    for pak in glob.glob(j(QT_PREFIX, 'resources', '*.pak')):
        shutil.copy2(pak, j(env.base, 'resources'))
    os.mkdir(j(env.base, 'translations'))
    shutil.copytree(j(QT_PREFIX, 'translations', 'qtwebengine_locales'),
                    j(env.base, 'translations', 'qtwebengine_locales'))
    sitepy = j(self_dir, 'site.py')
    shutil.copy2(sitepy, j(env.py_dir, 'site.py'))

    pdir = j(env.lib_dir, 'calibre-extensions')
    if not os.path.exists(pdir):
        os.mkdir(pdir)
    fix_pycryptodome(j(env.py_dir, 'site-packages'))
    for x in os.listdir(j(env.py_dir, 'site-packages')):
        os.rename(j(env.py_dir, 'site-packages', x), j(env.py_dir, x))
    os.rmdir(j(env.py_dir, 'site-packages'))
    print('Extracting extension modules from', ext_dir, 'to', pdir)
    ext_map = extract_extension_modules(ext_dir, pdir)
    shutil.rmtree(j(env.py_dir, 'calibre', 'plugins'))
    print('Extracting extension modules from', env.py_dir, 'to', pdir)
    ext_map.update(extract_extension_modules(env.py_dir, pdir))
    py_compile(env.py_dir)
    freeze_python(env.py_dir,
                  pdir,
                  env.obj_dir,
                  ext_map,
                  develop_mode_env_var='CALIBRE_DEVELOP_FROM')
    shutil.rmtree(env.py_dir)