コード例 #1
0
    def html(self, images_dir, reldir):
        html = ""
        html += HTML.header(title="Debugging - Kumiko processing steps", reldir=reldir)

        for i in range(len(self.steps) - 1):
            j = i + 1

            # Display debug images
            if self.steps[i]["name"] in self.images:
                html += HTML.imgbox(self.images[self.steps[i]["name"]])

            # Display panels diffs
            self.infos["panels"] = list(
                map(lambda p: p.to_xywh(), self.steps[i]["panels"])
            )
            json1 = self.infos.copy()
            self.infos["panels"] = list(
                map(lambda p: p.to_xywh(), self.steps[j]["panels"])
            )
            json2 = self.infos.copy()

            files_diff = Debug.get_files_diff(images_dir, [json1], [json2])

            step_name = str(i + 1) + ". " + self.steps[j]["name"]

            if len(files_diff) == 0:
                html += "<h2>{} - no change</h2>".format(step_name)

            for filename in files_diff:
                html += HTML.side_by_side_panels(
                    step_name,
                    "took {0:.2f} seconds".format(
                        self.steps[j]["elapsed_since_last_step"] / pow(10, 9)
                    ),
                    files_diff[filename]["jsons"],
                    "BEFORE - {} panels".format(
                        len(files_diff[filename]["jsons"][0][0]["panels"])
                    ),
                    "AFTER  - {} panels".format(
                        len(files_diff[filename]["jsons"][1][0]["panels"])
                    ),
                    images_dir=files_diff[filename]["images_dir"],
                    known_panels=files_diff[filename]["known_panels"],
                )

        html += HTML.footer
        return html
コード例 #2
0
class MovieExport:

    def __init__(self):
        # Create a new empty html object
        self.output = HTML('html')
        self.count = 0

    def add_movie(self, movie):
        """
        Add a movie object to the output html
        :param movie: A Movie object
        :return: None
        """
        # Create a new table on the html
        t = self.output.body.table(border="1")
        # Add a first row
        r = t.tr
        # Write title and director on the first row
        # Also define 20/80% ratio for 2 cells
        r.td(movie.director, width="20%")
        r.td(movie.title)
        # Add a secod row
        r2 = t.tr
        # Write section and duration on the second row
        r2.td(movie.section)
        r2.td(movie.duration)
        # Add a third row
        r3 = t.tr
        # Start with an empty row then write the synopse
        r3.td()
        r3.td(movie.synopse)
        # Add a line break after the table
        self.output.body.br()
        # Add 1 to the movie counter
        self.count += 1
        # This function returns nothing
        return None

    def save_to_file(self, filename):
        """
        Saves the added film to an html file
        :param filename: str: filename
        :return: None
        """
        # Open the filename to be re-written
        with open(filename, 'w+', encoding='utf-8') as outfile:
            # write the content of the html output to the file
            outfile.write(self.output.__str__())
コード例 #3
0
    def compare_all(self):
        self.max_diffs = 20

        for i in range(len(self.git_versions) - 1):
            v1 = self.git_versions[i]
            v2 = self.git_versions[i + 1]
            print('\n########## Comparing kumiko results between versions', v1,
                  'and', v2, '##########')

            files_diff = {}

            for file_or_dir in self.files:

                if len(files_diff) > 20:
                    print(
                        'The maximum number of differences in files (20) has been reached, stopping'
                    )
                    break

                with open(
                        os.path.join(self.savedir, v1,
                                     os.path.basename(file_or_dir) +
                                     '.json')) as fh:
                    json1 = json.load(fh)
                with open(
                        os.path.join(self.savedir, v2,
                                     os.path.basename(file_or_dir) +
                                     '.json')) as fh:
                    json2 = json.load(fh)

                files_diff.update(
                    Debug.get_files_diff(file_or_dir, json1, json2))

            print('Found', len(files_diff), 'differences')

            if not self.options['html']:
                return

            print('Generating HTML diff file')

            html_diff_file = os.path.join(self.savedir,
                                          'diff-' + v1 + '-' + v2 + '.html')
            diff_file = open(html_diff_file, 'w')
            diff_file.write(HTML.header('Comparing Kumiko results', '../../'))

            diff_file.write(HTML.nbdiffs(files_diff))

            for img in files_diff:
                diff_file.write(
                    HTML.side_by_side_panels(
                        img,
                        '',
                        files_diff[img]['jsons'],
                        v1,
                        v2,
                        images_dir=files_diff[img]['images_dir'],
                        known_panels=files_diff[img]['known_panels']))

            diff_file.write(HTML.footer)
            diff_file.close()

            if self.options['browser']:
                subprocess.run([self.options['browser'], html_diff_file])
