From 3b18cbb0325e21fb16ca98ff05cd162434d89a36 Mon Sep 17 00:00:00 2001 From: Razvan Deaconescu Date: Sun, 21 Aug 2011 19:48:12 +0300 Subject: [PATCH] Add add_swarm to TreeTextFileAccess. --- ppf/new/storage.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/ppf/new/storage.py b/ppf/new/storage.py index 4cf9e43..92ab3a9 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.DEBUG) +ch.setLevel(logging.ERROR) # Create formatter. formatter = logging.Formatter('%(filename)s:%(lineno)s - %(levelname)s: %(message)s') @@ -277,7 +277,6 @@ def find_last_numeric_subfolder(path): for entry in listing: # If directory name is a number (id) add it to the list. if os.path.isdir(os.path.join(path, entry)): - logger.debug("folder entry: %s" %(entry)) if pattern.match(entry): dir_list.append(int(entry)) @@ -292,8 +291,27 @@ class TreeTextFileAccess(FileAccess): super(TreeTextFileAccess, self).__init__(path) def add_swarm(self, swarm): - f = open(os.path.join(self.base_path, "swarm.conf")) - pass + """ + Create a subfolder with an unique id. Add 1 to the last numeric + subfolder id. In case none exists, use 1 as id. + """ + id = find_last_numeric_subfolder(self.base_path) + if id == None: + id = 1 + else: + id = id+1 + + swarm_path = os.path.join(self.base_path, str(id)) + os.mkdir(swarm_path) + + 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 + """ %(id, swarm.torrent_filename, swarm.data_size, swarm.description)) + f.close() def add_client_session(self, session): pass -- 2.20.1