annotate xena_delete.py @ 0:8bb037f88ed2

Uploaded
author melissacline
date Tue, 13 Jan 2015 23:37:23 -0500
parents
children 6eeb3ca663fb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
1 #!/usr/bin/env python
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
2
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
3 """
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
4 xena_delete.py: delete a dataset from Xena
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
5
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
6 Given the name of a Xena dataset, delete it from the local Xena database.
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
7 """
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
8
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
9 import argparse
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
10 import json
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
11 import os
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
12 import re
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
13 import shutil
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
14 import subprocess
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
15 import sys
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
16 import traceback
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
17 import xena_utils as xena
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
18
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
19 def main():
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
20 parser = argparse.ArgumentParser()
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
21 parser.add_argument("datasetName", type=str)
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
22 parser.add_argument("outfile", type=str)
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
23 args = parser.parse_args()
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
24
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
25 fp2 = open(args.outfile, "w")
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
26 xenaFileDir = xena.fileDir()
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
27
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
28 # Set up the xena delete comamnd and try to execute it. If an exception
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
29 # is generated, output a traceback and exit with nonzero status. If
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
30 # no exception was generated, indicate a successful import and exit
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
31 # with zero status.
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
32 xenaDeleteCmd = "java -jar %s --delete %s -p %s" % (xena.jarPath(),
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
33 args.datasetName,
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
34 xena.port())
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
35 try:
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
36 subprocess.call(xenaDeleteCmd, shell=True)
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
37 except:
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
38 exc_type, exc_value, exc_traceback = sys.exc_info()
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
39 lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
40 allLines = ''.join('!! ' + line for line in lines)
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
41 fp2.write("Unsuccessful: error %s\n" % allLines)
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
42 fp2.close()
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
43 sys.exit(-1)
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
44 else:
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
45 fp2.write( "Dataset %s deleted\n" % args.datasetName)
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
46 fp2.close()
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
47 sys.exit(0)
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
48
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
49
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
50 if __name__ == "__main__":
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
51 main()