コード例 #4
0
    def compare_all(self):
        self.max_diffs = 20

        for i in range(len(self.git_versions) - 1):
            v1 = self.git_versions[i]
            v2 = self.git_versions[i + 1]
            print(
                "\n########## Comparing kumiko results between versions",
                v1,
                "and",
                v2,
                "##########",
            )

            files_diff = {}

            for file_or_dir in self.files:

                if len(files_diff) > 20:
                    print(
                        "The maximum number of differences in files (20) has been reached, stopping"
                    )
                    break

                with open(
                        os.path.join(self.savedir, v1,
                                     os.path.basename(file_or_dir) +
                                     ".json")) as fh:
                    json1 = json.load(fh)
                with open(
                        os.path.join(self.savedir, v2,
                                     os.path.basename(file_or_dir) +
                                     ".json")) as fh:
                    json2 = json.load(fh)

                files_diff.update(
                    Debug.get_files_diff(file_or_dir, json1, json2))

            print("Found", len(files_diff), "differences")

            if not self.options["html"]:
                return

            print("Generating HTML diff file")

            html_diff_file = os.path.join(self.savedir,
                                          "diff-" + v1 + "-" + v2 + ".html")
            diff_file = open(html_diff_file, "w")
            diff_file.write(HTML.header("Comparing Kumiko results", "../../"))

            diff_file.write(HTML.nbdiffs(files_diff))

            for img in files_diff:
                diff_file.write(
                    HTML.side_by_side_panels(
                        img,
                        "",
                        files_diff[img]["jsons"],
                        v1,
                        v2,
                        images_dir=files_diff[img]["images_dir"],
                        known_panels=files_diff[img]["known_panels"],
                    ))

            diff_file.write(HTML.footer)
            diff_file.close()

            if self.options["browser"]:
                subprocess.run([self.options["browser"], html_diff_file])
コード例 #5
0
def main():
    args = parser.parse_args()
    k = Kumiko(
        {
            "debug": args.debug,
            "progress": args.progress,
            "rtl": args.rtl,
            "min_panel_size_ratio": args.min_panel_size_ratio[0]
            if args.min_panel_size_ratio
            else False,
        }
    )

    file_or_folder = args.input[0]
    folder = None
    html_file = None

    # Folder
    if len(args.input) == 1 and os.path.isdir(args.input[0]):
        folder = args.input[0]
        if folder[-1] == "/":
            folder = folder[0:-1]
        info = k.parse_dir(folder)
        html_file = os.path.join("tests/results", os.path.basename(folder) + ".html")

    # File
    elif len(args.input) == 1 and os.path.isfile(args.input[0]):
        f = args.input[0]
        folder = os.path.dirname(f)
        if not folder:
            folder = "./"
        info = k.parse_images([f])
        html_file = os.path.join("tests/results", os.path.basename(f) + ".html")

    # URL list
    else:
        folder = "urls"
        info = k.parse_url_list(args.input)
        filehash = hashlib.sha1(";".join(sorted(args.input)).encode()).hexdigest()
        html_file = os.path.join("tests/results", filehash + ".html")

    if len(info) == 0:
        print(
            "--input (-i) is not a file, or directory, or URL list: '"
            + str(args.input)
            + "'"
        )
        sys.exit(1)

    info = json.dumps(info)

    # Generate HTML
    if args.html or args.browser or args.html_static_dir or args.debug:
        images_dir = (
            "urls"
            if folder == "urls"
            else os.path.relpath(folder, "tests/results") + "/"
        )
        reldir = args.html_static_dir[0] if args.html_static_dir else "../../"

        html = ""
        if args.debug:
            html = k.dbg.html(folder, reldir)
        else:
            html += HTML.header(reldir=reldir)
            html += HTML.reader(info, images_dir)
            html += HTML.footer

        if args.output:
            html_file = args.output[0]

        if args.browser or args.output or args.debug:
            fh = open(html_file, "w")
            fh.write(html)
            fh.close()
            print("Saved HTML file:", html_file)
        else:
            print(html)

    # Or JSON info
    else:
        if args.output:
            f = open(args.output[0], "w")
            f.write(info)
            f.close()
        else:
            print(info)

    # Open in browser
    if args.browser:
        subprocess.run([args.browser[0], html_file])
コード例 #6
0
 def __init__(self):
     # Create a new empty html object
     self.output = HTML('html')
     self.count = 0