47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
import os
|
|
import json
|
|
import subprocess
|
|
|
|
def read_file(filepath):
|
|
"""读取文件内容"""
|
|
try:
|
|
with open(filepath, 'r', encoding='utf-8') as f:
|
|
return f.read()
|
|
except Exception as e:
|
|
print(f"Error reading {filepath}: {e}")
|
|
return None
|
|
|
|
def main():
|
|
# 获取所有Java文件
|
|
result = subprocess.run(
|
|
['find', 'src', '-type', 'f', '-name', '*.java'],
|
|
capture_output=True,
|
|
text=True
|
|
)
|
|
files = result.stdout.strip().split('\n')
|
|
files = [f for f in files if f]
|
|
|
|
print(f"Total files: {len(files)}")
|
|
|
|
# 创建JSON格式的文件列表
|
|
file_list = []
|
|
for filepath in files:
|
|
content = read_file(filepath)
|
|
if content:
|
|
file_list.append({
|
|
'path': filepath,
|
|
'content': content
|
|
})
|
|
print(f"Prepared: {filepath}")
|
|
|
|
# 输出JSON
|
|
with open('/tmp/files_to_push.json', 'w', encoding='utf-8') as f:
|
|
json.dump(file_list, f, ensure_ascii=False, indent=2)
|
|
|
|
print(f"\nTotal files prepared: {len(file_list)}")
|
|
print("Files saved to /tmp/files_to_push.json")
|
|
|
|
if __name__ == '__main__':
|
|
main()
|