Example #1
0
 def test_runscript_template(self):
     """Check the location & content of the template for the run script."""
     assert access(build_path(self.BASE_DIR, "runscript.pytemplate"),
                   FILE_IS_READABLE), "Can't find the runscript template"
     template_file = open(build_path(self.BASE_DIR, "runscript.pytemplate"))
     assert sha256(template_file.read().encode('ascii')).hexdigest()\
         == 'df42d02d957ef5ef0f7aaa5adda7fc1bbca12101c40451c35ff9769b2e5b7c1c',\
         "Runscript contents are wrong."
     template_file.close()
     assert stat(build_path(self.BASE_DIR,
                            "runscript.pytemplate")).st_uid == self.UandGID
     assert stat(build_path(self.BASE_DIR,
                            "runscript.pytemplate")).st_gid == self.UandGID
Example #2
0
 def test_Dockerfile_template(self):
     """Check the location and content of Dockerfile.pytemplate."""
     assert access(build_path(self.BASE_DIR, "Dockerfile.pytemplate"),
                   FILE_IS_READABLE), "Can't access Dockefile template"
     template_file = open(build_path(self.BASE_DIR,
                                     'Dockerfile.pytemplate'))
     assert sha256(template_file.read().encode('ascii')).hexdigest()\
         == 'c1f4cd3244dde9c8f2fc1f8dc56de5b7798ca03636d5d1cfa4b9cdd075e0678c',\
         "Dockerfile template file contents are wrong"
     template_file.close()
     assert stat(build_path(self.BASE_DIR,
                            'Dockerfile.pytemplate')).st_uid == self.UandGID
     assert stat(build_path(self.BASE_DIR,
                            'Dockerfile.pytemplate')).st_gid == self.UandGID
Example #3
0
class TestFiles():
    """Tests for files that should be present after setup."""
    BASE_DIR = build_path('/', 'usr', 'share', 'docker-gui')
    UandGID = 1000

    def test_post_setup_config(self):
        """During setup, the user is asked to choose the user.

        In my case (as well as most Linux users who are the primary user), that
        user has UID/GID 1000. This test simply tests that that is the case,
        although it may not be depending on the user you choose.
        """
        assert Config.user == self.UandGID
        assert Config.group == self.UandGID

    def test_base_folder(self):
        """Check for the base directory."""
        assert access(self.BASE_DIR, FILE_EXISTS), "Base dir doesn't exist"
        assert isdir(self.BASE_DIR), "Base dir {}.".format(
            "is a file, when it's supposed to be a directory" if access(
                self.BASE_DIR, FILE_EXISTS) else "doesn't exist")
        assert access(
            self.BASE_DIR, FILE_IS_WRITABLE
            | FILE_IS_EXECUTABLE), "Permissions aren't right on base dir"
        assert stat(self.BASE_DIR).st_uid == self.UandGID
        assert stat(self.BASE_DIR).st_gid == self.UandGID

    def test_Dockerfile_template(self):
        """Check the location and content of Dockerfile.pytemplate."""
        assert access(build_path(self.BASE_DIR, "Dockerfile.pytemplate"),
                      FILE_IS_READABLE), "Can't access Dockefile template"
        template_file = open(build_path(self.BASE_DIR,
                                        'Dockerfile.pytemplate'))
        assert sha256(template_file.read().encode('ascii')).hexdigest()\
            == 'c1f4cd3244dde9c8f2fc1f8dc56de5b7798ca03636d5d1cfa4b9cdd075e0678c',\
            "Dockerfile template file contents are wrong"
        template_file.close()
        assert stat(build_path(self.BASE_DIR,
                               'Dockerfile.pytemplate')).st_uid == self.UandGID
        assert stat(build_path(self.BASE_DIR,
                               'Dockerfile.pytemplate')).st_gid == self.UandGID

    def test_runscript_template(self):
        """Check the location & content of the template for the run script."""
        assert access(build_path(self.BASE_DIR, "runscript.pytemplate"),
                      FILE_IS_READABLE), "Can't find the runscript template"
        template_file = open(build_path(self.BASE_DIR, "runscript.pytemplate"))
        assert sha256(template_file.read().encode('ascii')).hexdigest()\
            == 'df42d02d957ef5ef0f7aaa5adda7fc1bbca12101c40451c35ff9769b2e5b7c1c',\
            "Runscript contents are wrong."
        template_file.close()
        assert stat(build_path(self.BASE_DIR,
                               "runscript.pytemplate")).st_uid == self.UandGID
        assert stat(build_path(self.BASE_DIR,
                               "runscript.pytemplate")).st_gid == self.UandGID
