view xena_delete.py @ 2:6eeb3ca663fb

Fixed dataset delete bugs (the full pathname was needed) plus changed xena_import to give a checkbox for turning on column normalization
author melissacline
date Wed, 14 Jan 2015 15:21:09 -0800
parents 8bb037f88ed2
children 98b498545a52
line wrap: on
line source

#!/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/%s -p %s" % (xena.jarPath(),
                                                           xenaFileDir,
                                                           args.datasetName,
                                                           xena.port())
    print "Issuing command", xenaDeleteCmd
    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()