def start_server(directory, port, token, pidfile, file_size_limit, min_chunk_size, max_chunk_size): """ Start a daemonized server. This is a server-related command that start a daemonized server (detached from the shell). Unlike the run command, it accepts the --pidfile flag which tells the pidfile location. By default, the pidfile is created in the current working directory and named 'daemon.pid'. Refer to the run command for more information. """ if not token: token = generate_token() display_generated_token(token) try: server = Server(directory, token, file_size_limit, min_chunk_size, max_chunk_size) except NotADirectoryError: print(INVALID_ROOT_DIRECTORY_MESSAGE) exit(1) except ValueError: print(INCORRECT_VALUE_ERROR_MESSAGE) exit(1) def loop(): server.run('127.0.0.1', port) daemon = Daemon(loop, pidfile) daemon.start()
def run_server(directory, port, token, file_size_limit, min_chunk_size, max_chunk_size): """ Start a (non-daemonized) server. This is a server-related command that start a non-daemonized server (not detached from the shell). The directory parameter is the root directory which will be served and therefore must be an existing directory. The server listens on port 6768 by default but it can be changed with the port parameter. If the token is not specified, it's generated and printed out to the console before the server starts running. Additionally, the file size limit and the chunk size range can be altered. The file size limit and minimum chunk size must be both be greater than 0, and maximum chunk size must be greater or equal to minimum chunk size. """ if not token: token = generate_token() display_generated_token(token) try: server = Server(directory, token, file_size_limit, min_chunk_size, max_chunk_size) except NotADirectoryError: print(INVALID_ROOT_DIRECTORY_MESSAGE) exit(1) except ValueError: print(INCORRECT_VALUE_ERROR_MESSAGE) exit(1) server.run('127.0.0.1', port)
import os import shutil import threading from pathlib import PurePosixPath, PosixPath from tempfile import TemporaryDirectory import unittest from remofile.server import Server from remofile.client import Client from remofile.token import generate_token from remofile.protocol import * from remofile.exceptions import * HOSTNAME = '127.0.0.1' PORT = 6768 TOKEN = generate_token() class TestClient(unittest.TestCase): """ Test the client class. It consists of testing its methods that implement all native file operations. """ def setUp(self): # create local working directory self.local_directory = TemporaryDirectory() self.local_directory_path = PosixPath(self.local_directory.name) # create remote working directory self.remote_directory = TemporaryDirectory()