Skip to content
Snippets Groups Projects
Commit d4aaea6f authored by Matthieu Gonnet's avatar Matthieu Gonnet Committed by Seblu
Browse files

Add clean command


Seblu: Fix too many things...

Signed-off-by: default avatarSeblu <sebastien.luttringer@smartjog.com>
parent 401c15a5
No related branches found
No related tags found
No related merge requests found
......@@ -103,7 +103,9 @@ def c_clean(parser, args):
'''
Clean a repository
'''
raise NotImplementedError("Not yet implemented")
repoman = load_repositories(args)
for reponame in args.repository:
repoman[reponame].clean()
def c_copy(parser, args):
'''
......@@ -320,6 +322,7 @@ p_cat.set_defaults(func=c_cat)
# clean command parser
p_clean = subparsers.add_parser("clean", help=c_clean.__doc__.lower())
p_clean.add_argument("repository", nargs="+", help="repositories to clean")
p_clean.set_defaults(func=c_clean)
# copy command parser
......
......@@ -175,6 +175,36 @@ class Repository(object):
arrow(os.path.basename(obj.path), 1)
os.unlink(obj.path)
def getallmd5(self):
'''
Get list of all md5 in DB
'''
res = self.db.ask("SELECT md5 FROM image UNION SELECT md5 FROM payload").fetchall()
return [ md5[0] for md5 in res ]
def clean(self):
'''
Clean the repository's content
'''
# Check if the repo is local
if not istools.isfile(self.config.path):
raise Exception("Repository must be local")
allmd5 = set(self.getallmd5())
repofiles = set(os.listdir(self.config.path)) - set([self.config.dbname, self.config.lastname])
dirtyfiles = repofiles - allmd5
if len(dirtyfiles) > 0:
if not confirm("Remove dirty files? (yes) "):
raise Exception("Aborted!")
for f in dirtyfiles:
p = os.path.join(self.config.path, f)
try:
if os.path.isdir(p):
os.rmdir(p)
else:
os.unlink(p)
except:
raise Exception("Removing %s failed" % p)
def delete(self, name, version):
'''
Delete an image from repository
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment