代码拉取完成,页面将自动刷新
同步操作将从 itopen/gitlab_sync 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/usr/bin/env python3
# _*_ coding:utf-8 _*_
# @Time : 2023/2/4 1:25
# @Author : wen_fei
# @Email : [email protected]
# @File : xml_parse.py
# @Project : CreatGitLabPrj
import os
class XmlParse:
def __init__(self, ohos_path=None, default_xml=None):
self.ohos_path = ohos_path
self.manifests_path = os.path.join(self.ohos_path, '.repo', 'manifests')
self.default_xml = default_xml
self.xml_list = []
self.plist = []
# 解析出default_xml
def get_default_xml(self):
manifest = os.path.join(self.ohos_path, '.repo/manifest.xml')
print('manifest xml is {}'.format(manifest))
with open(manifest, 'r') as file:
for line in file.readlines():
if not line.count('include name'):
continue
self.default_xml = line.split('"')[1]
break
print("get_default_xml is {}".format(self.default_xml))
return self.default_xml
# 解析xml文件
def _get_xml_list(self, xml_file):
with open(xml_file, 'r') as file:
for line in file.readlines():
if line.count('include name'):
tmp_file = line.split('"')[1]
new_xml = os.path.join(self.manifests_path, tmp_file)
self._get_xml_list(new_xml)
self.xml_list.append(xml_file)
# 打印xml list
def show_xml_list(self):
print("start show xml list:")
for list in self.xml_list:
print(list)
return
# 解析出default_xml包含的xml
def get_xml_list(self):
if not self.default_xml:
self.get_default_xml()
main_xml = os.path.join(self.manifests_path, self.default_xml)
print('main_xml is {}'.format(main_xml))
self._get_xml_list(main_xml)
self.show_xml_list()
return self.xml_list
# default param解析
def parse_default_param(self, context):
pass
# 解析project
def _parse_project(self, context):
list = context.split()
project_name = None
project_path = None
pdict = {}
for str in list:
if str.count('name='):
project_name = str.split('"')[1]
continue
if str.count('path='):
project_path = str.split('"')[1]
continue
if project_name and project_path:
pdict['name'] = project_name
pdict['path'] = os.path.join(self.ohos_path, project_path)
self.plist.append(pdict)
return
# 解析remove project
def _parse_remove_project(self, context):
list = context.split()
project_name = None
for str in list:
if str.count('name='):
project_name = str.split('"')[1]
break
if not project_name:
return
for proj in self.plist:
if project_name == proj['name']:
self.plist.remove(proj)
return
# 解析xml文件
def _parse_xml(self, xml_file):
print("xml_file is {}".format(xml_file))
with open(xml_file, 'r') as file:
for line in file.readlines():
if line.count('<default'):
self.parse_default_param(line)
if line.count('<project'):
self._parse_project(line)
if line.count('<remove-project'):
self._parse_remove_project(line)
return
# 按xml_list顺序解析xml,获取project名称和路径
def parse_xml(self):
if not self.xml_list:
self.get_xml_list()
for list in self.xml_list:
self._parse_xml(list)
# 打印plist
def show_plist(self):
print("start print plist:")
for list in self.plist:
print("name = {}, path = {}".format(list['name'], list['path']))
if __name__ == '__main__':
xmlParse = XmlParse(ohos_path='.')
xmlParse.parse_xml()
xmlParse.show_plist()
pass
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。