Skip to content

Commit e2f6c3e

Browse files
author
Vladimir Kotal
committed
add repository mirroring scripts
1 parent 18b8fa0 commit e2f6c3e

File tree

19 files changed

+1083
-47
lines changed

19 files changed

+1083
-47
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ Currently supported message types:
141141
* **get-repos** – get list of repositories in the form of relative paths to source root for given project(s)
142142
* **get-repos-type** – get repository type(s) for given project(s)
143143

144+
6. **RepositoryMessage** – used for getting repository info.
145+
146+
* **get-repo-type** – get repository type
147+
144148
## 4. OpenGrok install
145149

146150
### 4.1 Installing on Solaris from *.p5p file

build.xml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,9 +682,23 @@ Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
682682
<include name="Groups"/>
683683
</tarfileset>
684684
<tarfileset dir="tools/sync" prefix="${distname}-${version}/bin/" mode="555">
685-
<include name="sync.py"/>
686685
<include name="command.py"/>
687686
<include name="commands.py"/>
687+
<include name="cvs.py"/>
688+
<include name="filelock.py"/>
689+
<include name="git.py"/>
690+
<include name="hook.py"/>
691+
<include name="mercurial.py"/>
692+
<include name="mirror.py"/>
693+
<include name="opengrok.py"/>
694+
<include name="readconfig.py"/>
695+
<include name="repofactory.py"/>
696+
<include name="repository.py"/>
697+
<include name="svn.py"/>
698+
<include name="sync.py"/>
699+
<include name="teamware.py"/>
700+
<include name="testmercurial.py"/>
701+
<include name="utils.py"/>
688702
<include name="reindex-project.ksh"/>
689703
</tarfileset>
690704
<tarfileset dir="doc" prefix="${distname}-${version}/doc">

platform/solaris/ips/create.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,30 @@ PKG pkgsend add file tools/sync/filelock.py \
252252
mode=0555 owner=root group=bin path=/usr/opengrok/bin/filelock.py
253253
PKG pkgsend add file tools/sync/reindex-project.ksh \
254254
mode=0555 owner=root group=bin path=/usr/opengrok/bin/reindex-project.ksh
255+
PKG pkgsend add file tools/sync/cvs.py
256+
mode=0555 owner=root group=bin path=/usr/opengrok/bin/cvs.py
257+
PKG pkgsend add file tools/sync/git.py
258+
mode=0555 owner=root group=bin path=/usr/opengrok/bin/git.py
259+
PKG pkgsend add file tools/sync/hook.py
260+
mode=0555 owner=root group=bin path=/usr/opengrok/bin/hook.py
261+
PKG pkgsend add file tools/sync/mercurial.py
262+
mode=0555 owner=root group=bin path=/usr/opengrok/bin/mercurial.py
263+
PKG pkgsend add file tools/sync/mirror.py
264+
mode=0555 owner=root group=bin path=/usr/opengrok/bin/mirror.py
265+
PKG pkgsend add file tools/sync/opengrok.py
266+
mode=0555 owner=root group=bin path=/usr/opengrok/bin/opengrok.py
267+
PKG pkgsend add file tools/sync/readconfig.py
268+
mode=0555 owner=root group=bin path=/usr/opengrok/bin/readconfig.py
269+
PKG pkgsend add file tools/sync/repofactory.py
270+
mode=0555 owner=root group=bin path=/usr/opengrok/bin/repofactory.py
271+
PKG pkgsend add file tools/sync/repository.py
272+
mode=0555 owner=root group=bin path=/usr/opengrok/bin/repository.py
273+
PKG pkgsend add file tools/sync/svn.py
274+
mode=0555 owner=root group=bin path=/usr/opengrok/bin/svn.py
275+
PKG pkgsend add file tools/sync/teamware.py
276+
mode=0555 owner=root group=bin path=/usr/opengrok/bin/teamware.py
277+
PKG pkgsend add file tools/sync/utils.py
278+
mode=0555 owner=root group=bin path=/usr/opengrok/bin/utils.py
255279

