1
1
"""
2
- SPDX-FileCopyrightText: Copyright (c) 2023 Contributors to the
2
+ SPDX-FileCopyrightText: Copyright (c) 2023 Contributors to the
3
3
Eclipse Foundation
4
4
5
5
See the NOTICE file(s) distributed with this work for additional
34
34
PROTO_OUTPUT_DIR = os .path .abspath ("../uprotocol/proto" )
35
35
36
36
37
- def clone_or_pull (repo_url , PROTO_REPO_DIR ):
37
+ def clone_or_pull (repo_url , proto_repo_dir ):
38
38
try :
39
- repo = Repo .clone_from (repo_url , PROTO_REPO_DIR )
40
- print (f"Repository cloned successfully from { repo_url } to { PROTO_REPO_DIR } " )
39
+ repo = Repo .clone_from (repo_url , proto_repo_dir )
40
+ print (f"Repository cloned successfully from { repo_url } to { proto_repo_dir } " )
41
41
# Checkout the specific tag
42
42
repo .git .checkout (TAG_NAME )
43
43
except git .exc .GitCommandError :
44
44
try :
45
45
git_pull_command = ["git" , "pull" , "origin" , TAG_NAME ]
46
- subprocess .run (git_pull_command , cwd = PROTO_REPO_DIR , check = True )
46
+ subprocess .run (git_pull_command , cwd = proto_repo_dir , check = True )
47
47
print ("Git pull successful after clone failure." )
48
48
except subprocess .CalledProcessError as pull_error :
49
49
print (f"Error during Git pull: { pull_error } " )
50
50
51
51
52
52
def execute_maven_command (project_dir , command ):
53
53
try :
54
- with subprocess .Popen (command , cwd = os .path .join (os .getcwd (), project_dir ), shell = True , stdout = subprocess .PIPE ,
55
- stderr = subprocess .PIPE , text = True ) as process :
54
+ with subprocess .Popen (
55
+ command ,
56
+ cwd = os .path .join (os .getcwd (), project_dir ),
57
+ shell = True ,
58
+ stdout = subprocess .PIPE ,
59
+ stderr = subprocess .PIPE ,
60
+ text = True ,
61
+ ) as process :
56
62
stdout , stderr = process .communicate ()
57
63
print (stdout )
58
64
59
65
if process .returncode != 0 :
60
66
print (f"Error: { stderr } " )
61
67
else :
62
68
print ("Maven command executed successfully." )
63
- src_directory = os .path .join (os .getcwd (), project_dir , "target" , "generated-sources" , "protobuf" ,
64
- "python" )
65
- # if not os.path.exists(PROTO_OUTPUT_DIR):
66
- # os.makedirs(PROTO_OUTPUT_DIR)
69
+ src_directory = os .path .join (
70
+ os .getcwd (), project_dir , "target" , "generated-sources" , "protobuf" , "python"
71
+ )
67
72
68
73
shutil .copytree (src_directory , PROTO_OUTPUT_DIR , dirs_exist_ok = True )
69
74
process_python_protofiles (PROTO_OUTPUT_DIR )
@@ -89,8 +94,9 @@ def process_python_protofiles(directory):
89
94
file_path = os .path .join (root , file )
90
95
replace_in_file (file_path , r'import uri_pb2' , 'import uprotocol.proto.uri_pb2' )
91
96
replace_in_file (file_path , r'import uuid_pb2' , 'import uprotocol.proto.uuid_pb2' )
92
- replace_in_file (file_path , r'import uprotocol_options_pb2' ,
93
- 'import uprotocol.proto.uprotocol_options_pb2' )
97
+ replace_in_file (
98
+ file_path , r'import uprotocol_options_pb2' , 'import uprotocol.proto.uprotocol_options_pb2'
99
+ )
94
100
replace_in_file (file_path , r'import uattributes_pb2' , 'import uprotocol.proto.uattributes_pb2' )
95
101
replace_in_file (file_path , r'import upayload_pb2' , 'import uprotocol.proto.upayload_pb2' )
96
102
replace_in_file (file_path , r'import ustatus_pb2' , 'import uprotocol.proto.ustatus_pb2' )
0 commit comments