def main(argv=None):
    if argv is None:
        argv = sys.argv

    logging.basicConfig()
    logger = logging.getLogger("sksync_edgui")

    # TODO proper argument parsing
    logger.setLevel(logging.INFO)
    sksync.logger.setLevel(logging.INFO)
    try:
        conf_filename = argv[1]
    except IndexError:
        conf_filename = 'sksync.json'
        # try and locate it
        if not os.path.isfile(conf_filename):
            # Under android current directory doesn't work
            conf_filename = os.path.join(os.path.dirname(__file__), conf_filename)
    logger.info('attempting to open config: %r', conf_filename)
    try:
        f = open(conf_filename, 'rb')
        config = sksync.load_json(f.read())
        f.close()
    except IOError:
        print 'config file not found, defaulting config'
        config = {}

    # defaults
    config = sksync.set_default_config(config)

    sksync.easydialogs_gui(config)
    return 0
Beispiel #2
0
    def test_sync_from_server_with_times_to_empty_client_directory(self):
        # Expect SSL errors if SSL requested but no SSL cert/key specified
        safe_rmtree(self.client_dir)
        safe_mkdir(self.client_dir)
        result = os.path.isdir(self.server_dir)

        # clone of self.perform_sync(server_dir, client_dir,
        HOST = '127.0.0.1'
        PORT = get_random_port()
        config = self.config
        server_dir, client_dir = self.server_dir, self.client_dir
        recursive = True

        config['host'] = HOST
        config['port'] = PORT
        #config['server_path'] = server_dir
        #config['client_path'] = client_dir
        config['clients'] = config.get('clients', {})
        config['clients']['testing'] = {}
        config['clients']['testing']['server_path'] = server_dir
        config['clients']['testing']['client_path'] = client_dir
        config['clients']['testing']['recursive'] = recursive
        config = sksync.set_default_config(config)
        server_config = config.copy()
        # TODO do NOT run server threaded, create thread for client. Then use assertRaises() for server
        server_config['raise_errors'] = False

        # Start sync server in thread
        server = sksync.MyThreadedTCPServer((HOST, PORT), sksync.MyTCPHandler)
        try:
            host, port = server.server_address
            server.sksync_config = server_config

            # Start a thread with the server, in turn that thread will then start additional threads
            # One additional thread for each client request/connection
            server_thread = threading.Thread(target=server.serve_forever)
            # Exit the server thread when the main thread terminates
            server_thread.daemon = True
            server_thread.start()

            def local_func_run_client():
                # do sync
                sksync.run_client(config, config_name='testing')

            self.assertRaises(sksync.ssl.SSLError, local_func_run_client)
        finally:
            server.shutdown()
Beispiel #3
0
    def perform_sync(self,
                     server_dir,
                     client_dir,
                     HOST='127.0.0.1',
                     PORT=get_random_port(),
                     recursive=False,
                     config=None):
        config = config or {}
        config['host'] = HOST
        config['port'] = PORT
        config['require_auth'] = config.get('require_auth', False)
        #config['server_path'] = server_dir
        #config['client_path'] = client_dir
        config['clients'] = config.get('clients', {})
        config['clients']['testing'] = {}

        #config['clients']['testing']['server_path'] = client_dir  # NOTE switch client/server directory
        #config['clients']['testing']['client_path'] = server_dir  # NOTE switch client/server directory
        config['clients']['testing']['server_path'] = server_dir
        config['clients']['testing']['client_path'] = client_dir

        config['clients']['testing']['recursive'] = recursive
        config['clients']['testing'][
            'sync_type'] = sksync.SKSYNC_PROTOCOL_TYPE_BIDIRECTIONAL_USE_TIME
        config = sksync.set_default_config(config)

        # Start sync server in thread
        server = sksync.MyThreadedTCPServer((HOST, PORT), sksync.MyTCPHandler)
        try:
            host, port = server.server_address
            server.sksync_config = config

            # Start a thread with the server, in turn that thread will then start additional threads
            # One additional thread for each client request/connection
            server_thread = threading.Thread(target=server.serve_forever)
            # Exit the server thread when the main thread terminates
            server_thread.daemon = True
            server_thread.start()
            #print "Server loop running in thread:", server_thread.name

            # do sync
            sksync.run_client(config, config_name='testing')
        finally:
            server.shutdown()