Ejemplo n.º 1
0
def main():
    parser.add_argument(
        '-m',
        '--mode',
        default='json',
        help='modes: json, document, hack, file, network (default: json)')
    parser.add_argument('-x',
                        '--func',
                        default='delkey',
                        help='functions: delkey,rmkey ...')
    parser.add_argument('-d', '--data', default='', help='input data')
    parser.add_argument('-i',
                        '--inpath',
                        default='',
                        help='indicates input file path.')
    parser.add_argument('-o',
                        '--outpath',
                        default='',
                        help='indicates output file path.')
    args = parser.parse_args()
    from handy.misc import switch
    for mode in switch(args.mode):
        if mode('json'):
            for func in switch(args.func):
                from handy.jzon.handler import load, save
                from handy.dict.mixedict import delkey, rmempty, isin
                if func('delkey'):
                    if not args.inpath:
                        print('add input path with -i/--inpath.')
                        break
                    if not args.data:
                        print('add keyname to be deleted with -d/--data.')
                        break
                    if not args.outpath:
                        answer = raw_input(
                            msg_no_output
                        ) if sys.version_info[0] == 2 else input(msg_no_output)
                        if any(symbol in answer[0] for symbol in yes_symbols):
                            args.outpath = args.inpath
                        elif any(symbol in answer[0] for symbol in no_symbols):
                            break
                        else:
                            args.outpath = answer
                    data = load(args.inpath)
                    if not data:
                        print("input file doesn't exist or wrong file.")
                        break
                    delkey(data, args.data)
                    rmempty(data)
                    save(data, args.outpath)
                    break
                if func():
                    print('type mode with -x or --func.\n \
                          modes: delkey, rmempty')
                    break
            break
        if mode():
            print('type mode with -m or --mode')
            break
 def mouseMoveEvent(self, event):
  
     if not self.isDragging:
         return
     
     imgRect = self.label.contentsRect()
     ###
     left = imgRect.left()
     right = imgRect.right()
     top = imgRect.top()
     bottom = imgRect.bottom()
     ###
     point = event.pos() + self.drag_offset
     point.setX(max(left, min(point.x(), right)))
     point.setY(max(top, min(point.y(), bottom)))
     ### set roiRect
     #print(left,right,top,bottom)
     #print(imgRect.topLeft())
     self.pos_end=event.pos()
     ### project to label
     for case in switch(self.selected_option):
         if case('Direction'):
             self.thread.setDirection(self.pos_start,self.pos_end)
             break
         if case('Forbidden'):
             self.roiRect.setTopLeft(self.pos_start)#-imgRect.TopLeft())
             self.roiRect.setBottomRight(self.pos_end)#-imgRect.TopLeft())
             self.thread.setRect(self.roiRect)
             break
         if case('RedLine'):
             self.thread.setRedLinePts(self.pos_start,self.pos_end)
             break
     self.thread.refresh()
     ###        
     self.update()
Ejemplo n.º 3
0
def deleteLine(keystring, filename, option='-a'):
    fullpath = os.path.realpath(filename)
    if not os.path.exists(fullpath):
        print(msg_file_not_found)
        return
    if not os.path.isfile(fullpath):
        print("directory not accepted.")
        return
    f = open(fullpath)
    output = []
    for line in f:
        for case in switch(sys.argv[2]):
            if case("-e"):
                if not line.endswith(keystring):
                    output.append(line)
                    break
            if case("-s"):
                if not line.startswith(keystring):
                    output.append(line)
                    break
            if case():
                if not keystring in line:
                    output.append(line)
                    break
    f.close()
    f = open(fullpath, 'w')
    f.writelines(output)
    f.close()
