Newer
Older
'''
Remove local cached repository files
'''
for reponame in self.select_repositories(patterns):
arrow(u"Purging cache of repository %s" % reponame)
db = os.path.join(self.cache_path, reponame)
try:
os.unlink(db)
arrow("done", 1)
except:
arrow("failed", 1)
else:
arrow("nothing to do", 1)
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
def show_repositories(self, patterns, local=None, online=None,
o_url=False, o_state=False, o_json=False):
'''
Show repository inside manager
if :param online: is true, list only online repositories
if :param online: is false, list only offline repostiories
if :param online: is None, list both online and offline repostiories.
if :param local: is true, list only local repositories
if :param local: is false, list only remote repostiories
if :param local: is None, list both local and remote repostiories.
'''
# build repositories dict
repos = {}
for reponame in self.select_repositories(patterns):
repo = self[reponame]
if repo.config.offline and online is True:
continue
if not repo.config.offline and online is False:
continue
if repo.local and local is False:
continue
if not repo.local and local is True:
continue
repos[reponame] = dict(repo.config.items())
repos[reponame]["local"] = repo.local
# display result
if o_json:
s = json.dumps(repos)
else:
l = []
for name, repo in repos.items():
ln = ""
so = "#l##r#Off#R# " if repo["offline"] else "#l##g#On#R# "
sl = "#l##y#Local#R# " if repo["local"] else "#l##c#Remote#R# "
rc = "#l##r#" if repo["offline"] else "#l##g#"
if o_state:
ln += u"%s%s " % (so, sl)
ln += u"%s%s#R#"% (rc, name)
ln += u" (%s)" % repo["path"]
l.append(ln)
s = os.linesep.join(l)
out(s)
class RepositoryConfig(object):
'''
Repository configuration container
'''
def __init__(self, name, **kwargs):
# set default value for arguments
self._valid_param = ("name", "path", "dbpath", "lastpath",
"uid", "gid", "fmod", "dmod", "offline")
self.name = Repository.check_repository_name(name)
self._offline = False
self._dbpath = None
self.dbname = "db"
self._lastpath = None
self.lastname = "last"
self._uid = os.getuid()
self._gid = os.getgid()
umask = os.umask(0)
os.umask(umask)
self._fmod = 0666 & ~umask
self._dmod = 0777 & ~umask
self.update(**kwargs)
def __str__(self):
l = []
l.append(u"%s: %s" % (k, v))
return os.linesep.join(l)
def __eq__(self, other):
return vars(self) == vars(other)
def __ne__(self, other):
return not (self == other)
def __contains__(self, key):
return key in self.__dict__
def __getitem__(self, key):
if key not in self._valid_param:
raise IndexError(key)
return getattr(self, key)
def __iter__(self):
for p in self._valid_param:
yield p
def items(self):
for p in self:
yield p, self[p]
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
@property
def lastpath(self):
'''
Return the last file complete path
'''
if self._lastpath is None:
return os.path.join(self.path, self.lastname)
return self._lastpath
@lastpath.setter
def lastpath(self, value):
'''
Set last path
'''
self._lastpath = value
@property
def dbpath(self):
'''
Return the db complete path
'''
if self._dbpath is None:
return os.path.join(self.path, self.dbname)
return self._dbpath
@dbpath.setter
def dbpath(self, value):
'''
Set db path
'''
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
if not istools.isfile(value):
raise ValueError("Database path must be local")
self._dbpath = os.path.abspath(value)
@property
def uid(self):
'''
Return owner of repository
'''
return self._uid
@uid.setter
def uid(self, value):
'''
Define user name owning repository
'''
if not value.isdigit():
self._uid = pwd.getpwnam(value).pw_uid
else:
self._uid = int(value)
@property
def gid(self):
'''
Return group of the repository
'''
return self._gid
@gid.setter
def gid(self, value):
'''
Define group owning repository
'''
if not value.isdigit():
self._gid = grp.getgrnam(value).gr_gid
else:
self._gid = int(value)
@property
def fmod(self):
'''
Return new file mode
'''
return self._fmod
@fmod.setter
def fmod(self, value):
'''
Define new file mode
'''
if value.isdigit():
self._fmod = int(value, 8)
else:
raise ValueError("File mode must be an integer")
@property
def dmod(self):
'''
Return new directory mode
'''
return self._dmod
@dmod.setter
def dmod(self, value):
'''
Define new directory mode
'''
if value.isdigit():
self._dmod = int(value, 8)
else:
raise ValueError("Directory mode must be an integer")
@property
def offline(self):
'''
Get the offline state of a repository
'''
return self._offline
@offline.setter
def offline(self, value):
if type(value) in (str, unicode):
value = value.lower() not in ("false", "no", "0")
elif type(value) is not bool:
value = bool(value)
self._offline = value
def update(self, *args, **kwargs):
'''
Update attribute with checking value
All attribute must already exists
'''
# autoset parameter in cmdline
for k in kwargs:
if hasattr(self, k):
try:
setattr(self, k, kwargs[k])
except Exception as e:
warn(u"Unable to set config parameter %s in repository %s: %s" %
(k, self.name, e))
debug(u"No such repository parameter: %s" % k)