示例#1
0
def usage(style = None):
    """show usage info, for style=="brief" show only first 2 lines"""
    import os.path
    myname = os.path.basename(sys.argv[0])
    msg = __doc__.replace("transtru", myname)
    if style == 'brief':
        msg = msg.split("\n")[1] + "\n" + \
                "Try `%s --help' for more information." % myname
    else:
        from diffpy.Structure.Parsers import inputFormats, outputFormats
        msg = msg.replace("inputFormats", " ".join(inputFormats()))
        msg = msg.replace("outputFormats", " ".join(outputFormats()))
    print msg
    return
示例#2
0
def usage(style=None):
    """show usage info, for style=="brief" show only first 2 lines"""
    import os.path
    myname = os.path.basename(sys.argv[0])
    msg = __doc__.replace("transtru", myname)
    if style == 'brief':
        msg = msg.split("\n")[1] + "\n" + \
                "Try `%s --help' for more information." % myname
    else:
        from diffpy.Structure.Parsers import inputFormats, outputFormats
        msg = msg.replace("inputFormats", " ".join(inputFormats()))
        msg = msg.replace("outputFormats", " ".join(outputFormats()))
    print msg
    return
示例#3
0
         usage()
         sys.exit()
     elif o in ("-V", "--version"):
         version()
         sys.exit()
 if len(args) < 1:
     usage('brief')
     sys.exit()
 # process arguments
 from diffpy.Structure.Parsers import inputFormats, outputFormats
 try:
     infmt, outfmt = args[0].split('..', 1)
     if infmt not in inputFormats():
         print >> sys.stderr, "'%s' is not valid input format" % infmt
         sys.exit(2)
     if outfmt not in outputFormats():
         print >> sys.stderr, "'%s' is not valid output format" % outfmt
         sys.exit(2)
 except ValueError:
     print >> sys.stderr, \
         "invalid format specification '%s' does not contain .." % args[0]
     sys.exit(2)
 # ready to do some real work
 try:
     strufile = args[1]
     stru = Structure()
     if args[1] == "-":
         stru.readStr(sys.stdin.read(), infmt)
     else:
         stru.read(strufile, infmt)
     sys.stdout.write( stru.writeStr(outfmt) )
 def getFileFormats():
     """Return list of valid values for the fileformat attribute.
     """
     from diffpy.Structure.Parsers import outputFormats
     return outputFormats()
 def getFileFormats():
     """Return list of valid values for the fileformat attribute.
     """
     from diffpy.Structure.Parsers import outputFormats
     return outputFormats()
示例#6
0
         usage()
         sys.exit()
     elif o in ("-V", "--version"):
         version()
         sys.exit()
 if len(args) < 1:
     usage('brief')
     sys.exit()
 # process arguments
 from diffpy.Structure.Parsers import inputFormats, outputFormats
 try:
     infmt, outfmt = args[0].split('..', 1)
     if infmt not in inputFormats():
         print >> sys.stderr, "'%s' is not valid input format" % infmt
         sys.exit(2)
     if outfmt not in outputFormats():
         print >> sys.stderr, "'%s' is not valid output format" % outfmt
         sys.exit(2)
 except ValueError:
     print >> sys.stderr, \
         "invalid format specification '%s' does not contain .." % args[0]
     sys.exit(2)
 # ready to do some real work
 try:
     strufile = args[1]
     stru = Structure()
     if args[1] == "-":
         stru.readStr(sys.stdin.read(), infmt)
     else:
         stru.read(strufile, infmt)
     sys.stdout.write(stru.writeStr(outfmt))