合并devpi镜像服务端数据导出数据
本帖最后由 thirtyyears 于 2022-3-4 23:59 编辑devpi 离线缓存服务端及其更新,全方案:
[*] 在联网环境下搭建devpi镜像服务,
[*]下载需要的pypi包,确保联网环境下的devpi服务端有需要的包
[*]使用devpi-export 命令导出服务端数据
[*]打包zip,传输到内网
[*]在内网搭建devpi镜像服务,首次内网源,可直接打包1环境时生成的serverdir目录,解压到内网环境也可用,注:使用offline模式应该可提高响应速度
[*]由于需要更新内容的pypi包内容,且内网中还可存储自定义包,直接替换的方式很麻烦,且自己上传的包会失效,故开发下列合并方式。使用命令示例:python merge_exported.py -s serverdir -e exported_data_path
[*]时间关系,如有问题,可直接交流,如有需要,将持续补充内容
import zipfile
def main():
# run_server()
from argparse import ArgumentParser
parser = ArgumentParser('merge devpi exported data')
parser.add_argument('-s', dest='server_dir', help='需要合并到的位置')
parser.add_argument('-e', dest='exported_data', required=True, help='导出的数据')
args = parser.parse_args()
merge_exported(args.exported_data, args.server_dir)
pass
def merge_exported(exported_data_path, server_dir=None):
from devpi_server.config import get_pluginmanager
plugin_manager = get_pluginmanager()
import py
import sys
tw = py.io.TerminalWriter(sys.stderr)
# if argv is None:
# argv = sys.argv
# argv =
argv = []
if server_dir:
argv = ['--serverdir', str(server_dir)]
xom = get_xom(argv, plugin_manager)
from devpi_server.importexport import Importer
importer = Importer(tw, xom)
path = py.path.local(exported_data_path)
import tempfile
from pathlib import Path
mkstemp = tempfile.mkdtemp()
tmpdir = Path(mkstemp)
if path.ext == '.zip' and zipfile.is_zipfile(path.basename):
with zipfile.ZipFile(path) as f:
f.extractall(tmpdir)
print(tmpdir)
f_name = tmpdir
for n in f.filelist:
if not n.filename.endswith("dataindex.json"):
continue
f_name = f_name / n.filename
f_name = str(f_name.parent)
# print(f_name)
break
path = py.path.local(f_name)
importer.import_all(path)
# tmpdir.unlink()
def get_xom(argv, pluginmanager):
from devpi_server.config import parseoptions
config = parseoptions(pluginmanager, argv)
# args = config.args
# meta commmands
# if args.version:
# from devpi_server.views import server_version
# print(server_version)
# return 0
# now we can configure logging
from devpi_server.log import configure_logging
configure_logging(config.args)
if not config.path_nodeinfo.exists():
from devpi_server.main import fatal
fatal("The path '%s' contains no devpi-server data, use devpi-init to initialize." % config.serverdir)
from devpi_server.main import xom_from_config
return xom_from_config(config)
def run_server():
import devpi_server.main
devpi_server.main.main()
if __name__ == '__main__':
# run_server()
main()
看看,谢谢楼主分享。 感谢楼主分享 过来学习,多谢分享
过来学习,多谢分享 感谢楼主分享 谢谢楼主分享{:biggrin:} 谢谢分享,支持
页:
[1]