示例#1
0
def parse_options(argv):
    import getopt

    basepath = '.'

    timestamp = datetime.now()
    tag = timestamp.strftime('%Y-%m-%d-%H-%M-%S')
    filename = tag + ".csv"

    try:
        opts, args = getopt.getopt(argv, "s:f:", ["source=", "file="])
    except getopt.GetoptError:
        print 'tutorial.py -s <source dir> -f <output filename>'
        sys.exit(2)

    for opt, arg in opts:
        if opt == '-h':
            print 'tutorial.py -s <source dir> -f <output filename>'
            sys.exit()
        elif opt in ("-s", "--source"):
            basepath = arg
        elif opt in ("-f", "--filename"):
            filename = arg

    destination_path = os.path.abspath(os.path.join(basepath, "output"))
    mkdir(destination_path)
    outuput_filename = os.path.join(destination_path, filename)
    source_path = os.path.abspath(basepath)

    logging.info("parsing files %(s)s to %(f)s" % {
        's': source_path,
        'f': outuput_filename
    })
    return (source_path, outuput_filename)
示例#2
0
def parse_options(argv):
    import getopt

    basepath = '.'
    
    timestamp = datetime.now()
    tag = timestamp.strftime('%Y-%m-%d-%H-%M-%S')
    filename = tag+".csv"  

    try:
        opts, args = getopt.getopt(argv,"s:f:",["source=","file="])
    except getopt.GetoptError:
        print 'tutorial.py -s <source dir> -f <output filename>'
        sys.exit(2)
    
    for opt, arg in opts:
        if opt == '-h':
           print 'tutorial.py -s <source dir> -f <output filename>' 
           sys.exit()
        elif opt in ("-s", "--source"):
           basepath = arg
        elif opt in ("-f", "--filename"):
           filename = arg
           
    destination_path = os.path.abspath(os.path.join(basepath, "output"))
    mkdir(destination_path)
    outuput_filename = os.path.join(destination_path, filename)
    source_path = os.path.abspath(basepath)
    
    logging.info("parsing files %(s)s to %(f)s" % {'s': source_path, 'f': outuput_filename})
    return (source_path,outuput_filename)
def initialize_logger(output_dir, file_level=logging.DEBUG, console_level=logging.DEBUG, file_mode='a'):
    mkdir(output_dir)
    
    # set up logging to file (default)
    file_name = os.path.join(output_dir, "edgesense.log")
    logging.basicConfig(level=file_level,
                        format='[%(asctime)s] %(name)-12s %(levelname)-8s %(message)s',
                        datefmt='%Y-%m-%d %H:%M:%S',
                        filename=file_name,
                        filemode=file_mode)
    logging.getLogger('rdflib').setLevel(logging.ERROR)
    # create console handler and set level to info
    handler = logging.StreamHandler()
    handler.setLevel(console_level)
    formatter = logging.Formatter("[%(asctime)s] %(message)s")
    handler.setFormatter(formatter)
    logging.getLogger('').addHandler(handler)