コード例 #1
0
def add_preso(db, srcp, dstp):
    if not needs_add(db, srcp, dstp): return

    log("Adding %s..." % srcp)

    common.mkdirs(os.path.join("root", os.path.split(dstp)[0]))

    juno = odptools.odf.juno.juno()
    try:
        preso = juno.desktop.loadComponentFromURL \
            (juno.mkpath(srcp), "_blank", 0,
             (juno.PropertyValue("Hidden", True),
              juno.PropertyValue("ReadOnly", True),
              juno.PropertyValue("FilterName", "impress8")))

        preso.storeToURL(juno.mkpath(os.path.join(os.getcwd(), "root", dstp)),
                         ())

        removepagenumbers(preso.getMasterPages())
        removepagenumbers(preso.getDrawPages())

        sql = insertpreso(srcp, dstp, preso.getDrawPages().getCount())
        sql.extend(createthumbs(juno, dstp, preso))
        sql.extend(insertcontent(dstp, preso))

        log("Committing and disconnecting...")

        doqueries(db, sql)

        preso.dispose()

    finally:
        juno.disconnect()
コード例 #2
0
def add_preso(db, srcp, dstp):
    if not needs_add(db, srcp, dstp): return

    log("Adding %s..." % srcp)

    common.mkdirs(os.path.join("root", os.path.split(dstp)[0]))

    juno = odptools.odf.juno.juno()
    try:
        preso = juno.desktop.loadComponentFromURL \
            (juno.mkpath(srcp), "_blank", 0,
             (juno.PropertyValue("Hidden", True),
              juno.PropertyValue("ReadOnly", True),
              juno.PropertyValue("FilterName", "impress8")))

        preso.storeToURL(juno.mkpath(os.path.join(os.getcwd(), "root", dstp)),
                         ())

        removepagenumbers(preso.getMasterPages())
        removepagenumbers(preso.getDrawPages())

        sql = insertpreso(srcp, dstp, preso.getDrawPages().getCount())
        sql.extend(createthumbs(juno, dstp, preso))
        sql.extend(insertcontent(dstp, preso))

        log("Committing and disconnecting...")

        doqueries(db, sql)

        preso.dispose()

    finally:
        juno.disconnect()
コード例 #3
0
def add_trees():
    procs = []

    q = multiprocessing.Queue()
    for i in range(args["workers"]):
        p = multiprocessing.Process(target = worker, args = (i, q))
        p.start()
        procs.append(p)

    for sync in config["juno-sync"]:
        (srcbase, dstbase) = sync.rsplit(" ", 1)
        for dirpath, dirnames, filenames in os.walk(srcbase):
            if os.path.split(dirpath)[1][0] == ".":
                del dirnames[:]
                continue
            
            created = False
            if dstbase == "home":
                common.mkdirs(os.path.join("root", common.Mapper.s2d(dirpath)))
                created = True

            for f in sorted(filenames):
                if f[0] != ".":
                    if not created:
                        common.mkdirs(os.path.join("root", common.Mapper.s2d(dirpath)))
                        created = True
                    q.put(os.path.join(dirpath, f))

    for p in procs:
        q.put("STOP")

    q.close()
    q.join_thread()

    for p in procs:
        p.join()

    for p in procs:
        if p.exitcode:
            sys.exit(1)
コード例 #4
0
def createthumbs(juno, dstp, preso):
    args = []
    common.mkdirs(os.path.join("slides", dstp))
    common.mkdirs(os.path.join("thumbs", dstp))

    filter = juno.createInstance("com.sun.star.drawing.GraphicExportFilter")

    pages = preso.getDrawPages()
    pagect = pages.getCount()
    for i in range(0, pagect):
        slidep = os.path.join("slides", dstp, "%03u.png" % i)
        thumbp = os.path.join("thumbs", dstp, "%03u.jpg" % i)

        page = pages.getByIndex(i)
        (x, y) = constrain((page.Width, page.Height), slidesize)

        filterdata = juno.Any("[]com.sun.star.beans.PropertyValue",
                              (juno.PropertyValue("PixelWidth", x),
                               juno.PropertyValue("PixelHeight", y)))

        filter.setSourceDocument(page)

        log("Exporting PNG %u/%u..." % (i + 1, pagect))
        filter.filter((juno.PropertyValue("MediaType", "image/png"),
                       juno.PropertyValue("URL", juno.mkpath(slidep)),
                       juno.PropertyValue("FilterData", filterdata)))

        log("Resizing PNGs...")
        im = extend(slidep, slidesize)
        resize(im, thumbp, thumbsize)

        with open(slidep, "rb") as f:
            png = f.read()

        args.append((dstp, i, hashlib.sha1(png).hexdigest()))

    return [["INSERT INTO slides VALUES(?, ?, ?)", args]]
