mirror of
https://github.com/tuna/tunasync.git
synced 2025-04-21 04:42:46 +00:00
add and options
This commit is contained in:
parent
162ffd130c
commit
0b4c5b9cb9
@ -31,6 +31,7 @@ provider = "shell"
|
||||
command = "sleep 10"
|
||||
local_dir = "/mnt/sdb1/mirror/archlinux/current/"
|
||||
# log_file = "/dev/null"
|
||||
exec_post_sync = "/bin/bash -c 'date --utc \"+%s\" > ${TUNASYNC_WORKING_DIR}/.timestamp'"
|
||||
|
||||
[[mirrors]]
|
||||
name = "arch2"
|
||||
|
35
tunasync/exec_pre_post.py
Normal file
35
tunasync/exec_pre_post.py
Normal file
@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding:utf-8 -*-
|
||||
import os
|
||||
import sh
|
||||
import shlex
|
||||
from .hook import JobHook
|
||||
|
||||
|
||||
class CmdExecHook(JobHook):
|
||||
POST_SYNC = "post_sync"
|
||||
PRE_SYNC = "pre_sync"
|
||||
|
||||
def __init__(self, command, exec_at=POST_SYNC):
|
||||
self.command = shlex.split(command)
|
||||
if exec_at == self.POST_SYNC:
|
||||
self.before_job = self._keep_calm
|
||||
self.after_job = self._exec
|
||||
elif exec_at == self.PRE_SYNC:
|
||||
self.before_job = self._exec
|
||||
self.after_job = self._keep_calm
|
||||
|
||||
def _keep_calm(self, ctx={}, **kwargs):
|
||||
pass
|
||||
|
||||
def _exec(self, ctx={}, **kwargs):
|
||||
new_env = os.environ.copy()
|
||||
new_env["TUNASYNC_MIRROR_NAME"] = ctx["mirror_name"]
|
||||
new_env["TUNASYNC_WORKING_DIR"] = ctx["current_dir"]
|
||||
|
||||
_cmd = self.command[0]
|
||||
_args = [] if len(self.command) == 1 else self.command[1:]
|
||||
cmd = sh.Command(_cmd)
|
||||
cmd(*_args, _env=new_env)
|
||||
|
||||
# vim: ts=4 sw=4 sts=4 expandtab
|
@ -40,6 +40,7 @@ def run_job(sema, child_q, manager_q, provider, **settings):
|
||||
manager_q.put(("UPDATE", (provider.name, status)))
|
||||
ctx = {} # put context info in it
|
||||
ctx['current_dir'] = provider.local_dir
|
||||
ctx['mirror_name'] = provider.name
|
||||
|
||||
try:
|
||||
for hook in provider.hooks:
|
||||
|
@ -5,6 +5,7 @@ from datetime import datetime
|
||||
from .mirror_provider import RsyncProvider, ShellProvider
|
||||
from .btrfs_snapshot import BtrfsHook
|
||||
from .loglimit import LogLimitHook
|
||||
from .exec_pre_post import CmdExecHook
|
||||
|
||||
|
||||
class MirrorConfig(object):
|
||||
@ -126,6 +127,15 @@ class MirrorConfig(object):
|
||||
hooks.append(BtrfsHook(service_dir, working_dir, gc_dir))
|
||||
|
||||
hooks.append(LogLimitHook())
|
||||
|
||||
if self.exec_pre_sync:
|
||||
hooks.append(
|
||||
CmdExecHook(self.exec_pre_sync, CmdExecHook.PRE_SYNC))
|
||||
|
||||
if self.exec_post_sync:
|
||||
hooks.append(
|
||||
CmdExecHook(self.exec_post_sync, CmdExecHook.POST_SYNC))
|
||||
|
||||
return hooks
|
||||
|
||||
# vim: ts=4 sw=4 sts=4 expandtab
|
||||
|
@ -2,6 +2,7 @@
|
||||
# -*- coding:utf-8 -*-
|
||||
import sh
|
||||
import os
|
||||
import shlex
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
@ -110,7 +111,7 @@ class ShellProvider(MirrorProvider):
|
||||
super(ShellProvider, self).__init__(name, local_dir, log_dir, log_file,
|
||||
interval, hooks)
|
||||
self.upstream_url = str(upstream_url)
|
||||
self.command = command.split()
|
||||
self.command = shlex.split(command)
|
||||
|
||||
def run(self, ctx={}):
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user