Example #4
0
def make_outfile(path, infile, ext=None):
    name, oldext = splitext(basename(infile))
    return build_path(path, ".".join((name, ext if ext else oldext)))
Example #5
0
def make_basename(path, infile):
    return build_path(path, splitext(basename(infile))[0])
Example #6
0
def main(argv):
    import logging

    # Parse commandline
    args = parse_args(argv)

    logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)

    profile = load_profile(args.profile)

    print("\033[36mXConv %s (c) Taeyeon Mori\033[0m" % version)
    print("\033[34mProfile: %s\033[0m" % args.profile)

    unknown_defines = [
        n for n in args.define.keys() if n not in profile.defines
    ]
    if unknown_defines:
        print(
            "\033[33mWarning: Unknown defines %s; see '%s -i %s' for avaliable defines in this profile\033[0m"
            % (", ".join(unknown_defines), argv[0], args.profile))

    if args.create_directory:
        makedirs(args.output_directory, exist_ok=True)

    if not args.output_filename and not isdir(args.output_directory):
        print("\033[31mOutput location '%s' is not a directory.\033[0m" %
              args.output_directory)
        return -1

    # Initialize AAV
    aav = Manager(ffmpeg=args.ffmpeg,
                  ffprobe=args.ffprobe,
                  workers=args.concurrent)

    if args.quiet:
        aav.global_conv_args = "-loglevel", "warning"

    aav.global_args += "-hide_banner", "-stats"

    # Collect Tasks
    tasks = []

    print("\033[35mCollecting Tasks..\033[0m")

    if args.merge:
        tasks.append(create_task(aav, profile, args.inputs, args))

    elif args.concat:
        import tempfile, os
        tmp = tempfile.NamedTemporaryFile(mode="w", delete=False)

        with tmp:
            tmp.write("ffconcat version 1.0\n")
            tmp.write("# XConv concat file\n")
            for f in map(abspath, args.inputs):
                print("\033[36m  Concatenating %s\033[0m" % basename(f))
                tmp.write("file '%s'\n" % f)

        task = create_task(aav,
                           profile, (),
                           args,
                           filename_from=args.inputs[0])

        task.add_input(tmp.name).set(f="concat", safe="0")

        tasks.append(task)

    else:
        for input in args.inputs:
            tasks.append(create_task(aav, profile, (input, ), args))

    print("\033[35mPreparing Tasks..\033[0m")

    # Prepare profile parameters
    pkw = {}
    if profile.defines:
        pkw["defines"] = args.define
    if profile.features:
        if "argshax" in profile.features:
            pkw["args"] = args

    # Apply profile
    for task in tasks:
        print("\033[32m  Applying profile for '%s'\033[0m" % task_name(task),
              end="\033[K\r")
        res = profile(task, **pkw)
        if not res:
            print("\033[31m  Failed to apply profile for '%s'\033[0m\033[K" %
                  task_name(task))
            return 1

    if args.update:
        for task in tasks[:]:
            for output in [o for o in task.outputs if exists(o.filename)]:
                print(
                    "\033[33m  Skipping existing '%s' (--update)\033[0m\033[K"
                    % output.name)
                task.outputs.remove(output)
            if not tasks.outputs:
                print(
                    "\033[33m  Skipping task '%s' because no output files are left\033[0m\033[K"
                    % task_name(task))
                tasks.remove(task)

    print("\033[35mExecuting Tasks..\033[0m\033[K")

    # Paralellize
    if args.concurrent > 1 and not args.merge and not args.concat:
        tasks = sum([task.split(args.concurrent) for task in tasks], [])

        # Commit
        [t.commit2() for t in tasks]
        aav.process_queue()
        aav.wait()

    else:
        for task in tasks:
            print("\033[32m  Processing '%s'\033[0m" % task_name(task))
            task.commit()

    # Clean up
    if args.concat:
        os.unlink(tmp.name)

    # Copy files
    if args.copy_files:
        print("\033[35mCopying Files..\033[0m\033[K")
        for file in args.copy_files:
            print("\033[32m  Copying '%s'\033[0m\033[K" % basename(file))
            copyfile(file, build_path(args.output_directory, basename(file)))

    print("\033[35mDone.\033[0m\033[K")

    return 0