Ejemplo n.º 4
0
def deline():
    if len(sys.argv) < 2:
        print(msg_help_deline)
        return
    elif len(sys.argv) == 2:
        if sys.stdin.isatty():
            print(msg_help_deline)
            return
        for line in sys.stdin:
            if line.startswith(sys.argv[1]): print(line.strip("\n"))
        return
    elif len(sys.argv) == 3:
        if os.path.exists(sys.argv[2]):
            deleteLine(sys.argv[1], sys.argv[2])
            return
        elif sys.stdin.isatty():
            print(msg_help_deline)
            return
        from handy.misc import switch
        for line in sys.stdin:
            for case in switch(sys.argv[2]):
                if case("-e"):
                    if not line.endswith(sys.argv[1]):
                        print(line.strip("\n"))
                        break
                if case("-s"):
                    if not line.startswith(sys.argv[1]):
                        print(line.strip("\n"))
                        break
                if case():
                    if not sys.argv[1] in line:
                        print(line.strip("\n"))
                        break
    else:
        deleteLine(sys.argv[1], sys.argv[2], sys.argv[3])
Ejemplo n.º 5
0
def set_env_variable(key, value, mode='add'):
    import os
    import platform
    if key in os.environ.keys() and 'add' in mode:
        for case in switch(platform.system()):
            if case('Windows'):
                if str(value) not in os.environ[key]:
                    os.environ[key] = os.environ[str(key)] + ';' + str(value)
                break
            if case('Linux'):
                break
            if case('MacOS'):
                break
    else:
        os.environ[key] = str(value)
Ejemplo n.º 6
0
def wifipass():
    if len(sys.argv) > 1 and '-h' in sys.argv[1]: return msg_help_wifipass
    from handy.misc import switch
    for platform in switch(sys.platform):
        if platform("win32"):
            os.system('netsh wlan show profile name=%s key=clear|findstr Key'%sys.argv[1])
            break
        if platform("linux2"):
            os.system('grep psk= /etc/NetworkManager/system-connections/*')
            break
        if platform('osx'):
            os.system('security find-generic-password -wa labnol')
            break
        if platform():
            os.system('grep psk= /etc/NetworkManager/system-connections/*')
            break
 def paintEvent(self,event):
     painter = QPainter()
     painter.begin(self)
     painter.setRenderHint(QPainter.Antialiasing)        
     for case in switch(self.selected_option):
         if case('Direction'):
             painter.setPen(QPen(QBrush(Qt.red), 1, Qt.DashLine))
             painter.drawLine(QLine(self.pos_start,self.pos_end))
             break
         if case('Forbidden'):
             painter.setPen(QPen(QBrush(Qt.green), 1, Qt.DashLine))
             painter.drawRect(self.roiRect)
             break
         if case('RedLine'):
             painter.setPen(QPen(QBrush(Qt.yellow), 1, Qt.DashLine))
             painter.drawLine(QLine(self.pos_start,self.pos_end))
             break
     painter.end()
Ejemplo n.º 8
0
def genpass(string, level=0):
    from handy.misc import switch
    for depth in switch(level):
        if depth(0):
            origin = origin_l0
            crypted = crypted_l0
            break
        if depth(1):
            origin = origin_l1
            crypted = crypted_l1
            break
        if depth(2):
            origin = origin_l2
            crypted = crypted_l2
            break
        if depth():
            origin = origin_l1
            crypted = crypted_l1
            break
    result = ''
    for i, char in enumerate(string):
        result += crypted[origin.index(char)] if char in origin else char
    return result
Ejemplo n.º 9
0
     cv2.rectangle(frame, (left, top), (right, bottom), bg_color, 3)
     drawMark(frame, (left, top, width, height),
              labels[rclasses[i]])
     # license recognition
     if labels[rclasses[i]] not in ['bus', 'car']:
         continue
     roi, cands = recognize_plate(roi)
     # mark
     for lp_str, conf, rect, lp_colr, lp_str_, conf, length in cands:
         if conf < 0.7:
             continue
         left_, top_, width_, height_ = rect
         frame[top:top+height,left:left+width,:] = \
                 drawRectBox(roi,(int(left_),int(top_),int(width_),int(height_)),lp_str)
         break
 for case in switch(mode):
     if case('displaying'):
         frame = cv2.resize(frame, screen_size)
         cv2.imshow('demo', frame)
         break
     if case('recoding'):
         writer.write(frame)
         break
     if case('mix'):
         frame = cv2.resize(frame, screen_size)
         cv2.imshow('demo', frame)
         writer.write(frame)
         break
 # Wait for Esc key to stop
 if cv2.waitKey(5) == 27:
     cv2.destroyAllWindows()