Skip to content

Commit 71b005e

Browse files
author
Vladimir Kotal
committed
introduce the --nolock option
1 parent bff0f6e commit 71b005e

File tree

1 file changed

+65
-53
lines changed
  • opengrok-tools/src/main/python/opengrok_tools

1 file changed

+65
-53
lines changed

opengrok-tools/src/main/python/opengrok_tools/sync.py

Lines changed: 65 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#
2020

2121
#
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.
2323
#
2424

2525
"""
@@ -51,7 +51,7 @@
5151
print("Need Python 3, you are running {}".format(major_version))
5252
sys.exit(1)
5353

54-
__version__ = "0.7"
54+
__version__ = "0.8"
5555

5656

5757
def worker(base):
@@ -66,6 +66,52 @@ def worker(base):
6666
return base
6767

6868

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+
69115
def main():
70116
dirs_to_process = []
71117

@@ -95,6 +141,10 @@ def main():
95141
parser.add_argument('-f', '--driveon', action='store_true', default=False,
96142
help='continue command sequence processing even '
97143
'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+
98148
try:
99149
args = parser.parse_args()
100150
except ValueError as e:
@@ -151,57 +201,19 @@ def main():
151201
pass
152202
logger.debug("Ignored projects: {}".format(ignore_errors))
153203

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)
205217

206218

207219
if __name__ == '__main__':

0 commit comments

Comments
 (0)