|
a/scripts/purge_project.py |
|
b/scripts/purge_project.py |
|
... |
|
... |
17 |
MONGO_RESTORE=os.path.join(MONGO_HOME, 'bin/mongorestore')
|
17 |
MONGO_RESTORE=os.path.join(MONGO_HOME, 'bin/mongorestore')
|
18 |
|
18 |
|
19 |
def main():
|
19 |
def main():
|
20 |
if len(sys.argv) != 2:
|
20 |
if len(sys.argv) != 2:
|
21 |
log.error('Usage: %s <shortname>', sys.argv[0])
|
21 |
log.error('Usage: %s <shortname>', sys.argv[0])
|
22 |
return
|
22 |
return 1
|
23 |
pname = sys.argv[1]
|
23 |
pname = sys.argv[1]
|
24 |
log.info('Purging %s', pname)
|
24 |
log.info('Purging %s', pname)
|
25 |
project = M.Project.query.get(shortname=pname)
|
25 |
project = M.Project.query.get(shortname=pname)
|
26 |
if project is None:
|
26 |
if project is None:
|
27 |
log.fatal('Project %s not found', pname)
|
27 |
log.fatal('Project %s not found', pname)
|
28 |
return
|
28 |
return 2
|
29 |
purge_project(project)
|
29 |
purge_project(project)
|
30 |
|
30 |
|
31 |
def purge_project(project):
|
31 |
def purge_project(project):
|
32 |
gid = project.tool_data.get('sfx', {}).get('group_id', project._id)
|
32 |
gid = project.tool_data.get('sfx', {}).get('group_id', project._id)
|
33 |
project.shortname = 'deleted-%s' % gid
|
33 |
project.shortname = 'deleted-%s' % gid
|
34 |
project.deleted = True
|
34 |
project.deleted = True
|
35 |
g.solr.delete(q='project_id_s:%s' % project._id)
|
35 |
g.solr.delete(q='project_id_s:%s' % project._id)
|
36 |
session(project).flush()
|
36 |
session(project).flush()
|
37 |
|
37 |
|
38 |
if __name__ == '__main__':
|
38 |
if __name__ == '__main__':
|
39 |
main()
|
39 |
sys.exit(main())
|