Skip to content

Commit 4de8988

Browse files
author
Vladimir Kotal
committed
add option/config for ignoring projects
1 parent a3065a2 commit 4de8988

File tree

1 file changed

+30
-7
lines changed
  • tools/src/main/python/opengrok_tools

1 file changed

+30
-7
lines changed

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

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,15 @@ def main():
131131
group1 = parser.add_mutually_exclusive_group()
132132
group1.add_argument('-d', '--directory',
133133
help='Directory to process')
134-
group1.add_argument('-P', '--projects', nargs='*',
135-
help='List of projects to process')
134+
group1.add_argument('-P', '--project', nargs='*',
135+
help='project(s) to process')
136136

137137
parser.add_argument('-I', '--indexed', action='store_true',
138138
help='Sync indexed projects only')
139139
parser.add_argument('-i', '--ignore_errors', nargs='*',
140140
help='ignore errors from these projects')
141+
parser.add_argument('--ignore_project', nargs='+',
142+
help='do not process given project(s)')
141143
parser.add_argument('-c', '--config', required=True,
142144
help='config file in JSON/YAML format')
143145
parser.add_argument('-U', '--uri', default='http://localhost:8080/source',
@@ -193,7 +195,7 @@ def main():
193195
headers.update(config_headers)
194196

195197
directory = args.directory
196-
if not args.directory and not args.projects and not args.indexed:
198+
if not args.directory and not args.project and not args.indexed:
197199
# Assume directory, get the source root value from the webapp.
198200
directory = get_config_value(logger, 'sourceRoot', uri, headers=headers)
199201
if not directory:
@@ -211,11 +213,11 @@ def main():
211213
ignore_errors = config["ignore_errors"]
212214
except KeyError:
213215
pass
214-
logger.debug("Ignored projects: {}".format(ignore_errors))
216+
logger.debug("Ignoring errors from projects: {}".format(ignore_errors))
215217

216218
dirs_to_process = []
217-
if args.projects:
218-
dirs_to_process = args.projects
219+
if args.project:
220+
dirs_to_process = args.project
219221
logger.debug("Processing directories: {}".
220222
format(dirs_to_process))
221223
elif args.indexed:
@@ -235,16 +237,37 @@ def main():
235237
if path.isdir(path.join(directory, entry)):
236238
dirs_to_process.append(entry)
237239

240+
ignored_projects = []
241+
config_ignored_projects = config.get("ignore_projects")
242+
if config_ignored_projects:
243+
logger.debug("Updating list of ignored projects list from the configuration: {}".
244+
format(config_ignored_projects))
245+
ignored_projects.extend(config_ignored_projects)
246+
247+
if args.ignore_project:
248+
logger.debug("Updating list of ignored projects based on options: {}".
249+
format(args.ignore_project))
250+
ignored_projects.extend(args.ignore_project)
251+
252+
if ignored_projects:
253+
dirs_to_process = list(set(dirs_to_process) - set(ignored_projects))
254+
logger.debug("Removing projects: {}".format(ignored_projects))
255+
238256
logger.debug("directories to process: {}".format(dirs_to_process))
239257

258+
if len(args.project) == 1:
259+
lockfile_name = args.project[0]
260+
else:
261+
lockfile_name = os.path.basename(sys.argv[0])
262+
240263
if args.nolock:
241264
r = do_sync(args.loglevel, commands, config.get("cleanup"),
242265
dirs_to_process,
243266
ignore_errors, uri, args.workers,
244267
driveon=args.driveon, http_headers=headers)
245268
else:
246269
lock = FileLock(os.path.join(tempfile.gettempdir(),
247-
"opengrok-sync.lock"))
270+
lockfile_name + ".lock"))
248271
try:
249272
with lock.acquire(timeout=0):
250273
r = do_sync(args.loglevel, commands, config.get("cleanup"),

0 commit comments

Comments
 (0)