256280
PKG pkgsend add file dist/opengrok.jar \
257281
mode=0444 owner=root group=bin path=/usr/opengrok/lib/opengrok.jar

tools/sync/README

Lines changed: 0 additions & 29 deletions
This file was deleted.

tools/sync/README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
2+
Set of scripts to facilitate parallel project synchronization and mirroring
3+
4+
Use e.g. like this:
5+
6+
# sync.py -c /scripts/sync.conf -d /ws-local/ -p
7+
8+
where the sync.conf file contents might look like this:
9+
10+
```
11+
{
12+
"commands": [["/usr/opengrok/bin/Messages", "-c", "info", "-e", "+1 hour",
13+
"-n", "normal", "-t", "ARG", "resync + reindex in progress"],
14+
["sudo", "-u", "wsmirror", "/usr/opengrok/bin/mirror.py",
15+
"-c", "/opengrok/etc/mirror-config.yml", "-b",
16+
"--messages", "/usr/opengrok/bin/Messages"],
17+
["sudo", "-u", "webservd", "/usr/opengrok/bin/reindex-project.ksh",
18+
"/opengrok/etc/opengrok.conf", "/usr/opengrok/bin"],
19+
["/usr/opengrok/bin/Messages", "-n", "abort", "-t"],
20+
["/scripts/check-indexer-logs.ksh"]]
21+
}
22+
```
23+
24+
The commands got appended project name unless one of their arguments is equal
25+
to 'ARG', in which case it is substituted with project name and no append is
26+
done.
27+
28+
For per-project reindexing to work properly, reindex-project.ksh uses
29+
the logging.properties.template to make sure each project has its own
30+
log directory.
31+
32+
The mirror-config.yml can look e.g. like this:
33+
34+
```
35+
#
36+
# Commands (or paths - for specific repository types only)
37+
#
38+
commands:
39+
hg: /usr/bin/hg
40+
svn: /usr/bin/svn
41+
teamware: /ontools/onnv-tools-i386/teamware/bin
42+
#
43+
# The proxy environment variables will be set for a project's repositories
44+
# if the 'proxy' property is True.
45+
#
46+
proxy:
47+
http_proxy: proxy.example.com:80
48+
https_proxy: proxy.example.com:80
49+
ftp_proxy: proxy.example.com:80
50+
no_proxy: example.com,foo.example.com
51+
hookdir: /tmp/hooks
52+
# per-project hooks relative to 'hookdir' above
53+
logdir: /tmp/logs
54+
#
55+
# Per project configuration.
56+
#
57+
projects:
58+
http:
59+
proxy: true
60+
history:
61+
disable: true
62+
userland:
63+
proxy: true
64+
hooks:
65+
pre: userland-pre.ksh
66+
post: userland-post.ksh
67+
```
68+
69+
See https://github.com/OpenGrok/OpenGrok/wiki/Per-project-management
70+
for more details on per-project management.

tools/sync/command.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#
1919

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

2424
import os
@@ -40,10 +40,12 @@ class Command:
4040
ERRORED = "errored"
4141

4242
def __init__(self, cmd, args_subst=None, args_append=None, logger=None,
43-
excl_subst=False):
43+
excl_subst=False, work_dir=None, env_vars=None):
4444
self.cmd = cmd
4545
self.state = "notrun"
4646
self.excl_subst = excl_subst
47+
self.work_dir = work_dir
48+
self.env_vars = env_vars
4749

4850
self.logger = logger or logging.getLogger(__name__)
4951
logging.basicConfig()
@@ -96,11 +98,27 @@ def fileno(self):
9698
def close(self):
9799
os.close(self.write_fd)
98100

