예제 #1
0
파일: qw.py 프로젝트: dimas3452/qdt
    def save_project_to_file(self, file_name):
        project = self.pht.p

        project.sync_layouts()

        # Ensure that all machine nodes are in corresponding lists
        for d in project.descriptions:
            if isinstance(d, MachineNode):
                d.link(handle_system_bus=False)

        pythonize(project, file_name)
예제 #2
0
파일: qdc-gui.py 프로젝트: ufwt/qdt
    def save_project_to_file(self, file_name):
        self.pw.refresh_layouts()

        project = self.proj

        # Ensure that all machine nodes are in corresponding lists
        for d in project.descriptions:
            if isinstance(d, MachineNode):
                d.link(handle_system_bus=False)

        pythonize(project, file_name)

        self.set_current_file_name(file_name)
        self.saved_operation = self.pht.pos
        self.__check_saved_asterisk__()
예제 #3
0
 def store_cache(self):
     pythonize(self._cache, self.cache_file)
예제 #4
0
def main():
    print("Git Interactive Cloner")

    init_cwd = getcwd()

    ap = ArgumentParser()
    ap.add_argument("source", type=arg_type_git_repository, nargs="?")
    ap.add_argument("-d", "--destination", type=arg_type_new_directory)
    ap.add_argument("-r", "--result-state", type=arg_type_output_file)
    ap.add_argument("-m",
                    "--main-stream",
                    type=arg_type_SHA1_lower,
                    metavar="SHA1",
                    help="""\
Set main stream by SHA1 of one of main stream commits. Only main stream commits
will be cloned. Other commits will be taken as is. A commit belongs to main
stream if it is a descendant of the given commit or both have at least one
common ancestor. Commonly, SHA1 corresponds to main stream initial commit.""")
    ap.add_argument("-b",
                    "--break",
                    type=arg_type_SHA1_lower,
                    action='append',
                    dest="breaks",
                    metavar="SHA1",
                    help="""\
Specify break points. A break point is set on the commit identified by SHA1. \
The process will be interrupted after the commit allowing a user to change it. \
The tool will recover original committer name, e-mail and date during the next \
launch.""")
    ap.add_argument("-s",
                    "--skip",
                    type=arg_type_SHA1_lower,
                    action='append',
                    dest="skips",
                    metavar="SHA1",
                    help="""\
Specify a commit to skip. Use multiple options to skip several commits. If a \
commit at break point is skipped then interruption will be made after \
previous non-skipped commit in the branch except for no commits are copied yet \
since either trunk or root.""")
    ap.add_argument("-H",
                    "--head",
                    type=arg_type_git_head_name,
                    action='append',
                    dest="refs",
                    metavar="name_of_head",
                    help="""\
Copy commits those are ancestors of selected heads only (including the
heads).""")
    ap.add_argument("-t",
                    "--tag",
                    type=arg_type_git_tag_name,
                    action='append',
                    dest="refs",
                    metavar="name_of_tag",
                    help="""\
Copy commits those are ancestors of selected tags only (including the tag).""")
    ap.add_argument("-i",
                    "--insert-before",
                    type=composite_type(arg_type_SHA1_lower,
                                        arg_type_input_file),
                    action='append',
                    nargs=2,
                    dest="insertions",
                    metavar=("SHA1", "COMMIT"),
                    help="""\
Insert COMMIT before the commit with SHA1. COMMIT must be defined by a path
of the patch file in 'git am' compatible format.""")
    ap.add_argument("-g",
                    "--git",
                    type=arg_type_git,
                    default="git",
                    metavar="path/to/alternative/git",
                    help="""Use explicit git executable.""")
    ap.add_argument("-l",
                    "--log",
                    type=arg_type_output_file,
                    default=LOG_STANDARD,
                    metavar="path/to/log.csv",
                    help="Log git`s standard output and errors to that file.")
    ap.add_argument(
        "-c",
        "--cache",
        type=arg_type_directory,
        metavar="path/to/cache",
        dest="cache_path",
        help="""Resolve conflicts or edit break point commits using
patches from the cache. A patch file name must start with SHA1 of corresponding
original commit."""

        # TODO: User modifications will be also preserved in the cache.
    )
    ap.add_argument(
        "--from-cache",
        action="store_true",
        help="""If a patch is found in the cache then the process will not
be interrupted on either a conflicts or a break point. All changes is taken
from that patch.""")

    args = ap.parse_args()

    ctx = None
    if isfile(STATE_FILE_NAME):
        try:
            ctx = load_context(STATE_FILE_NAME)
        except:
            print("Incorrect state file")
            print_exc(file=sys.stdout)

    cloned_source = None

    if ctx is None:
        git_cmd = args.git
        source = args.source

        if source is None:
            print("No source repository path was given.")
            ap.print_help(sys.stdout)
            return

        try:
            local = arg_type_git_local(source)
        except ArgumentTypeError:
            remote = source
            # Source points to a remote repository. It must be cloned first
            # because git.Repo cannot work with a remote repository.
            cloned_source = join(init_cwd, ".gic-cloned-source")
            try:
                cloned_source = arg_type_new_directory(cloned_source)
            except ArgumentTypeError:
                raise RuntimeError(
                    "Cannot clone source repository into local "
                    "temporal directory '%s', underlying error:\n%s" %
                    (cloned_source, format_exc()))

            print("Cloning source repository into local temporal directory "
                  "'%s'" % cloned_source)

            # delete existing copy
            if isdir(cloned_source):
                rmtree(cloned_source)

            try:
                launch([git_cmd, "clone", remote, cloned_source],
                       epfx="Cloning has failed")
            except:
                sys.stderr.write("\n" + format_exc())
                rmtree(cloned_source)
                exit(1)

            # create all branches in temporal copy
            tmp_repo = Repo(cloned_source)

            chdir(cloned_source)

            for ref in list(tmp_repo.references):
                if not ref.path.startswith("refs/remotes/origin/"):
                    continue

                # cut out prefix "origin/"
                branch = ref.name[7:]

                if branch == "HEAD" or branch == "master":
                    continue

                try:
                    launch(
                        [git_cmd, "branch", branch, ref.name],
                        epfx="Cannot create tracking branch '%s' in temporal"
                        " copy of origin repository" % branch)
                except:
                    chdir(init_cwd)
                    rmtree(cloned_source)
                    sys.stderr.write("\n" + format_exc())
                    exit(1)

            chdir(init_cwd)

            srcRepoPath = cloned_source
        else:
            # Source points to a local repository.
            srcRepoPath = local

        log = args.log

        # overwrite log
        if log is not LOG_STANDARD and isfile(log):
            unlink(log)

        ctx = GitContext(src_repo_path=srcRepoPath,
                         git_command=git_cmd,
                         cache_path=args.cache_path,
                         from_cache=args.from_cache,
                         log=log)

        switch_context(ctx)
    else:
        srcRepoPath = ctx.src_repo_path

    print("Building graph of repository: " + srcRepoPath)

    repo = Repo(srcRepoPath)
    sha2commit = ctx._sha2commit
    GICCommitDesc.build_git_graph(repo,
                                  sha2commit,
                                  skip_remotes=True,
                                  skip_stashes=True,
                                  refs=args.refs)

    print("Total commits: %d" % len(sha2commit))

    if ctx.current_action < 0:
        destination = args.destination
        if destination is None:
            print("No destination specified. Dry run.")
            return

        dstRepoPath = destination

        ms = args.main_stream
        if ms:
            ms_bits = sha2commit[ms].roots
        else:
            ms_bits = 0

        print("The repository will be cloned to: " + dstRepoPath)

        # Planing
        plan(repo,
             sha2commit,
             dstRepoPath,
             breaks=args.breaks,
             skips=args.skips,
             main_stream_bits=ms_bits,
             insertions=args.insertions)

        # remove temporal clone of the source repository
        if cloned_source:
            RemoveDirectory(path=cloned_source)
    else:
        print("The context was loaded. Continuing...")

        ctx.restore_cloned()

    ctx.do()

    # save results
    if getcwd() != init_cwd:
        chdir(init_cwd)

    if ctx.finished:
        if isfile(STATE_FILE_NAME):
            unlink(STATE_FILE_NAME)
    else:
        pythonize(ctx, STATE_FILE_NAME + ".tmp")

        if isfile(STATE_FILE_NAME):
            unlink(STATE_FILE_NAME)
        rename(STATE_FILE_NAME + ".tmp", STATE_FILE_NAME)

    rs = args.result_state
    if rs:
        pythonize(ctx, rs)
