Merge branch 'master' of github.com:tuna/tunasync

This commit is contained in:
tuna-mirror-server 2016-01-15 02:46:42 +08:00
commit 026921e050
7 changed files with 58 additions and 25 deletions

View File

@ -2,5 +2,6 @@
echo $TUNASYNC_WORKING_DIR
echo $TUNASYNC_LOG_FILE
echo $TUNASYNC_UPSTREAM_URL
echo $REPO
sleep 5
exit 1

View File

@ -58,5 +58,18 @@ command = "./shell_provider.sh"
upstream = "https://pypi.python.org/"
# log_file = "/tmp/arch4-{date}.log"
use_btrfs = false
# set environment varialbes
[mirrors.env]
REPO = "/usr/local/bin/repo"
# vim: ft=toml
[[mirrors]]
name = "arch5"
provider = "shell"
command = "./shell_provider.sh"
upstream = "https://pypi.python.org/"
# log_file = "/tmp/arch4-{date}.log"
use_btrfs = false
[mirrors.env]
REPO = "/usr/local/bin/repo2"
# vim: ft=toml ts=2 sts=2 sw=2

View File

@ -1,4 +1,3 @@
setproctitle==1.1.8
sh==1.09
toml==0.8.2
wsgiref==0.1.2
setproctitle==1.1.9
sh==1.11
toml==0.9.1

View File

@ -1,18 +0,0 @@
#!/bin/bash
function sync_android() {
cd $TUNASYNC_WORKING_DIR
/usr/local/bin/android-repo sync -f
}
function update_repo_config() {
for repo in $(find $TUNASYNC_WORKING_DIR -type d -not -path "*/.repo/*" -name "*.git")
do
cd $repo
echo $repo
git config pack.threads 1
done
}
sync_android
update_repo_config

21
scripts/aosp.sh Executable file
View File

@ -0,0 +1,21 @@
#!/bin/bash
REPO=${REPO:-"/usr/local/bin/repo"}
function repo_init() {
mkdir -p $TUNASYNC_WORKING_DIR
cd $TUNASYNC_WORKING_DIR
$REPO init -u https://android.googlesource.com/mirror/manifest --mirror
}
function repo_sync() {
cd $TUNASYNC_WORKING_DIR
$REPO sync -f
}
if [ ! -d "$TUNASYNC_WORKING_DIR/git-repo.git" ]; then
echo "Initializing AOSP mirror"
repo_init
fi
repo_sync

View File

@ -53,6 +53,9 @@ class MirrorConfig(object):
self.options["use_btrfs"] = self._parent.use_btrfs
assert self.options["use_btrfs"] in (True, False)
if "env" in self.options:
assert isinstance(self.options["env"], dict)
def __getattr__(self, key):
if key in self.__dict__:
return self.__dict__[key]
@ -68,6 +71,7 @@ class MirrorConfig(object):
'log_dir': self.log_dir,
'log_file': self.log_file,
'interval': self.interval,
'env': self.env,
'hooks': hooks,
}

View File

@ -65,7 +65,7 @@ class RsyncProvider(MirrorProvider):
def __init__(self, name, upstream_url, local_dir, log_dir,
useIPv6=True, password=None, exclude_file=None,
log_file="/dev/null", interval=120, hooks=[]):
log_file="/dev/null", interval=120, env=None, hooks=[]):
super(RsyncProvider, self).__init__(name, local_dir, log_dir, log_file,
interval, hooks)
@ -73,6 +73,7 @@ class RsyncProvider(MirrorProvider):
self.useIPv6 = useIPv6
self.exclude_file = exclude_file
self.password = password
self.env = env
@property
def options(self):
@ -99,6 +100,9 @@ class RsyncProvider(MirrorProvider):
new_env = os.environ.copy()
if self.password is not None:
new_env["RSYNC_PASSWORD"] = self.password
if self.env is not None and isinstance(self.env, dict):
for k, v in self.env.items():
new_env[k] = v
self.p = sh.rsync(*_args, _env=new_env, _out=log_file,
_err_to_out=True, _out_bufsize=1, _bg=True)
@ -153,6 +157,9 @@ class TwoStageRsyncProvider(RsyncProvider):
new_env = os.environ.copy()
if self.password is not None:
new_env["RSYNC_PASSWORD"] = self.password
if self.env is not None and isinstance(self.env, dict):
for k, v in self.env.items():
new_env[k] = v
with open(log_file, 'w', buffering=1) as f:
def log_output(line):
@ -175,13 +182,15 @@ class TwoStageRsyncProvider(RsyncProvider):
class ShellProvider(MirrorProvider):
def __init__(self, name, command, upstream_url, local_dir, log_dir,
log_file="/dev/null", log_stdout=True, interval=120, hooks=[]):
log_file="/dev/null", log_stdout=True, interval=120, env=None,
hooks=[]):
super(ShellProvider, self).__init__(name, local_dir, log_dir, log_file,
interval, hooks)
self.upstream_url = str(upstream_url)
self.command = shlex.split(command)
self.log_stdout = log_stdout
self.env = env
def run(self, ctx={}):
@ -194,6 +203,10 @@ class ShellProvider(MirrorProvider):
new_env["TUNASYNC_UPSTREAM_URL"] = self.upstream_url
new_env["TUNASYNC_LOG_FILE"] = log_file
if self.env is not None and isinstance(self.env, dict):
for k, v in self.env.items():
new_env[k] = v
_cmd = self.command[0]
_args = [] if len(self.command) == 1 else self.command[1:]