1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
 
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import with_statement
 
import os
import sys
import configargparse  #pip install configargparse
import logging
import time
 
log = logging.getLogger()
log.setLevel(level=logging.DEBUG)
fileLogFormatter = logging.Formatter(
    "%(asctime)s [%(threadName)-12.12s] [%(levelname)-5.5s]  %(message)s")
fileHandler = logging.FileHandler("log.log")
fileHandler.setFormatter(fileLogFormatter)
fileHandler.setLevel(logging.INFO)
log.addHandler(fileHandler)
 
consoleLogFormat = logging.Formatter(
    "%(asctime)s %(levelname)1.1s %(filename)5.5s %(lineno)3.3s-> %(message)s")
consoleHandler = logging.StreamHandler()
consoleHandler.setFormatter(consoleLogFormat)
consoleHandler.setLevel(logging.DEBUG)
log.addHandler(consoleHandler)
 
 
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
 
 
def timeit(method):
    def timed(*args, **kw):
        ts = time.time()
        trans = args[0]
        log.debug("timing start:" + str(trans))
        try:
            result = method(*args, **kw)
        except:
            result = -1
            pass
        log.debug("timing end:" + str(trans))
        te = time.time()
        trans.cost_time = te - ts
        log.info("time is %d sec for %s" % (trans.cost_time, trans))
        return result
    return timed
 
 
class Obj(object):
    def __init__(self, **kwargs):
        self.kwargs = kwargs
        #log.info("qsize: {qsize: 4d}".format(qsize=self.kwargs.get("qsize", 0.23)))
        #log.info("qsize: {qsize: 4.2f}".format(qsize=self.kwargs.get("qsize", 0.23)))
 
    @timeit
    def do(self):
        src = self.kwargs.get("src").replace("\\", "/")
        if not src:
            log.fatal("parameter is missing: src directory")
            sys.exit(1)
        if not os.path.isdir(src):
            log.fatal("no src directory: {src}".format(src=src))
            sys.exit(1)
 
        dst = self.kwargs.get("dst").replace("\\", "/")
        if not dst:
            log.fatal("parameter is missing: dst directory")
            sys.exit(1)
        if not os.path.isdir(dst):
            log.fatal("no dst directory: {dst}".format(dst=dst))
            sys.exit(1)
 
 
        #finp = self.kwargs.get("fin")
        #if not finp or not os.path.exists(finp):
            #log.fatal("in file not found: {fin}".format(fin=finp))
            #sys.exit(1)
 
        #out_root = self.kwargs.get("out_root")
        #if not out_root or not os.path.exists(out_root) or not os.path.isdir(out_root):
            #log.fatal("out dir not found: {out_root}".format(out_root=out_root))
            #sys.exit(1)
 
        #finp = finp.replace("\\", "/")  # e.g., #/a/b/c.mp4
        #foutd, fout = os.path.split(finp)    # ('a/b', 'c.mp4')
        #fname, fext = os.path.splitext(fout)  # ('c', '.mp4')
        #foutp = os.path.join(out_root, fname + ".dat")
 
 
 
if __name__ == "__main__":
    p = configargparse.ArgParser(default_config_files=['../settings.ini', '..\settings.ini'],ignore_unknown_config_file_keys=True)
    p.add('-c', '--config', is_config_file=True, help='config file path')
    p.add('-v', help='verbose', action='store_true')
    p.add('src', nargs='?', help='variant file(s)')
    p.add('dst', nargs='?', help='variant file(s)')
 
    #p.add("-i", "--in", nargs="?", dest="in", default="data/in", help="input directory")
    #p.add("-o", "--out", nargs="?", dest="out", default="/data/out", help="output directory")
    #p.add("--inf", nargs="?", dest="inf", default="data/in/in.dat", help="input file")
    #p.add("--infs", nargs="*", dest="infs", default=["data/in/in1.dat", "/data/in/in2.dat"], help="input files")
    #p.add("--outf", nargs="?", dest="outf", default="/data/out/out.dat", help="output file")
    #p.add("-d", "--debug", dest="debug", action='store_true', help="debug mode")
 
    #p.add("--qsize", nargs="?", type=int, default=1000, help="output file")
    #p.add("--itN", nargs="?", type=int, default=100000, help="output file")
    #p.add("--classN", nargs="?", type=int, default=1000, help="output file")
    #p.add("--batchsize", nargs="?", type=int, default=20, help="output file")
 
    #p.add("--in2", nargs="?", dest="in2", default="/data/in2", help="input directory2")
    #p.add("--in3", nargs="?", dest="in3", default="/data/in3", help="input directory3")
    #p.add("--out2", nargs="?", dest="out2", default="/data/out2", help="output directory2")
    #p.add("--out3", nargs="?", dest="out3", default="/data/out3", help="output directory3")
    #p.add("--inf2", nargs="?", dest="inf2", default="data/in/in2.dat", help="input file2")
    #p.add("--inf3", nargs="?", dest="inf3", default="data/in/in3.dat", help="input file3")
    #p.add("--outf2", nargs="?", dest="outf2", default="/data/out/out2.dat", help="output file2")
    #p.add("--outf3", nargs="?", dest="outf3", default="/data/out/out3.dat", help="output file3")
 
    args = p.parse_args()
    dic = vars(args)
    log.info(dic)
    obj = Obj(**dic)
    obj.do()
    log.info("all over")