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

Add check command

parent a4ca3823
No related branches found
No related tags found
No related merge requests found
......@@ -99,6 +99,14 @@ def c_cat(parser, args):
for filename in args.file:
img.cat(filename)
def c_check(parser, args):
'''
Check for unreferenced and missing files inside a repository
'''
repoman = load_repositories(args)
for reponame in args.repository:
repoman[reponame].check()
def c_clean(parser, args):
'''
Clean a repository
......@@ -320,6 +328,11 @@ p_cat.add_argument("file", nargs="+",
help="file inside image to cat (globbing allowed)")
p_cat.set_defaults(func=c_cat)
# check command parser
p_check = subparsers.add_parser("check", help=c_check.__doc__.lower())
p_check.add_argument("repository", nargs="+", help="repositories to check")
p_check.set_defaults(func=c_check)
# clean command parser
p_clean = subparsers.add_parser("clean", help=c_clean.__doc__.lower())
p_clean.add_argument("repository", nargs="+", help="repositories to clean")
......
......@@ -182,6 +182,27 @@ class Repository(object):
res = self.db.ask("SELECT md5 FROM image UNION SELECT md5 FROM payload").fetchall()
return [ md5[0] for md5 in res ]
def check(self):
'''
Check repository for unreferenced and missing files
'''
# Check if the repo is local
if not istools.isfile(self.config.path):
raise Exception("Repository must be local")
local_files = set(os.listdir(self.config.path))
db_files = set(self.getallmd5())
db_files.add(self.config.dbname)
db_files.add( self.config.lastname)
# compute missing and unref files list
missing_files = db_files - local_files
unref_files = local_files - db_files
if len(missing_files) > 0:
arrow("Missing files:")
out(os.linesep.join(missing_files))
if len(unref_files) > 0:
arrow("Unreferenced files:")
out(os.linesep.join(unref_files))
def clean(self):
'''
Clean the repository's content
......
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