Skip to content

Commit f3fa009

Browse files
author
Vladimir Kotal
authored
make it possible to mirror more projects at once (#2731)
1 parent 79dec9c commit f3fa009

File tree

11 files changed

+629
-324
lines changed

11 files changed

+629
-324
lines changed

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

Lines changed: 49 additions & 297 deletions
Large diffs are not rendered by default.

opengrok-tools/src/main/python/opengrok_tools/scm/cvs.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#
2323

2424
from ..utils.command import Command
25-
from .repository import Repository
25+
from .repository import Repository, RepositoryException
2626
from shutil import which
2727

2828

@@ -37,8 +37,7 @@ def __init__(self, logger, path, project, command, env, hooks, timeout):
3737
self.command = which("cvs")
3838

3939
if not self.command:
40-
self.logger.error("Cannot get cvs command")
41-
raise OSError
40+
raise RepositoryException("Cannot get cvs command")
4241

4342
def reposync(self):
4443
hg_command = [self.command, "update", "-dP"]

opengrok-tools/src/main/python/opengrok_tools/scm/git.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ def __init__(self, logger, path, project, command, env, hooks, timeout):
3737
self.command = which("git")
3838

3939
if not self.command:
40-
self.logger.error("Cannot get git command")
41-
raise OSError
40+
raise RepositoryException("Cannot get git command")
4241

4342
def reposync(self):
4443
git_command = [self.command, "pull", "--ff-only"]

opengrok-tools/src/main/python/opengrok_tools/scm/mercurial.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ def __init__(self, logger, path, project, command, env, hooks, timeout):
3737
self.command = which("hg")
3838

3939
if not self.command:
40-
self.logger.error("Cannot get hg command")
41-
raise OSError
40+
raise RepositoryException("Cannot get hg command")
4241

4342
def get_branch(self):
4443
hg_command = [self.command, "branch"]

opengrok-tools/src/main/python/opengrok_tools/scm/repo.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ def __init__(self, logger, path, project, command, env, hooks, timeout):
3737
self.command = which("repo")
3838

3939
if not self.command:
40-
self.logger.error("Cannot get repo command")
41-
raise OSError
40+
raise RepositoryException("Cannot get repo command")
4241

4342
def reposync(self):
4443
repo_command = [self.command, "sync", "-cf"]

opengrok-tools/src/main/python/opengrok_tools/scm/repofactory.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,35 @@
1818
#
1919

2020
#
21-
# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
21+
# Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
2222
#
2323

24+
import logging
25+
2426
from .cvs import CVSRepository
2527
from .git import GitRepository
2628
from .mercurial import MercurialRepository
2729
from .repo import RepoRepository
2830
from .svn import SubversionRepository
2931
from .teamware import TeamwareRepository
3032

33+
logger = logging.getLogger(__name__)
34+
3135

32-
def get_repository(logger, path, repo_type, project, commands, env, hooks,
36+
def get_repository(path, repo_type, project, commands, env, hooks,
3337
timeout):
3438
"""
35-
Repository factory. Returns a Repository derived object according
36-
to the type specified or None if given repository type cannot
37-
be found.
39+
:param path: full path
40+
:param repo_type: repository type
41+
:param project: project name
42+
:param commands: commands list
43+
:param env: environment varibables dictionary
44+
:param hooks: hook dictionary
45+
:param timeout: timeout in seconds
46+
:return: a Repository derived object according to the type specified
47+
or None if given repository type cannot be found.
3848
"""
49+
3950
repo_lower = repo_type.lower()
4051

4152
logger.debug("Constructing repo object for path {}".format(path))
@@ -68,4 +79,6 @@ def get_repository(logger, path, repo_type, project, commands, env, hooks,
6879
commands.get("repo"),
6980
env, hooks, timeout)
7081
else:
82+
logger.warning("Unsupported repository type {}: {}".
83+
format(repo_type, path))
7184
return None

opengrok-tools/src/main/python/opengrok_tools/scm/svn.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#
2323

2424
from ..utils.command import Command
25-
from .repository import Repository
25+
from .repository import Repository, RepositoryException
2626
from shutil import which
2727

2828

@@ -37,8 +37,7 @@ def __init__(self, logger, path, project, command, env, hooks, timeout):
3737
self.command = which("svn")
3838

3939
if not self.command:
40-
self.logger.error("Cannot get svn command")
41-
raise OSError
40+
raise RepositoryException("Cannot get svn command")
4241

4342
def reposync(self):
4443
svn_command = [self.command]

opengrok-tools/src/main/python/opengrok_tools/scm/teamware.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#
2323

2424
from ..utils.command import Command
25-
from .repository import Repository
25+
from .repository import Repository, RepositoryException
2626
import os
2727

2828

@@ -41,21 +41,19 @@ def __init__(self, logger, path, project, command, env, hooks, timeout):
4141
#
4242
if command:
4343
if not os.path.isdir(command):
44-
self.logger.error("Cannot construct Teamware repository:"
45-
" {} is not a directory".format(command))
46-
raise OSError
44+
raise RepositoryException("Cannot construct Teamware "
45+
"repository: {} is not a "
46+
"directory".format(command))
4747

4848
try:
4949
path = os.environ['PATH']
5050
except KeyError:
51-
self.logger.error("Cannot get PATH env var")
52-
raise OSError
51+
raise OSError("Cannot get PATH env var")
5352

5453
path += ":" + command
5554
self.env['PATH'] = path
5655
else:
57-
self.logger.error("Cannot get path to Teamware commands")
58-
raise OSError
56+
raise RepositoryException("Cannot get path to Teamware commands")
5957

6058
def reposync(self):
6159
#

opengrok-tools/src/main/python/opengrok_tools/utils/log.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
#
1919

2020
#
21-
# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
21+
# Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
2222
#
2323

2424
import logging
2525
import sys
26+
import os
2627
import argparse
28+
from logging.handlers import RotatingFileHandler
2729

2830

2931
def print_exc_exit(e):
@@ -92,7 +94,8 @@ def get_class_basename():
9294
return __name__.split('.')[0]
9395

9496

95-
def get_console_logger(name, level=logging.INFO, format='%(message)s'):
97+
def get_console_logger(name=__name__, level=logging.INFO,
98+
format='%(message)s'):
9699
"""
97100
Get logger that logs logging.ERROR and higher to stderr, the rest
98101
to stdout. For logging.DEBUG level more verbose format is used.
@@ -122,7 +125,41 @@ def get_console_logger(name, level=logging.INFO, format='%(message)s'):
122125
logger = logging.getLogger(name)
123126
logger.setLevel(level)
124127
logger.propagate = False
128+
logger.handlers = []
125129
logger.addHandler(stdout_handler)
126130
logger.addHandler(stderr_handler)
127131

128132
return logger
133+
134+
135+
def get_batch_logger(logdir, project_name, loglevel, backupcount,
136+
name=__name__):
137+
"""
138+
Get rotating file logger for storing logs of mirroring of given project.
139+
:param logdir: log directory
140+
:param project_name: name of the project
141+
:param loglevel: logging level
142+
:param backupcount count of log files to keep around
143+
:param name name of the logger
144+
:return logger
145+
"""
146+
147+
logger = logging.getLogger(name)
148+
149+
logfile = os.path.join(logdir, project_name + ".log")
150+
logger.debug("Switching logging to the {} file".
151+
format(logfile))
152+
153+
handler = RotatingFileHandler(logfile, maxBytes=0, mode='a',
154+
backupCount=backupcount)
155+
formatter = logging.Formatter("%(asctime)s - %(levelname)s: "
156+
"%(message)s", '%m/%d/%Y %I:%M:%S %p')
157+
handler.setFormatter(formatter)
158+
handler.doRollover()
159+
160+
logger.setLevel(loglevel)
161+
logger.propagate = False
162+
logger.handlers = []
163+
logger.addHandler(handler)
164+
165+
return logger

0 commit comments

Comments
 (0)