add rescan command
This commit is contained in:
parent
337c5c53d3
commit
03a41f943b
|
@ -29,12 +29,14 @@ class Add(Command):
|
|||
for project_name in parsed_args.project:
|
||||
project_path = os.path.join(self.app.options.repo_root, project_name)
|
||||
proj_obj = project.add_or_update(session, project_name, project_path)
|
||||
session.commit()
|
||||
session.commit()
|
||||
|
||||
|
||||
class List(Lister):
|
||||
"""Show the registered projects"""
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
session = self.app.get_db_session()
|
||||
query = session.query(Project).order_by(Project.name)
|
||||
|
@ -42,6 +44,19 @@ class List(Lister):
|
|||
((p.name, p.path) for p in query.all()))
|
||||
|
||||
|
||||
class Rescan(Command):
|
||||
"Rescan all known projects"
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
session = self.app.get_db_session()
|
||||
query = session.query(Project).order_by(Project.name)
|
||||
for proj_obj in query.all():
|
||||
project.update(session, proj_obj)
|
||||
session.commit()
|
||||
|
||||
|
||||
class Remove(Command):
|
||||
"Remove a project from the database"
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ def add_or_update(session, name, path):
|
|||
LOG.info('adding project %s from %s', name, path)
|
||||
session.add(proj_obj)
|
||||
|
||||
update_project_files(session, proj_obj)
|
||||
update(session, proj_obj)
|
||||
return proj_obj
|
||||
|
||||
|
||||
|
@ -38,7 +38,11 @@ def remove(session, name):
|
|||
session.delete(proj_obj)
|
||||
|
||||
|
||||
def update_project_files(session, proj_obj):
|
||||
def update(session, proj_obj):
|
||||
_update_project_files(session, proj_obj)
|
||||
|
||||
|
||||
def _update_project_files(session, proj_obj):
|
||||
"""Update the files stored for each project"""
|
||||
# Delete any existing files in case the list of files being
|
||||
# managed has changed. This naive, and we can do better, but as a
|
||||
|
@ -63,5 +67,5 @@ def update_project_files(session, proj_obj):
|
|||
with io.open(fullname, mode='r', encoding='utf-8') as f:
|
||||
body = f.read()
|
||||
lines = body.splitlines()
|
||||
LOG.info('%s has %s lines', filename, len(lines))
|
||||
LOG.info('%s/%s has %s lines', proj_obj.name, filename, len(lines))
|
||||
session.add(File(project=proj_obj, name=filename, path=fullname))
|
||||
|
|
Loading…
Reference in New Issue