Example #7
0
def make_outfile(path, infile, ext=None):
    name, oldext = splitext(basename(infile))
    return build_path(path, ".".join((name, ext if ext else oldext)))
Example #8
0
def make_basename(path, infile):
    return build_path(path, splitext(basename(infile))[0])
Example #9
0
def main(argv):
    import logging

    # Parse commandline
    args = parse_args(argv)

    logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)

    profile = load_profile(args.profile)

    print("\033[36mXConv %s (c) Taeyeon Mori\033[0m" % version)
    print("\033[34mProfile: %s\033[0m" % args.profile)

    unknown_defines = [n for n in args.define.keys() if n not in profile.defines]
    if unknown_defines:
        print("\033[33mWarning: Unknown defines %s; see '%s -i %s' for avaliable defines in this profile\033[0m" %
              (", ".join(unknown_defines), argv[0], args.profile))

    if args.create_directory:
        makedirs(args.output_directory, exist_ok=True)

    if not args.output_filename and not isdir(args.output_directory):
        print("\033[31mOutput location '%s' is not a directory.\033[0m" % args.output_directory)
        return -1

    # Initialize AAV
    aav = Manager(ffmpeg=args.ffmpeg, ffprobe=args.ffprobe, workers=args.concurrent)

    if args.quiet:
        aav.global_conv_args = "-loglevel", "warning"

    aav.global_args += "-hide_banner", "-stats"

    # Collect Tasks
    tasks = []

    print("\033[35mCollecting Tasks..\033[0m")

    if args.merge:
        tasks.append(create_task(aav, profile, args.inputs, args))

    elif args.concat:
        import tempfile, os
        tmp = tempfile.NamedTemporaryFile(mode="w", delete=False)

        with tmp:
            tmp.write("ffconcat version 1.0\n")
            tmp.write("# XConv concat file\n")
            for f in map(abspath, args.inputs):
                print("\033[36m  Concatenating %s\033[0m" % basename(f))
                tmp.write("file '%s'\n" % f)

        task = create_task(aav, profile, (), args, filename_from=args.inputs[0])

        task.add_input(tmp.name).set(f="concat", safe="0")

        tasks.append(task)

    else:
        for input in args.inputs:
            tasks.append(create_task(aav, profile, (input,), args))

    print("\033[35mPreparing Tasks..\033[0m")

    # Prepare profile parameters
    pkw = {}
    if profile.defines:
        pkw["defines"] = args.define
    if profile.features:
        if "argshax" in profile.features:
            pkw["args"] = args

    # Apply profile
    for task in tasks:
        print("\033[32m  Applying profile for '%s'\033[0m" % task_name(task), end="\033[K\r")
        res = profile(task, **pkw)
        if not res:
            print("\033[31m  Failed to apply profile for '%s'\033[0m\033[K" % task_name(task))
            return 1

    if args.update:
        for task in tasks[:]:
            for output in [o for o in task.outputs if exists(o.filename)]:
                print("\033[33m  Skipping existing '%s' (--update)\033[0m\033[K" % output.name)
                task.outputs.remove(output)
            if not tasks.outputs:
                print("\033[33m  Skipping task '%s' because no output files are left\033[0m\033[K" % task_name(task))
                tasks.remove(task)

    print("\033[35mExecuting Tasks..\033[0m\033[K")

    # Paralellize
    if args.concurrent > 1 and not args.merge and not args.concat:
        tasks = sum([task.split(args.concurrent) for task in tasks], [])

    # Commit
        [t.commit2() for t in tasks]
        aav.process_queue()
        aav.wait()

    else:
        for task in tasks:
            print("\033[32m  Processing '%s'\033[0m" % task_name(task))
            task.commit()

    # Clean up
    if args.concat:
        os.unlink(tmp.name)

    # Copy files
    if args.copy_files:
        print("\033[35mCopying Files..\033[0m\033[K")
        for file in args.copy_files:
            print("\033[32m  Copying '%s'\033[0m\033[K" % basename(file))
            copyfile(file, build_path(args.output_directory, basename(file)))

    print("\033[35mDone.\033[0m\033[K")

    return 0