Esempio n. 1
0
def clean():
    from shutil import rmtree
    label("Cleaning temp directory...")
    try:
        rmtree(temp)
    except Exception as e:
        if type(e) != FileNotFoundError:
            fatal("Can't access temp directory!", e=e)
        pass
Esempio n. 2
0
def install(url):
    import os
    import wget

    label("Descargando actualización...")
    out = os.path.join(temp, "basa3pdf.exe")
    wget.download(url, out=out)

    import subprocess
    label("Instalando actualización...")
    subprocess.Popen([out])
    os._exit(1)
Esempio n. 3
0
def clean():
    label("Limpiando archivos viejos...")
    import time

    now = time.time()
    for f in os.listdir(temp):
        f = os.path.join(temp, f)
        if os.stat(f).st_mtime < now - tempHalfLife:
            try:
                os.remove(f)
            except:
                pass
Esempio n. 4
0
def _extract(file):
    # Extract zip file (if fails prompt for password)
    label("Extracting archive...")
    from zipfile import ZipFile
    archive = ZipFile(file)
    password = ""
    while True:
        try:
            output = temp + file[file.rfind('/') + 1:file.rfind('.')]
            archive.extractall(output, pwd=bytes(password, 'utf-8'))
            break
        except:
            password = ask("Password",
                           "The file is encrypted and needs a password:"******"Password is needed to extract archive!")
            pass
Esempio n. 5
0
def task(file):
    try:
        update.check()
    except Exception as e:
        print(e)
        pass

    label("Abriendo archivo...")

    import os

    if len(file) < 2:
        fatal("No se encuentra el archivo")
    file = file[1]

    if not file.endswith('.basa'):
        fatal("No se encuentra el archivo")

    try:
        directory = file[:file.rindex('.basa')]
    except Exception as e:
        fatal("No se puede abrir el archivo:", e)

    try:
        i = directory.find(".xlsx")
        j = directory.find(".docx")
        k = directory.rfind("\\")
        label("Generando PDF...")
        if i > -1:
            outFile = directory[k+1:i] + directory[i+5:] + ".pdf"
            outFile = os.path.join(temp, outFile)
            xlsx(file, outFile)
        elif j > -1:
            outFile = directory[k+1:j] + directory[j+5:] + ".pdf"
            outFile = os.path.join(temp, outFile)
            docx(file, outFile)
        else:
            fatal("No se encuentra el archivo")
        os.startfile(outFile, 'open')
        clean()
        os._exit(1)
    except Exception as e:
        fatal("No se puede abrir el archivo:", e)
Esempio n. 6
0
def check():
    global version

    if previousCheck():
        return

    label("Buscando actualizaciones...")

    import requests
    r = requests.get(checkURL).json()

    if float(r["tag_name"]) <= checkVersion:
        return

    answer = confirm("Actualizar basa3pdf",
                     "Hay una nueva versión disponible. ¿Instalar ahora?")

    if answer != "yes":
        return

    install(r["assets"][0]["browser_download_url"])
Esempio n. 7
0
def convert():
    # Check if app is in another process
    from subprocess import check_output
    from shutil import copy2
    s = check_output('tasklist', shell=True)
    if s.count(b"pymanga") > 1:
        fatal("Pymanga is already running on another process!")

    # Prompt for archive
    archives = selectzip("Open archive(s) to use:")

    # Extract and read zip file
    files, skipped = zip.read(archives)
    if len(skipped):
        confirm("The following files will not be included:", str(skipped))

    # Select output file
    from pathlib import Path
    from os.path import commonprefix
    outFile = path.basename(commonprefix(archives))
    if "." in outFile:
        outFile = outFile.split(".")[0]

    if False:  # confirm("Choose format", "Do you want to convert the .cbz to .pdf?") == "yes":

        label("Creating .pdf file...")
        command = [imagemagick]
        command.extend(files)

        # Add extension to output file
        outFile = path.join(temp, outFile + ".pdf")
        command.append(outFile)

        # Convert file using ImageMagick
        from subprocess import Popen, PIPE, STDOUT
        p = Popen(command, stdin=PIPE, stdout=PIPE, stderr=STDOUT, encoding='UTF8')

        # Wait for process to finish
        from time import sleep
        while p.poll() is None:
            sleep(1)
        response = p.stdout.readline()
        if response != "":
            fatal("Can't convert to pdf!", response)

    else:

        label("Creating .cbz file...")

        # Add extension to output file
        outFile = path.join(temp, outFile + ".cbz")

        # Copy all images in order to root of temp folder
        order = 0
        pages = []
        fill = len(str(len(files))) + 1
        for file in files:
            order += 1
            page = str(order).zfill(fill) + file[file.rfind('.'):]
            copy2(file, page)
            pages.append(page)

        # Create .cbz file
        zip.create(pages, outFile)

    # Save output file to Desktop or open with default editor
    outFile2 = path.join(Path.home(), "Desktop", path.basename(outFile))
    try:
        copy2(outFile, outFile2)
    except Exception as e:
        fatal("Error copying file!", e=e)

    success("File saved to the desktop successfully!")

    from os import _exit
    _exit(1)