From d20e88b51403254a6f9dfb208c2aad4b50a8e745 Mon Sep 17 00:00:00 2001 From: Razvan Deaconescu Date: Sun, 21 Aug 2011 20:34:47 +0300 Subject: [PATCH] Add add_client_session to TreeTextFileAccess. --- ppf/new/storage.py | 57 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 7 deletions(-) diff --git a/ppf/new/storage.py b/ppf/new/storage.py index 92ab3a9..8fb9435 100644 --- a/ppf/new/storage.py +++ b/ppf/new/storage.py @@ -20,7 +20,7 @@ logger.setLevel(logging.DEBUG) # Create console handler and set level to ERROR. ch = logging.StreamHandler() -ch.setLevel(logging.ERROR) +ch.setLevel(logging.DEBUG) # Create formatter. formatter = logging.Formatter('%(filename)s:%(lineno)s - %(levelname)s: %(message)s') @@ -126,13 +126,13 @@ class Swarm(object): class ClientSession(object): """ Class mimics a C structure. """ - def __init__(self, swarm_id=None, btclient_id=None, system_os=None, + def __init__(self, swarm_id=None, btclient=None, system_os=None, system_os_version=None, system_ram=None, system_cpu=None, public_ip=None, public_port=None, ds_limit=None, us_limit=None, start_time=None, dht_enabled=None, pxe_enabled=None, streaming_enabled=None, features=None, description=None): self.swarm_id = swarm_id - self.btclient_id = btclient_id + self.btclient = btclient self.system_os = system_os self.system_os_version = system_os_version self.system_ram = system_ram @@ -307,14 +307,57 @@ class TreeTextFileAccess(FileAccess): swarm_config = os.path.join(swarm_path, "swarm.conf") f = open(swarm_config, 'w') f.write("""id = %s - self.torrent_filename = %s - self.data_size = %s - self.description = %s + torrent_filename = %s + data_size = %s + description = %s """ %(id, swarm.torrent_filename, swarm.data_size, swarm.description)) f.close() def add_client_session(self, session): - pass + """ + Create session subfolder in swarm subfolder and add config file. + TODO: Throw exception in case swarm subfolder doesn't exist. + """ + swarm_path = os.path.join(self.base_path, str(session.swarm_id)) + + # Search first available folder in swarm_path. + id = find_last_numeric_subfolder(swarm_path) + if id == None: + id = 1 + else: + id = id+1 + + # Create session subfolder. + session_path = os.path.join(swarm_path, str(id)) + os.mkdir(session_path) + + # Create and populate configuration file. + session_config = os.path.join(session_path, "client_session.conf") + f = open(session_config, 'w') + f.write("""id = %s + swarm_id = %s + btclient = %s + system_os = %s + system_os_version = %s + system_ram = %s + system_cpu = %s + public_ip = %s + public_port = %s + ds_limit = %s + us_limit = %s + start_time = %s + dht_enabled = %s + pxe_enabled = %s + streaming_enabled = %s + features = %s + description = %s + """ %(id, session.swarm_id, session.btclient, session.system_os, + session.system_os_version, session.system_ram, session.system_cpu, + session.public_ip, session.public_port, session.ds_limit, + session.us_limit, session.start_time, session.dht_enabled, + session.pxe_enabled, session.streaming_enabled, + session.features, session.description)) + f.close() def add_peer_status_message(self, msg): pass -- 2.20.1