def zipUpDir(self, myzip, tdir, localname):
     currentdir = tdir
     if localname != "":
         currentdir = os.path.join(currentdir,localname)
     list = path.listdir(currentdir)
     for file in list:
         afilename = file
         localfilePath = os.path.join(localname, afilename)
         realfilePath = os.path.join(currentdir,file)
         if path.isfile(realfilePath):
             myzip.write(pathof(realfilePath), pathof(localfilePath), zipfile.ZIP_DEFLATED)
         elif path.isdir(realfilePath):
             self.zipUpDir(myzip, tdir, localfilePath)
示例#2
0
 def zipUpDir(self, myzip, tdir, localname):
     currentdir = tdir
     if localname != "":
         currentdir = os.path.join(currentdir, localname)
     list = path.listdir(currentdir)
     for file in list:
         afilename = file
         localfilePath = os.path.join(localname, afilename)
         realfilePath = os.path.join(currentdir, file)
         if path.isfile(realfilePath):
             myzip.write(pathof(realfilePath), pathof(localfilePath),
                         zipfile.ZIP_DEFLATED)
         elif path.isdir(realfilePath):
             self.zipUpDir(myzip, tdir, localfilePath)
示例#3
0
    def makeEPUB(self, usedmap, obfuscate_data, uid):
        bname = os.path.join(self.k8dir, self.getInputFileBasename() + '.epub')
        # Create an encryption key for Adobe font obfuscation
        # based on the epub's uid
        if obfuscate_data:
            key = re.sub(r'[^a-fA-F0-9]', '', uid)
            key = binascii.unhexlify((key + key)[:32])

        # copy over all images and fonts that are actually used in the ebook
        # and remove all font files from mobi7 since not supported
        imgnames = path.listdir(self.imgdir)
        for name in imgnames:
            if usedmap.get(name, 'not used') == 'used':
                filein = os.path.join(self.imgdir, name)
                if name.endswith(".ttf"):
                    fileout = os.path.join(self.k8fonts, name)
                elif name.endswith(".otf"):
                    fileout = os.path.join(self.k8fonts, name)
                elif name.endswith(".failed"):
                    fileout = os.path.join(self.k8fonts, name)
                else:
                    fileout = os.path.join(self.k8images, name)
                data = open(pathof(filein), 'rb').read()
                if obfuscate_data:
                    if name in obfuscate_data:
                        data = mangle_fonts(key, data)
                open(pathof(fileout), 'wb').write(data)
                if name.endswith(".ttf") or name.endswith(".otf"):
                    os.remove(pathof(filein))

        # opf file name hard coded to "content.opf"
        container = '<?xml version="1.0" encoding="UTF-8"?>\n'
        container += '<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">\n'
        container += '    <rootfiles>\n'
        container += '<rootfile full-path="OEBPS/content.opf" media-type="application/oebps-package+xml"/>'
        container += '    </rootfiles>\n</container>\n'
        fileout = os.path.join(self.k8metainf, 'container.xml')
        open(pathof(fileout), 'wb').write(container)

        if obfuscate_data:
            encryption = '<encryption xmlns="urn:oasis:names:tc:opendocument:xmlns:container" \
xmlns:enc="http://www.w3.org/2001/04/xmlenc#" xmlns:deenc="http://ns.adobe.com/digitaleditions/enc">\n'

            for font in obfuscate_data:
                encryption += '  <enc:EncryptedData>\n'
                encryption += '    <enc:EncryptionMethod Algorithm="http://ns.adobe.com/pdf/enc#RC"/>\n'
                encryption += '    <enc:CipherData>\n'
                encryption += '      <enc:CipherReference URI="OEBPS/Fonts/' + font + '"/>\n'
                encryption += '    </enc:CipherData>\n'
                encryption += '  </enc:EncryptedData>\n'
            encryption += '</encryption>\n'
            fileout = os.path.join(self.k8metainf, 'encryption.xml')
            open(pathof(fileout), 'wb').write(encryption)

        # ready to build epub
        self.outzip = zipfile.ZipFile(pathof(bname), 'w')

        # add the mimetype file uncompressed
        mimetype = 'application/epub+zip'
        fileout = os.path.join(self.k8dir, 'mimetype')
        open(pathof(fileout), 'wb').write(mimetype)
        nzinfo = ZipInfo('mimetype', compress_type=zipfile.ZIP_STORED)
        self.outzip.writestr(nzinfo, mimetype)

        self.zipUpDir(self.outzip, self.k8dir, 'META-INF')

        self.zipUpDir(self.outzip, self.k8dir, 'OEBPS')
        self.outzip.close()
    def makeEPUB(self, usedmap, obfuscate_data, uid):
        bname = os.path.join(self.k8dir, self.getInputFileBasename() + '.epub')
        # Create an encryption key for Adobe font obfuscation
        # based on the epub's uid
        if obfuscate_data:
            key = re.sub(r'[^a-fA-F0-9]', '', uid)
            key = binascii.unhexlify((key + key)[:32])

        # copy over all images and fonts that are actually used in the ebook
        # and remove all font files from mobi7 since not supported
        imgnames = path.listdir(self.imgdir)
        for name in imgnames:
            if usedmap.get(name,'not used') == 'used':
                filein = os.path.join(self.imgdir,name)
                if name.endswith(".ttf"):
                    fileout = os.path.join(self.k8fonts,name)
                elif name.endswith(".otf"):
                    fileout = os.path.join(self.k8fonts,name)
                elif name.endswith(".failed"):
                    fileout = os.path.join(self.k8fonts,name)
                else:
                    fileout = os.path.join(self.k8images,name)
                data = open(pathof(filein),'rb').read()
                if obfuscate_data:
                    if name in obfuscate_data:
                        data = mangle_fonts(key, data)
                open(pathof(fileout),'wb').write(data)
                if name.endswith(".ttf") or name.endswith(".otf"):
                    os.remove(pathof(filein))

        # opf file name hard coded to "content.opf"
        container = '<?xml version="1.0" encoding="UTF-8"?>\n'
        container += '<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">\n'
        container += '    <rootfiles>\n'
        container += '<rootfile full-path="OEBPS/content.opf" media-type="application/oebps-package+xml"/>'
        container += '    </rootfiles>\n</container>\n'
        fileout = os.path.join(self.k8metainf,'container.xml')
        open(pathof(fileout),'wb').write(container)

        if obfuscate_data:
            encryption = '<encryption xmlns="urn:oasis:names:tc:opendocument:xmlns:container" \
xmlns:enc="http://www.w3.org/2001/04/xmlenc#" xmlns:deenc="http://ns.adobe.com/digitaleditions/enc">\n'
            for font in obfuscate_data:
                encryption += '  <enc:EncryptedData>\n'
                encryption += '    <enc:EncryptionMethod Algorithm="http://ns.adobe.com/pdf/enc#RC"/>\n'
                encryption += '    <enc:CipherData>\n'
                encryption += '      <enc:CipherReference URI="OEBPS/Fonts/' + font + '"/>\n'
                encryption += '    </enc:CipherData>\n'
                encryption += '  </enc:EncryptedData>\n'
            encryption += '</encryption>\n'
            fileout = os.path.join(self.k8metainf,'encryption.xml')
            open(pathof(fileout),'wb').write(encryption)

        # ready to build epub
        self.outzip = zipfile.ZipFile(pathof(bname), 'w')

        # add the mimetype file uncompressed
        mimetype = 'application/epub+zip'
        fileout = os.path.join(self.k8dir,'mimetype')
        open(pathof(fileout),'wb').write(mimetype)
        nzinfo = ZipInfo('mimetype', compress_type=zipfile.ZIP_STORED)
        self.outzip.writestr(nzinfo, mimetype)

        self.zipUpDir(self.outzip,self.k8dir,'META-INF')

        self.zipUpDir(self.outzip,self.k8dir,'OEBPS')
        self.outzip.close()
示例#5
0
# -*- coding: utf-8 -*-

import dlib
import cv2
import sqite3
from contextlib import closing
import numpy as np
import path
from os import argv

dbname = "register_face.db"
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor("file_path")
images_path = argv[1]
images_list = path.listdir(images_path)


def register(name, image):
    with closing(sqite3.connect(dbname)) as conn:
        c = conn.cursor()

        create_table = '''create table if not exists {} (
                          id integer primary key autoincrement,
                          eye_surrounding real,
                          eye_distance real,
                          eye2eyebrw real,
                          mouse_surrounding real,
                          mouse_distance real,
                          mouse2nose real,
                          base_distance real)
                          '''.format(name)