コード例 #5
0
def createthumbs(juno, dstp, preso):
    args = []
    common.mkdirs(os.path.join("slides", dstp))
    common.mkdirs(os.path.join("thumbs", dstp))

    filter = juno.createInstance("com.sun.star.drawing.GraphicExportFilter")

    pages = preso.getDrawPages()
    pagect = pages.getCount()
    for i in range(0, pagect):
        slidep = os.path.join("slides", dstp, "%03u.png" % i)
        thumbp = os.path.join("thumbs", dstp, "%03u.jpg" % i)

        page = pages.getByIndex(i)
        (x, y) = constrain((page.Width, page.Height), slidesize)

        filterdata = juno.Any("[]com.sun.star.beans.PropertyValue",
                              (juno.PropertyValue("PixelWidth", x),
                               juno.PropertyValue("PixelHeight", y)))

        filter.setSourceDocument(page)

        log("Exporting PNG %u/%u..." % (i + 1, pagect))
        filter.filter((juno.PropertyValue("MediaType", "image/png"),
                       juno.PropertyValue("URL", juno.mkpath(slidep)),
                       juno.PropertyValue("FilterData", filterdata)))

        log("Resizing PNGs...")
        im = extend(slidep, slidesize)
        resize(im, thumbp, thumbsize)

        with open(slidep, "rb") as f:
            png = f.read()

        args.append((dstp, i, hashlib.sha1(png).hexdigest()))

    return [["INSERT INTO slides VALUES(?, ?, ?)", args]]
コード例 #6
0
        db.executemany(s[0], s[1])
    db.commit()

def parse_args():
    ap = argparse.ArgumentParser()
    ap.add_argument("-c", action="store_false", dest = "addtrees",
                    help = "clean %s" % config["juno-base"])
    ap.add_argument("-w", dest = "workers", default = 4, type = int,
                    help = "number of workers (default 4)")

    return vars(ap.parse_args())

if __name__ == "__main__":
    config = common.load_config()
    args = parse_args()

    common.mkdirs(config["juno-base"])
    os.chdir(config["juno-base"])

    lock = common.Lock(".lock")

    os.nice(10)

    db = DB(".db")
    check_fs(db)
    check_db(db)
    db.close()

    if args["addtrees"]:
        add_trees()
コード例 #7
0
ファイル: db.py プロジェクト: schenget/satools
        #print sql
        if args:
            return self.db.execute(sql, args)
        else:
            return self.db.execute(sql)

    def executemany(self, sql, params):
        #print sql
        return self.db.executemany(sql, params)


def parse_args():
    ap = argparse.ArgumentParser()
    ap.add_argument("cmd", choices=["create"], help="command")
    return ap.parse_args()


config = common.load_config()

if __name__ == "__main__":
    common.mkdirs(config["juno-base"])
    os.chdir(config["juno-base"])

    args = parse_args()

    if args.cmd == "create":
        DB(".db").createschema()
        common.mkdirs("root")
        common.mkdirs("slides")
        common.mkdirs("thumbs")
コード例 #8
0
ファイル: db.py プロジェクト: jamesread/satools
    def execute(self, sql, args = None):
        #print sql
        if args:
            return self.db.execute(sql, args)
        else:
            return self.db.execute(sql)

    def executemany(self, sql, params):
        #print sql
        return self.db.executemany(sql, params)

def parse_args():
    ap = argparse.ArgumentParser()
    ap.add_argument("cmd", choices=["create"], help = "command")
    return ap.parse_args()

config = common.load_config()

if __name__ == "__main__":
    common.mkdirs(config["juno-base"])
    os.chdir(config["juno-base"])

    args = parse_args()

    if args.cmd == "create":
        DB(".db").createschema()
        common.mkdirs("root")
        common.mkdirs("slides")
        common.mkdirs("thumbs")
コード例 #9
0
                    action="store_false",
                    dest="addtrees",
                    help="clean %s" % config["juno-base"])
    ap.add_argument("-w",
                    dest="workers",
                    default=4,
                    type=int,
                    help="number of workers (default 4)")

    return vars(ap.parse_args())


if __name__ == "__main__":
    config = common.load_config()
    args = parse_args()

    common.mkdirs(config["juno-base"])
    os.chdir(config["juno-base"])

    lock = common.Lock(".lock")

    os.nice(10)

    db = DB(".db")
    check_fs(db)
    check_db(db)
    db.close()

    if args["addtrees"]:
        add_trees()