コード例 #1
0
ファイル: describe_processing.py プロジェクト: plazar/TOASTER
def main(args):
    if args.from_file is not None:
        if args.from_file == "-":
            argfile = sys.stdin
        else:
            if not os.path.exists(args.from_file):
                raise errors.FileError("The list of cmd line args (%s) " "does not exist." % args.from_file)
            argfile = open(args.from_file, "r")
        for line in argfile:
            # Strip comments
            line = line.partition("#")[0].strip()
            if not line:
                # Skip empty line
                continue
            arglist = shlex.split(line.strip())
            args = parser.parse_args(arglist, namespace=args)

    procjobs = get_procjobs(args)
    if not len(procjobs):
        raise errors.ToasterError("No processing jobs match parameters provided!")
    # Sort procjobs
    utils.sort_by_keys(procjobs, args.sortkeys)
    if args.output_style == "text":
        show_procjobs(procjobs)
    elif args.output_style == "summary":
        summarize_procjobs(procjobs)
    else:
        custom_show_procjobs(procjobs, fmt=args.output_style)
コード例 #2
0
ファイル: write_timfile.py プロジェクト: plazar/TOASTER
def write_timfile(toas, timfile, sortkeys=('freq', 'mjd'), flags=(),
                  outname="-", formatter=formatters.tempo2_formatter):
    """Write TOAs to a timfile.
        
        Inputs:
            toas: A list of TOAs.
            timfile: Information about the timfile from the DB.
            flags: A single string containing flags to add to each TOA.
            sortkeys: A list of keys to sort TOAs by.
            outname: The output file's name. (Default: stdout)
            formatter: A formatter function.

        Outputs:
            None
    """
    if outname != '-' and os.path.exists(outname):
        raise errors.FileError("The output timfile sepcified (%s) "
                               "already exists. Doing nothing..." % outname)
    if not timfile['comments']:
        raise errors.BadInputError("Timfile (ID: %d) has no comment!" %
                                   timfile['timfile_id'])

    # Sort TOAs
    utils.sort_by_keys(toas, sortkeys)
    if outname is '-':
        tim = sys.stdout
    else:
        tim = open(outname, 'w')

    wrapper = textwrap.TextWrapper(initial_indent="# ",
                                   subsequent_indent="# ")
    tim.write(wrapper.fill(timfile['comments'])+'\n')
    userinfo = cache.get_userinfo(timfile['user_id'])
    tim.write("# Created by: %s (%s)\n" %
              (userinfo['real_name'], userinfo['email_address']))
    tim.write("#         at: %s\n" % timfile['add_time'])
    tim.write("# Timfile ID: %d\n" % timfile['timfile_id'])
    tim.write("# (Automatically generated by TOASTER)\n")

    lines = formatter(toas, flags)
    tim.write("\n".join(lines)+"\n")
    if outname != '-':
        tim.close()
        notify.print_info("Successfully wrote %d TOAs to timfile (%s)" %
                          (len(toas), outname), 1)