-
Notifications
You must be signed in to change notification settings - Fork 5
/
cgb_delete.py
executable file
·70 lines (53 loc) · 2.25 KB
/
cgb_delete.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
#####################################################
# This file is a component of ClusterGB #
# Copyright (c) 2018 Liam Huber #
# Released under the MIT License (see distribution) #
#####################################################
"""
Safely deletes Jobs from their parent Projects and the file system.
.. note::
Tab completing the Job you want to delete will likely put a "/" at the end of the Job name. The directory will
be deleted, but the Project won't recognize the child name and you will get a warning. Simply re-run without
the "/"--you will get a warning that the directory is not present (since it's already deleted) but this will
clean the child name from the Project.
"""
from __future__ import absolute_import
import argparse
#from . import clustergb as cgb
import clustergb as cgb
from shutil import rmtree
__author__ = "Liam Huber"
__copyright__ = "Copyright 2018, Liam Huber"
__license__ = "MIT"
__maintainer__ = "Liam Huber"
__email__ = "[email protected]"
__status__ = "Production"
def main(args):
try:
parent = cgb.osio.load_project()
except IOError:
raise Exception("You're not in a ClusterGB Project hierarchy, just use rm...")
for target in args.to_delete:
try:
parent.child_names.remove(target)
parent.save()
except ValueError:
print("WARNING: Child " + target + " does not belong to " + parent.__class__.__name__ + " " + parent.name +
".")
try:
rmtree(target)
except OSError:
print("WARNING: No directory " + target + " was found.")
return
def _ret_parser():
parser = argparse.ArgumentParser(description="Delete Jobs by name--including their references in their parent "
"Projects.",
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("to_delete", type=str, nargs="+",
help="Names of the Jobs/Projects in the current working directory to delete.")
return parser
if __name__ == "__main__":
returned_parer = _ret_parser()
arguments = returned_parer.parse_args()
main(arguments)