Ejemplo n.º 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("anyeye", myname)
    if style == 'brief':
        msg = msg.split("\n")[1] + "\n" + \
                "Try `%s --help' for more information." % myname
    else:
        from diffpy.Structure.Parsers import inputFormats
        fmts = [ f for f in inputFormats() if f != 'auto' ]
        msg = msg.replace("inputFormats", " ".join(fmts))
    print msg
    return
Ejemplo n.º 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
Ejemplo n.º 3
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("anyeye", myname)
    if style == "brief":
        msg = msg.split("\n")[1] + "\n" + "Try `%s --help' for more information." % myname
    else:
        from diffpy.Structure.Parsers import inputFormats

        fmts = [f for f in inputFormats() if f != "auto"]
        msg = msg.replace("inputFormats", " ".join(fmts))
    print msg
    return
Ejemplo n.º 4
0
 def _getOrderedFormats(self):
     """Build a list of relevance ordered structure formats.
     This only works when self.filename has a known extension.
     """
     from diffpy.Structure.Parsers import inputFormats
     ofmts = [fmt for fmt in inputFormats() if fmt != 'auto']
     if not self.filename:   return ofmts
     # filename is defined here
     filebase = os.path.basename(self.filename)
     from fnmatch import fnmatch
     # loop over copy of ofmts
     for fmt in list(ofmts):
         pattern = parser_index[fmt]['file_pattern']
         if pattern in ('*.*', '*'):     continue
         anymatch = [1 for p in pattern.split('|') if fnmatch(filebase, p)]
         if anymatch:
             ofmts.remove(fmt)
             ofmts.insert(0, fmt)
     return ofmts
Ejemplo n.º 5
0
 def _getOrderedFormats(self):
     """Build a list of relevance ordered structure formats.
     This only works when self.filename has a known extension.
     """
     from diffpy.Structure.Parsers import inputFormats
     ofmts = [fmt for fmt in inputFormats() if fmt != 'auto']
     if not self.filename: return ofmts
     # filename is defined here
     filebase = os.path.basename(self.filename)
     from fnmatch import fnmatch
     # loop over copy of ofmts
     for fmt in list(ofmts):
         pattern = parser_index[fmt]['file_pattern']
         if pattern in ('*.*', '*'): continue
         anymatch = [1 for p in pattern.split('|') if fnmatch(filebase, p)]
         if anymatch:
             ofmts.remove(fmt)
             ofmts.insert(0, fmt)
     return ofmts
Ejemplo n.º 6
0
 # process options
 for o, a in opts:
     if o in ("-h", "--help"):
         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)
Ejemplo n.º 7
0
 # process options
 for o, a in opts:
     if o in ("-h", "--help"):
         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)