blob: 373ce6cb03ae0d67f3e31c4cb96448d223aec3dd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
"""
Class to handle Bareos passwords.
"""
from copy import copy
class Path(object):
def __init__(self, path=None):
self.__set_defaults()
self.set_path(path)
def __str__(self):
result = ""
if self.is_root():
result += "/"
result += "/".join(self.path)
if (not self.is_root()) or self.len() > 0:
if self.is_directory():
result += "/"
return result
def __set_defaults(self):
self.path_orig = None
self.root = False
self.directory = False
self.path = None
def set_path(self, path):
if path == None:
self.__set_defaults()
elif isinstance(path, str):
self.path_orig = path
components = self.path_orig.split('/')
self.path = [i for i in components if i != '']
if path == "":
self.root = False
self.directory = True
else:
self.root = False
if self.path_orig[0] == '/':
self.root = True
self.directory = False
if components[-1] == '':
self.directory = True
else:
# exception
pass
def get(self, index=None):
if index == None:
return self.path
else:
return self.path[index]
#def lstrip(self, path=[]):
#"""
#Creates a new Path instance with lstrip components removed from left.
#"""
#result = copy(self)
#result.root = False
#for i in path:
#if result.get(0) == i:
#result.remove(0)
#else:
## TODO: exception?
#pass
#return result
def shift(self):
"""
Creates a new Path instance with lstrip components removed from left.
"""
result = self.get(0)
self.remove(0)
return result
def is_directory(self):
return self.directory
def is_root(self):
return self.root
def remove(self, index):
del(self.path[index])
def len(self):
return len(self.path)
|