Skip to content

Commit

Permalink
Merge pull request #3409 from AgoraIO/sync-test
Browse files Browse the repository at this point in the history
Sync test
  • Loading branch information
Cilla-luodan authored Nov 2, 2023
2 parents 9586fc5 + 26c9123 commit 385f515
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-app-sync-proto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: sync proto type (cn to en)
run: |
cd xml2json
python sync_prototype.py --src_dir ../dita/RTC-NG/API --dest_dir ../en-US/dita/RTC-NG/API
python sync_prototype.py --src_dir ../dita/RTC-NG --dest_dir ../en-US/dita/RTC-NG
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
Expand Down
9 changes: 6 additions & 3 deletions dita/RTC-NG/config/keys-rtc-ng-api-blueprint.ditamap
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,24 @@
<keydef keys="callback-section-title">
<topicmeta>
<keywords>
<keyword>参数</keyword>
<keyword props="cn">参数</keyword>
<keyword props="en">Parameters</keyword>
</keywords>
</topicmeta>
</keydef>
<keydef keys="return-section-title">
<topicmeta>
<keywords>
<keyword>返回值</keyword>
<keyword props="cn">返回值</keyword>
<keyword props="en">Returns</keyword>
</keywords>
</topicmeta>
</keydef>
<keydef keys="typedef">
<topicmeta>
<keywords>
<keyword>Struct 及 Enum</keyword>
<keyword props="cn">Struct 及 Enum</keyword>
<keyword props="en">Struct and Enum</keyword>
</keywords>
</topicmeta>
</keydef>
Expand Down
9 changes: 6 additions & 3 deletions dita/RTC-NG/config/keys-rtc-ng-api-cpp.ditamap
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,24 @@
<keydef keys="callback-section-title">
<topicmeta>
<keywords>
<keyword>参数</keyword>
<keyword props="cn">参数</keyword>
<keyword props="en">Parameters</keyword>
</keywords>
</topicmeta>
</keydef>
<keydef keys="return-section-title">
<topicmeta>
<keywords>
<keyword>返回值</keyword>
<keyword props="cn">返回值</keyword>
<keyword props="en">Returns</keyword>
</keywords>
</topicmeta>
</keydef>
<keydef keys="typedef">
<topicmeta>
<keywords>
<keyword>Struct 及 Enum</keyword>
<keyword props="cn">Struct 及 Enum</keyword>
<keyword props="en">Struct and Enum</keyword>
</keywords>
</topicmeta>
</keydef>
Expand Down
9 changes: 6 additions & 3 deletions dita/RTC-NG/config/keys-rtc-ng-api-electron.ditamap
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,24 @@
<keydef keys="callback-section-title">
<topicmeta>
<keywords>
<keyword>参数</keyword>
<keyword props="cn">参数</keyword>
<keyword props="en">Parameters</keyword>
</keywords>
</topicmeta>
</keydef>
<keydef keys="return-section-title">
<topicmeta>
<keywords>
<keyword>返回值</keyword>
<keyword props="cn">返回值</keyword>
<keyword props="en">Returns</keyword>
</keywords>
</topicmeta>
</keydef>
<keydef keys="typedef">
<topicmeta>
<keywords>
<keyword>Class 及 Enum</keyword>
<keyword props="cn">Class 及 Enum</keyword>
<keyword props="en">Class and Enum</keyword>
</keywords>
</topicmeta>
</keydef>
Expand Down
9 changes: 6 additions & 3 deletions dita/RTC-NG/config/keys-rtc-ng-api-flutter.ditamap
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@
<keydef keys="callback-section-title">
<topicmeta>
<keywords>
<keyword>参数</keyword>
<keyword props="cn">参数</keyword>
<keyword props="en">Parameters</keyword>
</keywords>
</topicmeta>
</keydef>
<keydef keys="return-section-title">
<topicmeta>
<keywords>
<keyword>异常</keyword>
<keyword props="cn">异常</keyword>
<keyword props="en">Exceptions</keyword>
</keywords>
</topicmeta>
</keydef>
Expand Down Expand Up @@ -12103,7 +12105,8 @@
<keydef keys="typedef">
<topicmeta>
<keywords>
<keyword>Class 及 Enum</keyword>
<keyword props="cn">Class 及 Enum</keyword>
<keyword props="en">Class and Enum</keyword>
</keywords>
</topicmeta>
</keydef>
Expand Down
9 changes: 6 additions & 3 deletions dita/RTC-NG/config/keys-rtc-ng-api-ios.ditamap
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,24 @@
<keydef keys="callback-section-title">
<topicmeta>
<keywords>
<keyword>参数</keyword>
<keyword props="cn">参数</keyword>
<keyword props="en">Parameters</keyword>
</keywords>
</topicmeta>
</keydef>
<keydef keys="return-section-title">
<topicmeta>
<keywords>
<keyword>返回值</keyword>
<keyword props="cn">返回值</keyword>
<keyword props="en">Returns</keyword>
</keywords>
</topicmeta>
</keydef>
<keydef keys="typedef">
<topicmeta>
<keywords>
<keyword>Class 及 Enum</keyword>
<keyword props="cn">Class 及 Enum</keyword>
<keyword props="en">Class and Enum</keyword>
</keywords>
</topicmeta>
</keydef>
Expand Down
9 changes: 6 additions & 3 deletions dita/RTC-NG/config/keys-rtc-ng-api-java.ditamap
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@
<keydef keys="callback-section-title">
<topicmeta>
<keywords>
<keyword>参数</keyword>
<keyword props="cn">参数</keyword>
<keyword props="en">Parameters</keyword>
</keywords>
</topicmeta>
</keydef>
<keydef keys="return-section-title">
<topicmeta>
<keywords>
<keyword>返回值</keyword>
<keyword props="cn">返回值</keyword>
<keyword props="en">Returns</keyword>
</keywords>
</topicmeta>
</keydef>
Expand Down Expand Up @@ -11798,7 +11800,8 @@
<keydef keys="typedef">
<topicmeta>
<keywords>
<keyword>Class 及 Enum</keyword>
<keyword props="cn">Class 及 Enum</keyword>
<keyword props="en">Class and Enum</keyword>
</keywords>
</topicmeta>
</keydef>
Expand Down
9 changes: 6 additions & 3 deletions dita/RTC-NG/config/keys-rtc-ng-api-macos.ditamap
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@
<keydef keys="callback-section-title">
<topicmeta>
<keywords>
<keyword>参数</keyword>
<keyword props="cn">参数</keyword>
<keyword props="en">Parameters</keyword>
</keywords>
</topicmeta>
</keydef>
<keydef keys="return-section-title">
<topicmeta>
<keywords>
<keyword>返回值</keyword>
<keyword props="cn">返回值</keyword>
<keyword props="en">Returns</keyword>
</keywords>
</topicmeta>
</keydef>
Expand Down Expand Up @@ -11664,7 +11666,8 @@
<keydef keys="typedef">
<topicmeta>
<keywords>
<keyword>Class 及 Enum</keyword>
<keyword props="cn">Class 及 Enum</keyword>
<keyword props="en">Class and Enum</keyword>
</keywords>
</topicmeta>
</keydef>
Expand Down
9 changes: 6 additions & 3 deletions dita/RTC-NG/config/keys-rtc-ng-api-rn.ditamap
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,24 @@
<keydef keys="callback-section-title">
<topicmeta>
<keywords>
<keyword>参数</keyword>
<keyword props="cn">参数</keyword>
<keyword props="en">Parameters</keyword>
</keywords>
</topicmeta>
</keydef>
<keydef keys="return-section-title">
<topicmeta>
<keywords>
<keyword>返回值</keyword>
<keyword props="cn">返回值</keyword>
<keyword props="en">Returns</keyword>
</keywords>
</topicmeta>
</keydef>
<keydef keys="typedef">
<topicmeta>
<keywords>
<keyword>Class 及 Enum</keyword>
<keyword props="cn">Class 及 Enum</keyword>
<keyword props="en">Class and Enum</keyword>
</keywords>
</topicmeta>
</keydef>
Expand Down
9 changes: 6 additions & 3 deletions dita/RTC-NG/config/keys-rtc-ng-api-unity.ditamap
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@
<keydef keys="callback-section-title">
<topicmeta>
<keywords>
<keyword>参数</keyword>
<keyword props="cn">参数</keyword>
<keyword props="en">Parameters</keyword>
</keywords>
</topicmeta>
</keydef>
<keydef keys="return-section-title">
<topicmeta>
<keywords>
<keyword>返回值</keyword>
<keyword props="cn">返回值</keyword>
<keyword props="en">Returns</keyword>
</keywords>
</topicmeta>
</keydef>
Expand Down Expand Up @@ -12815,7 +12817,8 @@
<keydef keys="typedef">
<topicmeta>
<keywords>
<keyword>Class 及 Enum</keyword>
<keyword props="cn">Class 及 Enum</keyword>
<keyword props="en">Class and Enum</keyword>
</keywords>
</topicmeta>
</keydef>
Expand Down
9 changes: 6 additions & 3 deletions dita/RTC-NG/config/keys-rtc-ng-api-unreal.ditamap
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,24 @@
<keydef keys="callback-section-title">
<topicmeta>
<keywords>
<keyword>参数</keyword>
<keyword props="cn">参数</keyword>
<keyword props="en">Parameters</keyword>
</keywords>
</topicmeta>
</keydef>
<keydef keys="return-section-title">
<topicmeta>
<keywords>
<keyword>返回值</keyword>
<keyword props="cn">返回值</keyword>
<keyword props="en">Returns</keyword>
</keywords>
</topicmeta>
</keydef>
<keydef keys="typedef">
<topicmeta>
<keywords>
<keyword>Struct 及 Enum</keyword>
<keyword props="cn">Struct 及 Enum</keyword>
<keyword props="en">Struct and Enum</keyword>
</keywords>
</topicmeta>
</keydef>
Expand Down
89 changes: 52 additions & 37 deletions xml2json/sync_prototype.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,55 @@
import os
import re
import argparse

