annotate xena_delete.py @ 48:d717d0c4c8f1

fix import bug
author jingchunzhu
date Sun, 09 Aug 2015 22:39:09 -0700
parents 98b498545a52
children
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.
2
6eeb3ca663fb Fixed dataset delete bugs (the full pathname was needed) plus changed xena_import to give a checkbox for turning on column normalization
melissacline
parents: 0
diff changeset
32 xenaDeleteCmd = "java -jar %s --delete %s/%s -p %s" % (xena.jarPath(),
6eeb3ca663fb Fixed dataset delete bugs (the full pathname was needed) plus changed xena_import to give a checkbox for turning on column normalization
melissacline
parents: 0
diff changeset
33 xenaFileDir,
6eeb3ca663fb Fixed dataset delete bugs (the full pathname was needed) plus changed xena_import to give a checkbox for turning on column normalization
melissacline
parents: 0
diff changeset
34 args.datasetName,
6eeb3ca663fb Fixed dataset delete bugs (the full pathname was needed) plus changed xena_import to give a checkbox for turning on column normalization
melissacline
parents: 0
diff changeset
35 xena.port())
0
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
36 try:
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
37 subprocess.call(xenaDeleteCmd, shell=True)
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
38 except:
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
39 exc_type, exc_value, exc_traceback = sys.exc_info()
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
40 lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
41 allLines = ''.join('!! ' + line for line in lines)
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
42 fp2.write("Unsuccessful: error %s\n" % allLines)
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
43 fp2.close()
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
44 sys.exit(-1)
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
45 else:
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
46 fp2.write( "Dataset %s deleted\n" % args.datasetName)
3
98b498545a52 Fixed xena_delete to delete the files from the Xena files directory as well as from the database
melissacline
parents: 2
diff changeset
47 dataPathname = xenaFileDir + "/" + args.datasetName
98b498545a52 Fixed xena_delete to delete the files from the Xena files directory as well as from the database
melissacline
parents: 2
diff changeset
48 if os.path.exists(dataPathname):
98b498545a52 Fixed xena_delete to delete the files from the Xena files directory as well as from the database
melissacline
parents: 2
diff changeset
49 os.unlink(dataPathname)
98b498545a52 Fixed xena_delete to delete the files from the Xena files directory as well as from the database
melissacline
parents: 2
diff changeset
50 metadataPathname = dataPathname + ".json"
98b498545a52 Fixed xena_delete to delete the files from the Xena files directory as well as from the database
melissacline
parents: 2
diff changeset
51 if os.path.exists(metadataPathname):
98b498545a52 Fixed xena_delete to delete the files from the Xena files directory as well as from the database
melissacline
parents: 2
diff changeset
52 os.unlink(metadataPathname)
0
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
53 fp2.close()
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
54 sys.exit(0)
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
55
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
56
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
57 if __name__ == "__main__":
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
58 main()