예제 #5
0
    def co_init_cache(self):
        if self.qvc is not None:
            print("Multiple QVC initialization " + self.src_path)
            self.qvc = None

        qvc_path = self.qvc_path = join(self.build_path, self.qvc_file_name)

        qemu_heuristic_hash = calculate_qh_hash()

        yield True

        if not isfile(qvc_path):
            self.qvc = QemuVersionCache()

            # Check out Qemu source to a temporary directory and analyze it
            # there. This avoids problems with user changes in main working
            # directory.

            print("Checking out temporary source tree...")

            # Note. Alternatively, checking out can be performed without
            # cloning. Instead, a magic might be casted on GIT_DIR and
            # GIT_WORK_TREE environment variables. But, this approach resets
            # staged files in src_path repository which can be inconvenient
            # for a user.
            tmp_repo = fast_repo_clone(self.repo, self.commit_sha, "qdt-qemu")
            tmp_work_dir = tmp_repo.working_tree_dir

            print("Temporary source tree: %s" % tmp_work_dir)

            # make new QVC active and begin construction
            prev_qvc = self.qvc.use()
            for path, recursive in self.include_paths:
                yield Header.co_build_inclusions(join(tmp_work_dir, path),
                                                 recursive)

            self.qvc.list_headers = self.qvc.stc.create_header_db()

            rmtree(tmp_work_dir)

            yield self.co_init_device_tree()

            yield self.co_gen_known_targets()

            # gen version description
            yield self.qvc.co_computing_parameters(self.repo, self.commit_sha)
            self.qvc.version_desc[QVD_QH_HASH] = qemu_heuristic_hash

            # Search for PCI Ids
            PCIClassification.build()

            yield True

            pythonize(self.qvc, qvc_path)
        else:
            self.load_cache()
            # make just loaded QVC active
            prev_qvc = self.qvc.use()

            if self.qvc.list_headers is not None:
                yield True

                yield self.qvc.stc.co_load_header_db(self.qvc.list_headers)

            yield True

            # verify that the version_desc is not outdated
            is_outdated = False
            try:
                checksum = self.qvc.version_desc[QVD_QH_HASH]
            except KeyError:
                is_outdated = True
            else:
                if not checksum == qemu_heuristic_hash:
                    is_outdated = True
            if is_outdated:
                yield self.qvc.co_computing_parameters(self.repo,
                                                       self.commit_sha)
                self.qvc.version_desc[QVD_QH_HASH] = qemu_heuristic_hash

            dt = self.qvc.device_tree
            if dt:
                # Targets to be added to the cache
                new_targets = self.softmmu_targets - dt.arches
                has_new_target = len(new_targets) > 0
            else:
                new_targets = self.softmmu_targets
                has_new_target = True

            if has_new_target:
                yield self.co_init_device_tree(new_targets)

            if is_outdated or has_new_target:
                pythonize(self.qvc, qvc_path)

        yield True

        # set Qemu version heuristics according to current version
        initialize_version(self.qvc.version_desc)

        yield True

        # initialize Qemu types in QVC
        get_vp()["qemu types definer"]()
        get_vp()["msi_init type definer"]()

        if prev_qvc is not None:
            prev_qvc.use()

        self.qvc_is_ready = True
예제 #6
0
파일: server.py 프로젝트: laerreal/async-pc
 def save(self, file):
     s = Storage(clients = self._clients)
     pythonize(s, file)