parser = argparse.ArgumentParser(description="Prototype syncer")

parser.add_argument("--src_dir",help="src dir",action="store")
parser.add_argument("--dest_dir", help="dest dir", action="store")

args = vars(parser.parse_args())

src_dir = args['src_dir']
dest_dir = args['dest_dir']

prefixes = ('api_', 'callback_', 'class_')

for file_name in os.listdir(src_dir):

if file_name.startswith(prefixes):

cn_path = os.path.join(src_dir, file_name)
with open(cn_path, 'r') as cn_file:
cn_file_content = cn_file.read()
pattern = r'<section id="prototype".*?</section>'
proto = re.findall(pattern, cn_file_content, flags=re.DOTALL)
if not proto:
print(f"No proto in cn file: {cn_path}")
continue

en_path = os.path.join(dest_dir, file_name)
try:
with open(en_path, 'r+') as en_file:
en_file_content = en_file.read()
en_file.seek(0)
updated_content = re.sub(r'<section id="prototype".*?</section>', proto[0], en_file_content, flags=re.DOTALL)
en_file.write(updated_content)
en_file.truncate()
except FileNotFoundError:
print(f"No corresponding en file: {en_path}")
continue
import shutil

def sync_prototype(src_dir, dest_dir):
src_api_dir = os.path.join(src_dir, 'API')
dest_api_dir = os.path.join(dest_dir, 'API')

