diff xena_delete.py @ 0:8bb037f88ed2

Uploaded
author melissacline
date Tue, 13 Jan 2015 23:37:23 -0500
parents
children 6eeb3ca663fb
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xena_delete.py	Tue Jan 13 23:37:23 2015 -0500
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+
+"""
+  xena_delete.py: delete a dataset from Xena
+
+  Given the name of a Xena dataset, delete it from the local Xena database.
+"""
+
+import argparse
+import json
+import os
+import re
+import shutil
+import subprocess
+import sys
+import traceback
+import xena_utils as xena
+
+def main():
+    parser = argparse.ArgumentParser()
+    parser.add_argument("datasetName", type=str)
+    parser.add_argument("outfile", type=str)
+    args = parser.parse_args()
+
+    fp2 = open(args.outfile, "w")
+    xenaFileDir = xena.fileDir()
+
+    # Set up the xena delete comamnd and try to execute it.  If an exception
+    # is generated, output a traceback and exit with nonzero status.  If
+    # no exception was generated, indicate a successful import and exit
+    # with zero status.
+    xenaDeleteCmd = "java -jar %s --delete %s -p %s" % (xena.jarPath(),
+                                                        args.datasetName,
+                                                        xena.port())
+    try:
+        subprocess.call(xenaDeleteCmd, shell=True)
+    except:
+        exc_type, exc_value, exc_traceback = sys.exc_info()
+        lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
+        allLines = ''.join('!! ' + line for line in lines)
+        fp2.write("Unsuccessful: error %s\n" % allLines)
+        fp2.close()
+        sys.exit(-1)
+    else:
+        fp2.write( "Dataset %s deleted\n" % args.datasetName)
+        fp2.close()
+        sys.exit(0)
+
+
+if __name__ == "__main__":
+    main()