101+
if self.work_dir:
102+
try:
103+
os.chdir(self.work_dir)
104+
except OSError as e:
105+
self.state = Command.ERRORED
106+
self.logger.error("Cannot change working directory to {}".
107+
format(self.work_dir))
108+
return
109+
99110
othr = OutputThread()
100111
try:
112+
self.logger.debug("working directory = {}".format(os.getcwd()))
101113
self.logger.debug("command = {}".format(self.cmd))
102-
p = subprocess.Popen(self.cmd, stderr=subprocess.STDOUT,
103-
stdout=othr)
114+
if self.env_vars:
115+
my_env = os.environ.copy()
116+
my_env.update(self.env_vars)
117+
p = subprocess.Popen(self.cmd, stderr=subprocess.STDOUT,
118+
stdout=othr, env=my_env)
119+
else:
120+
p = subprocess.Popen(self.cmd, stderr=subprocess.STDOUT,
121+
stdout=othr)
104122
p.wait()
105123
except KeyboardInterrupt as e:
106124
self.logger.debug("Got KeyboardException while processing ",

tools/sync/cvs.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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 command import Command
25+
from repository import Repository
26+
from utils import which
27+
28+
29+
class CVSRepository(Repository):
30+
def __init__(self, logger, path, project, command, env, hooks):
31+
32+
super().__init__(logger, path, project, command, env, hooks)
33+
34+
if command:
35+
self.command = command
36+
else:
37+
self.command = which("cvs")
38+
39+
if not self.command:
40+
self.logger.error("Cannot get cvs command")
41+
raise OSError
42+
43+
def reposync(self):
44+
hg_command = [self.command, "update", "-dP"]
45+
cmd = Command(hg_command, work_dir=self.path, env_vars=self.env)
46+
cmd.execute()
47+
self.logger.info(cmd.getoutput())
48+
if cmd.getretcode() != 0 or cmd.getstate() != Command.FINISHED:
49+
self.logger.error("failed to perform update for {}".
50+
format(self.path))
51+
return 1
52+
53+
return 0

tools/sync/git.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 command import Command
25+
from repository import Repository
26+
from utils import which
27+
28+
class GitRepository(Repository):
29+
def __init__(self, logger, path, project, command, env, hooks):
30+
31+
super().__init__(logger, path, project, command, env, hooks)
32+
33+
if command:
34+
self.command = command
35+
else:
36+
self.command = which("git")
37+
38+
if not self.command:
39+
self.logger.error("Cannot get git command")
40+
raise OSError
41+
42+
def reposync(self):
43+
hg_command = [self.command, "pull", "--ff-only"]
44+
cmd = Command(hg_command, work_dir=self.path, env_vars=self.env)
45+
cmd.execute()
46+
self.logger.info(cmd.getoutput())
47+
if cmd.getretcode() != 0 or cmd.getstate() != Command.FINISHED:
48+
self.logger.error("failed to perform pull for {}".
49+
format(self.path))
50+
return 1
51+
52+
return 0

tools/sync/hook.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
import os
25+
from command import Command
26+
import logging
27+
28+
def run_hook(logger, script, path):
29+
"""
30+
Change a working directory to specified path, run a command
31+
and change the working directory back to its original value.
32+
33+
Return 0 on success, 1 on failure.
34+
"""
35+
36+
orig_cwd = os.getcwd()
37+
38+
try:
39+
os.chdir(path)
40+
except:
41+
logger.error("Cannot chdir to {}".format(path))
42+
return 1
43+
44+
cmd = Command([script])
45+
cmd.execute()
46+
if cmd.state is not "finished" or cmd.getretcode() != 0:
47+
logger.error("failed to execute {}".format(cmd))
48+
logger.debug(cmd.getoutput())
49+
return 1
50+
51+
logger.info(cmd.getoutput())
52+
53+
try:
54+
os.chdir(orig_cwd)
55+
except:
56+
logger.error("Cannot chdir to {}".format(orig_cwd))
57+
return 1
58+
59+
return 0

0 commit comments

Comments
 (0)