for file_name in os.listdir(src_api_dir):
if file_name.startswith(('api_', 'callback_', 'class_')):
src_file = os.path.join(src_api_dir, file_name)
dest_file = os.path.join(dest_api_dir, file_name)

with open(src_file, 'r') as file:
content = file.read()
pattern = r'<section id="prototype".*?</section>'
proto = re.findall(pattern, content, flags=re.DOTALL)
if not proto:
print(f"No proto in cn file: {src_file}")
continue

if os.path.exists(dest_file):
with open(dest_file, 'r+') as file:
content = file.read()
updated_content = re.sub(r'<section id="prototype".*?</section>', proto[0], content, flags=re.DOTALL)
file.seek(0)
file.write(updated_content)
file.truncate()
else:
print(f"No corresponding en file: {dest_file}")

def sync_keysmap(src_dir, dest_dir):
src_config_dir = os.path.join(src_dir, 'config')
dest_config_dir = os.path.join(dest_dir, 'config')

for file_name in os.listdir(src_config_dir):
if file_name.startswith('keys-rtc-ng-api'):
src_file = os.path.join(src_config_dir, file_name)
dest_file = os.path.join(dest_config_dir, file_name)
shutil.copy2(src_file, dest_file)

def main():
parser = argparse.ArgumentParser(description="Prototype & Keysmap syncer")
parser.add_argument("--src_dir", help="source directory", action="store")
parser.add_argument("--dest_dir", help="destination directory", action="store")
args = vars(parser.parse_args())
src_dir = args['src_dir']
dest_dir = args['dest_dir']

sync_prototype(src_dir, dest_dir)
sync_keysmap(src_dir, dest_dir)

if __name__ == '__main__':
main()

0 comments on commit 385f515

Please sign in to comment.