19
19
#
20
20
21
21
#
22
- # Copyright (c) 2017, 2019 , Oracle and/or its affiliates. All rights reserved.
22
+ # Copyright (c) 2017, 2020 , Oracle and/or its affiliates. All rights reserved.
23
23
#
24
24
25
25
"""
51
51
print ("Need Python 3, you are running {}" .format (major_version ))
52
52
sys .exit (1 )
53
53
54
- __version__ = "0.7 "
54
+ __version__ = "0.8 "
55
55
56
56
57
57
def worker (base ):
@@ -66,6 +66,52 @@ def worker(base):
66
66
return base
67
67
68
68
69
+ def do_sync (args , commands , config , directory , dirs_to_process , ignore_errors ,
70
+ logger , uri ):
71
+
72
+ if args .projects :
73
+ dirs_to_process = args .projects
74
+ logger .debug ("Processing directories: {}" .
75
+ format (dirs_to_process ))
76
+ elif args .indexed :
77
+ indexed_projects = list_indexed_projects (logger , uri )
78
+ logger .debug ("Processing indexed projects: {}" .
79
+ format (indexed_projects ))
80
+
81
+ if indexed_projects :
82
+ for line in indexed_projects :
83
+ dirs_to_process .append (line .strip ())
84
+ else :
85
+ logger .error ("cannot get list of projects" )
86
+ sys .exit (FAILURE_EXITVAL )
87
+ else :
88
+ logger .debug ("Processing directory {}" .format (directory ))
89
+ for entry in os .listdir (directory ):
90
+ if path .isdir (path .join (directory , entry )):
91
+ dirs_to_process .append (entry )
92
+ logger .debug ("to process: {}" .format (dirs_to_process ))
93
+ cmds_base = []
94
+ for d in dirs_to_process :
95
+ cmd_base = CommandSequenceBase (d , commands , args .loglevel ,
96
+ config .get ("cleanup" ),
97
+ args .driveon )
98
+ cmds_base .append (cmd_base )
99
+ # Map the commands into pool of workers so they can be processed.
100
+ with Pool (processes = int (args .workers )) as pool :
101
+ try :
102
+ cmds_base_results = pool .map (worker , cmds_base , 1 )
103
+ except KeyboardInterrupt :
104
+ sys .exit (FAILURE_EXITVAL )
105
+ else :
106
+ for cmds_base in cmds_base_results :
107
+ logger .debug ("Checking results of project {}" .
108
+ format (cmds_base ))
109
+ cmds = CommandSequence (cmds_base )
110
+ cmds .fill (cmds_base .retcodes , cmds_base .outputs ,
111
+ cmds_base .failed )
112
+ cmds .check (ignore_errors )
113
+
114
+
69
115
def main ():
70
116
dirs_to_process = []
71
117
@@ -95,6 +141,10 @@ def main():
95
141
parser .add_argument ('-f' , '--driveon' , action = 'store_true' , default = False ,
96
142
help = 'continue command sequence processing even '
97
143
'if one of the commands requests break' )
144
+ parser .add_argument ('--nolock' , action = 'store_false' , default = True ,
145
+ help = 'do not acquire lock that prevents multiple '
146
+ 'instances from running' )
147
+
98
148
try :
99
149
args = parser .parse_args ()
100
150
except ValueError as e :
@@ -151,57 +201,19 @@ def main():
151
201
pass
152
202
logger .debug ("Ignored projects: {}" .format (ignore_errors ))
153
203
154
- lock = FileLock (os .path .join (tempfile .gettempdir (),
155
- "opengrok-sync.lock" ))
156
- try :
157
- with lock .acquire (timeout = 0 ):
158
- if args .projects :
159
- dirs_to_process = args .projects
160
- logger .debug ("Processing directories: {}" .
161
- format (dirs_to_process ))
162
- elif args .indexed :
163
- indexed_projects = list_indexed_projects (logger , uri )
164
- logger .debug ("Processing indexed projects: {}" .
165
- format (indexed_projects ))
166
-
167
- if indexed_projects :
168
- for line in indexed_projects :
169
- dirs_to_process .append (line .strip ())
170
- else :
171
- logger .error ("cannot get list of projects" )
172
- sys .exit (FAILURE_EXITVAL )
173
- else :
174
- logger .debug ("Processing directory {}" .format (directory ))
175
- for entry in os .listdir (directory ):
176
- if path .isdir (path .join (directory , entry )):
177
- dirs_to_process .append (entry )
178
-
179
- logger .debug ("to process: {}" .format (dirs_to_process ))
180
-
181
- cmds_base = []
182
- for d in dirs_to_process :
183
- cmd_base = CommandSequenceBase (d , commands , args .loglevel ,
184
- config .get ("cleanup" ),
185
- args .driveon )
186
- cmds_base .append (cmd_base )
187
-
188
- # Map the commands into pool of workers so they can be processed.
189
- with Pool (processes = int (args .workers )) as pool :
190
- try :
191
- cmds_base_results = pool .map (worker , cmds_base , 1 )
192
- except KeyboardInterrupt :
193
- sys .exit (FAILURE_EXITVAL )
194
- else :
195
- for cmds_base in cmds_base_results :
196
- logger .debug ("Checking results of project {}" .
197
- format (cmds_base ))
198
- cmds = CommandSequence (cmds_base )
199
- cmds .fill (cmds_base .retcodes , cmds_base .outputs ,
200
- cmds_base .failed )
201
- cmds .check (ignore_errors )
202
- except Timeout :
203
- logger .warning ("Already running, exiting." )
204
- sys .exit (FAILURE_EXITVAL )
204
+ if args .nolock :
205
+ do_sync (args , commands , config , directory , dirs_to_process ,
206
+ ignore_errors , logger , uri )
207
+ else :
208
+ lock = FileLock (os .path .join (tempfile .gettempdir (),
209
+ "opengrok-sync.lock" ))
210
+ try :
211
+ with lock .acquire (timeout = 0 ):
212
+ do_sync (args , commands , config , directory , dirs_to_process ,
213
+ ignore_errors , logger , uri )
214
+ except Timeout :
215
+ logger .warning ("Already running, exiting." )
216
+ sys .exit (FAILURE_EXITVAL )
205
217
206
218
207
219
if __name__ == '__main__' :
0 commit comments