# 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')
self.length = length
self.listen_port = listen_port
-class SwarmDataAccess():
+class SwarmDataAccess(object):
def __init__(self):
pass
def __init__(self, path):
self.base_path = path
+def find_last_numeric_subfolder(path):
+ """
+ Find last numeric folder in base_path folder.
+ The last numeric folder is the last swarm_id.
+ """
+ dir_list = []
+ pattern = re.compile("[0-9]+")
+
+ # Browse entries in base_path folder.
+ listing = os.listdir(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))
+
+ if not dir_list:
+ return None
+ else:
+ dir_list.sort()
+ return dir_list[len(dir_list)-1]
+
class TreeTextFileAccess(FileAccess):
def __init__(self, path):
- super(TextTreeFileAccess, self).__init(path)
- # TODO: Check exception.
- os.mkdir(self.base_path)
-
- def find_last_folder_id(self):
- """
- Find last numeric folder in base_path folder.
- The last numeric folder is the last swarm_id.
- """
- dir_list = []
- pattern = re.compile("[0-9]+")
-
- # Browse entries in base_path folder.
- listing = os.listdir(self.base_path)
- for entry in listing:
- # If directory name is a number (id) add it to the list.
- if os.path.isdir(entry):
- if pattern.match(entry):
- dir_list.append(int(entry))
-
- if dir_list.empty():
- return None
- else:
- dir_list.sort()
- return dir_list[len(dir_list)-1]
+ super(TreeTextFileAccess, self).__init__(path)
def add_swarm(self, swarm):
f = open(os.path.join(self.base_path, "swarm.conf"))