Skip to content

Commit 68e6d85

Browse files
JeromeParrotVladimir Kotal
authored andcommitted
Add Google repo tool for syncing
1 parent bef0fe4 commit 68e6d85

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from .repository import Repository
55
from .svn import SubversionRepository
66
from .teamware import TeamwareRepository
7+
from .repo import RepoRepository
78

89
__all__ = [
910
'CVSRepository',
@@ -12,4 +13,5 @@
1213
'SubversionRepository',
1314
'TeamwareRepository',
1415
'Repository',
16+
'RepoRepository',
1517
]
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#
2+
# CDDL HEADER START
3+
#
4+
# The contents of this file are subject to the terms of the
5+
# Common Development and Distribution License (the "License").
6+
# You may not use this file except in compliance with the License.
7+
#
8+
# See LICENSE.txt included in this distribution for the specific
9+
# language governing permissions and limitations under the License.
10+
#
11+
# When distributing Covered Code, include this CDDL HEADER in each
12+
# file and include the License file at LICENSE.txt.
13+
# If applicable, add the following below this CDDL HEADER, with the
14+
# fields enclosed by brackets "[]" replaced with your own identifying
15+
# information: Portions Copyright [yyyy] [name of copyright owner]
16+
#
17+
# CDDL HEADER END
18+
#
19+
20+
#
21+
# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
22+
#
23+
24+
from ..utils.command import Command
25+
from .repository import Repository, RepositoryException
26+
from shutil import which
27+
28+
29+
class RepoRepository(Repository):
30+
def __init__(self, logger, path, project, command, env, hooks, timeout):
31+
32+
super().__init__(logger, path, project, command, env, hooks, timeout)
33+
34+
if command:
35+
self.command = command
36+
else:
37+
self.command = which("repo")
38+
39+
if not self.command:
40+
self.logger.error("Cannot get repo command")
41+
raise OSError
42+
43+
def reposync(self):
44+
repo_command = [self.command, "sync", "-cf"]
45+
cmd = self.getCommand(repo_command, work_dir=self.path,
46+
env_vars=self.env, logger=self.logger)
47+
cmd.execute()
48+
self.logger.info(cmd.getoutputstr())
49+
if cmd.getretcode() != 0 or cmd.getstate() != Command.FINISHED:
50+
cmd.log_error("failed to perform sync")
51+
return 1
52+
53+
return 0
54+
55+
def incoming(self):
56+
repo_command = [self.command, "sync", "-n"]
57+
cmd = self.getCommand(repo_command, work_dir=self.path,
58+
env_vars=self.env, logger=self.logger)
59+
cmd.execute()
60+
if cmd.getretcode() != 0 or cmd.getstate() != Command.FINISHED:
61+
cmd.log_error("failed to perform sync")
62+
raise RepositoryException('failed to check for incoming in '
63+
'repository {}'.format(self))
64+
65+
if len(cmd.getoutput()) == 0:
66+
return False
67+
else:
68+
return True

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from ..scm.mercurial import MercurialRepository
2727
from ..scm.svn import SubversionRepository
2828
from ..scm.teamware import TeamwareRepository
29+
from ..scm.repo import RepoRepository
2930

3031

3132
def get_repository(logger, path, repo_type, project, commands, env, hooks,
@@ -62,5 +63,9 @@ def get_repository(logger, path, repo_type, project, commands, env, hooks,
6263
return GitRepository(logger, path, project,
6364
commands.get("git"),
6465
env, hooks, timeout)
66+
elif repo_lower == "repo":
67+
return RepoRepository(logger, path, project,
68+
commands.get("repo"),
69+
env, hooks, timeout)
6570
else:
6671
return None

0 commit comments

Comments
 (0)