Beispiel #1
0
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
Created on 2015-09-14

@author: Elem

'''

from utils import SyncFiles, execute_cmd

from isync_logger import logger_init
LOGGER = logger_init('pyisync.isync_server')


class SyncServer(object):
    """Real-time sync server
    """
    def __init__(self, remote_ip_lst=None):
        """
        Constructor
        """
        self.sync_files = SyncFiles()
        if remote_ip_lst is None:
            self.remote_ip_lst = []
        self.remote_ip_lst = remote_ip_lst

    def start(self):
        """启动实时同步配置文件接受端"""
        # 初始化rsync配置文件
        self.sync_files.update_rsyncd_conf(self.remote_ip_lst)
Beispiel #2
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on 2015-9-14

@author: Elem
'''
from argparse import ArgumentParser

from isync_client import SyncClient
from isync_server import SyncServer

from isync_logger import logger_init
LOGGER = logger_init('pyisync')

if __name__ == '__main__':
    prog_desc = 'Real-time client command'
    parser = ArgumentParser(description=prog_desc)
    type_help = 'start type, client or server'
    parser.add_argument('--type',
                        type=str,
                        choices=['client', 'server'],
                        default='client',
                        help=type_help)
    host_help = "Remote host address. e.g.:1.1.1.1,2.2.2.2"
    parser.add_argument('--host', type=str, required=True, help=host_help)
    args = parser.parse_args()

    hosts = args.host.split(',')
    if not hosts:
        print 'Err:host argument must be not null.'
Beispiel #3
0
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Created on 2015-9-14

@author: Elem
"""
import os
import subprocess
from xml.etree import ElementTree

from common import SyncConf
from isync_logger import logger_init

LOGGER = logger_init("hasync.sync_utils")


def daemonize():
    """Turn the process into daemon.

    Goes background and disables all i/o.
    """
    # launch new process, kill parent
    pid = os.fork()
    if pid != 0:
        os._exit(0)

    # start new session
    os.setsid()

    # stop i/o
Beispiel #4
0
from collections import deque
from Queue import Queue
import traceback

from  pyinotify import  WatchManager, ThreadedNotifier, ExcludeFilter, \
                        IN_DELETE, IN_CREATE, IN_CLOSE_WRITE, IN_MOVED_TO, \
                        IN_MOVED_FROM


from file_watch import EventHandler, SyncThreadManager, \
                RetryThread
from common import SyncConf
from utils import SyncFiles

from isync_logger import logger_init
LOGGER = logger_init('pyisync.isync_client')



class SyncClient(object):
    """Real-time sync client
    """

    def __init__(self, remote_ip_lst, local_ip=''):
        """
        Constructor
        """
        self.sync_files = SyncFiles()
        self.local_ip = local_ip
        self.remote_ip_lst = remote_ip_lst
        self.client_notifier = None
Beispiel #5
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on 2015-9-14

@author: Elem
"""
from argparse import ArgumentParser

from isync_client import SyncClient
from isync_server import SyncServer

from isync_logger import logger_init

LOGGER = logger_init("pyisync")

if __name__ == "__main__":
    prog_desc = "Real-time client command"
    parser = ArgumentParser(description=prog_desc)
    type_help = "start type, client or server"
    parser.add_argument("--type", type=str, choices=["client", "server"], default="client", help=type_help)
    host_help = "Remote host address. e.g.:1.1.1.1,2.2.2.2"
    parser.add_argument("--host", type=str, required=True, help=host_help)
    args = parser.parse_args()

    hosts = args.host.split(",")
    if not hosts:
        print "Err:host argument must be not null."
        print parser.print_help()

    if args.type == "client":
Beispiel #6
0
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
Created on 2015-9-14

@author: Elem
'''
import os
import subprocess
from xml.etree import ElementTree

from common import SyncConf
from isync_logger import logger_init
LOGGER = logger_init('hasync.sync_utils')


def daemonize():
    """Turn the process into daemon.

    Goes background and disables all i/o.
    """
    # launch new process, kill parent
    pid = os.fork()
    if pid != 0:
        os._exit(0)

    # start new session
    os.setsid()

    # stop i/o
    fd = os.open("/dev/null", os.O_RDWR)
Beispiel #7
0
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
Created on 2015-09-14

@author: Elem

'''


from utils import SyncFiles, execute_cmd

from isync_logger import logger_init
LOGGER = logger_init('pyisync.isync_server')



class SyncServer(object):
    """Real-time sync server
    """

    def __init__(self, remote_ip_lst=None):
        """
        Constructor
        """
        self.sync_files = SyncFiles()
        if remote_ip_lst is None:
            self.remote_ip_lst = []
        self.remote_ip_lst = remote_ip_lst

    def start(self):
Beispiel #8
0
@author: Elem
'''
import re
import time
import threading
import subprocess
from collections import deque

from  pyinotify import  WatchManager, ThreadedNotifier, \
        ProcessEvent, ExcludeFilter, IN_DELETE, IN_CREATE, \
        IN_CLOSE_WRITE, IN_MOVED_FROM, IN_MOVED_TO

from utils import SyncFiles
from common import SyncConf
from isync_logger import logger_init
LOGGER = logger_init('pyisync.sync_utils')


class RetryThread(threading.Thread):
    """ sync retry thread
    """
    def __init__(self,
                 name,
                 retryq,
                 remote_ip_lst=None,
                 retry_interval=120,
                 crontab=3600):
        """ init func

        @param name: thread name
        @type name: str