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
|
class Detection():
"""Detection Tout genre."""
def __init__(self, **kwargs):
""""""
self.count = 0 # Compter principale de fichiers
self.listFile = [] # List tous les fichiers
self.listFileA = [] # List les bons fichiers
self.listDir = [] # Tous les fichiers du repertoire choisit
if kwargs:
for key, value in kwargs.items():
setattr(self, key, value)
print key, value
#Probleme 1
if self.dirfile == 'file':
if self.img:
for a in self.img:
if os.path.isfile(a):
self.listFile.append(a)
for b in self.listFile:
if b.split('.')[1] in supported_type:
self.listFileA.append(b)
self.count += 1
print ('%s : %s ')%(self.count,self.listFileA)
#Probleme 2
elif self.dirfile == 'dir':
if self.img:
for a in self.img:
if os.path.isdir(a):
for (path, dirs, files) in os.walk(a):
for b in files:
if b.split('.')[1] in supported_type:
self.listDir.append(b)
self.count += 1
else:
print 'Directorie doesnt exist : %s'%a
print self.listDir
def Main():
"""Principale"""
#Argument PArser..
useRead = "usage PROG READ <fileORdir> ,<file1.txt><file2.txt>OR<dir>, --mode --eye ... )"
useWebcam = "usage PROG WEBCAM --mode --eye ... )"
useTest = "usage PROG TEST ..."
parser = argparse.ArgumentParser(prog='PROG', add_help=True)
subparsers = parser.add_subparsers(help='commands')
read_parser = subparsers.add_parser('read', help='Read/write one file', usage=useRead)
read_parser.add_argument("dirfile", nargs='?', action='store', const='file', help='Choix entre file/dir')
read_parser.add_argument("img", nargs='+', action='store', help="Your pictures")
read_parser.add_argument("--mode", nargs='?', const=1, type=int, help="Choosing mode Reading")
read_parser.add_argument("--eye", action='store_true', help="See Eyes", default=False)
read_parser.add_argument("--write", nargs='?', action='store', help="Write on disk", default=False)
webcam_parser = subparsers.add_parser('webcam', help='Write files/directories')
webcam_parser.add_argument("--mode", nargs='?', const=1, type=int, help="Choosing mode Reading")
webcam_parser.add_argument("--eye", action='store_true', help="See Eyes", default=False)
webcam_parser.add_argument("--write", nargs='?', const=1, action='store', help="Write on disk", default=False)
test_parser = subparsers.add_parser('test', help='Test File, before Writing.')
test_parser.add_argument("img", nargs='+', action='store', help="Your pictures")
test_parser.add_argument("--mode", nargs='?', const=1, type=int, help="Choosing mode Reading")
test_parser.add_argument("--eye", action='store_true', help="See Eyes", default=False)
#Verbose level
parser.add_argument('--verbose', '-v', action='count')
#parser.add_argument('args', nargs=argparse.REMAINDER)
args = parser.parse_args()
abc = Detection(**vars(args))
if __name__ == '__main__':
Main() |
Partager