Пример #1
0
        mesg = 'Found {0} message(s) in {1!r}.\n'
        self.mail.verbose(mesg.format(data[0], mailbox))


def main(args):
    mail = Detach()
    mail.connect(args)
    mail.login(args.username)
    mail.select(args.mbox)
    if args.search: arg.nums = mail.search(args.search, args.nums)
    mail.fetch(args.nums)
    mail.logout()      

if __name__ == '__main__':
    from cmd_line_args import Args
    args = Args(USAGE, __version__)
    args.parser.add_argument('--debug', type=int, 
        help='Debug level 1-5')
    args.parser.add_argument('--verbose', action='store_true', 
        help='Disable verbose mode')
    args.parser.add_argument('--host', default=None, 
        help='IMAP server hosname')
    args.parser.add_argument('--username', 
        help='IMAP login name, user@domain')
    args.parser.add_argument('--port', type=int, 
        help='IMAP server port number')
    args.parser.add_argument('--telnet', action='store_true', 
        help='Use telnet instead of SSL')
    args.parser.add_argument('--uid', action='store_true', 
        help='Use UID')
    # -----------------------------------------------------------------------
Пример #2
0
def parse_data(struct_fmt, lines):
    try:
        return [struct.unpack(struct_fmt, i) for i in lines]
    except struct.error:
        sys.stderr.write('Record layout vs. record size mismatch\n')
        size = sum([int(i) for i in struct_fmt.split('s')[:-1]])
        return [struct.unpack(struct_fmt, i.ljust(size)[:size]) for i in lines]


def main(args):
    copybook = load.csv_(args.copybook.readlines(), strip_=True)[1:]
    field_lengths = [int(i[2]) for i in copybook]
    struct_fmt = 's'.join([str(i) for i in field_lengths]) + 's'
    if args.struct:
        print struct_fmt
    else:
        for record in parse_data(struct_fmt, load.lines(args.datafile)):
            print record


if __name__ == '__main__':
    from cmd_line_args import Args
    args = Args(USAGE, __version__)
    args.allow_stdin()
    args.add_files('datafile', 'copybook')
    args.parser.add_argument('-s',
                             '--struct',
                             action='store_true',
                             help='show structure format')
    main(args.parse())
Пример #3
0
import load
import csv, struct, sys

def parse_data(struct_fmt, lines):
    try:
      return [ struct.unpack(struct_fmt, i) for i in lines ]
    except struct.error:
        sys.stderr.write('Record layout vs. record size mismatch\n')
        size = sum([ int(i) for i in struct_fmt.split('s')[:-1] ])
        return [ struct.unpack(struct_fmt, i.ljust(size)[:size]) 
          for i in lines ]

def main(args):  
    copybook = load.csv_(args.copybook.readlines(), strip_=True)[1:]
    field_lengths = [ int(i[2]) for i in copybook ]
    struct_fmt = 's'.join([ str(i) for i in field_lengths ]) + 's'
    if args.struct:
        print struct_fmt
    else:
        for record in parse_data(struct_fmt, load.lines(args.datafile)):
            print record

if __name__ == '__main__':
    from cmd_line_args import Args
    args = Args(USAGE, __version__)
    args.allow_stdin()
    args.add_files('datafile', 'copybook')
    args.parser.add_argument('-s', '--struct', action='store_true',
        help='show structure format')
    main(args.parse())
Пример #4
0
          
    def remove_filler(self, record_num, record):
        pass

   
def main(args):
    fields = load.csv_(args.copybook, strip_="right", prune=True)
    datetime_output_fmt = FormatDateTimeOutput(
        date_fmt = '%Y-%m-%d', time_fmt = '%H:%M:%S.%f')
    data = Data(fields, args, datetime_output_fmt)
    record = True
    record_num = 1
    while record:
        line = args.datafile.readline()
        if args.debug and line:
            sys.stdout.write('%s\n' % DBL_HORIZ_LINE)
            sys.stdout.write('RECORD NUMBER: %d\n' % record_num)
            sys.stdout.write('%s%s%s' % (HORIZ_LINE, line, HORIZ_LINE))
        record = data.parse_record(record_num, line, args.debug)
        if record:
            print record
        record_num += 1      

if __name__ == '__main__':
    from cmd_line_args import Args
    args = Args(USAGE, __version__)
    args.allow_stdin()
    args.add_files('copybook', 'datafile')
    args.add_options('debug')
    main(args.parse())