def create_submodule(self, name, url, path):
     """
     Args:
         name: Name of the submodule
         url: Url to the submodule repo
         path: Local system path to the submodule
     """
     try:
         git_modules_path = join(self._repo.working_tree_dir, ".git",
                                 "modules", name)
         if self.contains_submodule(url):
             get_input(
                 "Submodule {} already exists. Confirm this is as expected and press return to continue"
                 .format(name))
         else:
             if exists(git_modules_path) and ask_do_step(
                     "The submodule {} is not part of this repo, yet {} exists. Shall I delete it?"
                     "".format(name, git_modules_path)):
                 rmtree(git_modules_path)
             self._repo.create_submodule(name,
                                         path,
                                         url=url,
                                         branch="master")
     except InvalidGitRepositoryError as e:
         logging.error(
             "Cannot add {} as a submodule, it does not exist: {}".format(
                 path, e))
     except GitCommandError as e:
         logging.error(
             "Git command failed to create submodule from {}: {}".format(
                 path, e))
     except Exception as e:
         raise RuntimeError(
             "Unknown error {} of type {} whilst creating submodule in {}".
             format(e, type(e), path))
Exemplo n.º 2
0
def apply_support_dir_template(device_info):
    """
    Args:
        device_info: Provides name-based information about the device
    """
    mkdir(device_info.support_master_dir())
    cmd = [
        PERL, PERL_SUPPORT_GENERATOR, "-t", "streamSCPI",
        device_info.support_app_name()
    ]
    run_command(cmd, device_info.support_master_dir())
    if not path.exists(device_info.support_db_path()):
        logging.warning(
            "The makeSupport.pl didn't run correctly. It's very temperamental. "
            "Please run the following command manually from an EPICS terminal")
        logging.warning("cd {} && {}".format(device_info.support_master_dir(),
                                             " ".join(cmd)))
        get_input("Press return to continue...")

    # Some manual tweaks to the auto template
    remove(device_info.support_db_path())
    copyfile(SUPPORT_GITIGNORE,
             path.join(device_info.support_master_dir(), ".gitignore"))
    copyfile(SUPPORT_LICENCE,
             path.join(device_info.support_master_dir(), "LICENCE"))
    replace_in_file(
        path.join(device_info.support_app_path(), "Makefile"),
        [("DB += {}.proto".format(device_info.support_app_name()), "")])
    _add_template_db(device_info)

    run_command(["make"], device_info.support_master_dir())
Exemplo n.º 3
0
def create_submodule(device_info, create_submodule_in_git):
    """
    Creates a submodule and links it into the main EPICS repo

    Args:
        device_info: Provides name-based information about the device
        create_submodule_in_git: True then create submodule in git; False do not do this operation
    """
    mkdir(device_info.support_dir())
    copyfile(SUPPORT_MAKEFILE, path.join(device_info.support_dir(),
                                         "Makefile"))
    master_dir = device_info.support_master_dir()
    if create_submodule_in_git:
        if path.isdir(path.join(master_dir, ".git")):
            logging.error(
                "A git repository (not submodule) already exists at {0}."
                "Remove this to be able to creat the submodule correctly".
                format(master_dir))
            exit()
        get_input(
            "Attempting to create repository using remote {}. Press return to confirm it exists"
            .format(device_info.support_repo_url()))
        RepoWrapper(EPICS).create_submodule(device_info.support_app_name(),
                                            device_info.support_repo_url(),
                                            master_dir)
    else:
        logging.warning(
            "Because you have chosen no-git the submodule has not been added for your ioc support module. "
            "If files are added they will be added to EPICS not a submodule of it."
        )

    logging.info(
        "Initializing device support repository {}".format(master_dir))
    _add_to_makefile(device_info.support_app_name())
    def __init__(self, raw_name):
        """
        Args:
            raw_name: The raw input name of the device
        """
        self._name = raw_name
        self._ioc_name = None

        while True:
            proposed_name = self.ioc_name()
            if self._is_valid_ioc_name(proposed_name):
                break
            self._name = get_input(
                "Device name, {}, is invalid and produces an invalid IOC name {}. Please enter a valid device name: "
                .format(self._name, proposed_name))
def create_ioc(device_info, device_count):
    """
    Creates a vanilla IOC in the EPICS IOC submodule

    Args:
        device_info: Provides name-based information about the device
        device_count: Number of IOCs to generate
    """
    while not 1 <= device_count <= 9:
        try:
            device_count = int(get_input("{} IOCs currently requested. The current script requires a number"
                                         " between 1 and 9. Please enter a new value: ".format(device_count)))
        except (ValueError, TypeError) as e:
            logging.warning("That was not a valid input, please try again: {}".format(e))

    mkdir(device_info.ioc_path())

    _run_ioc_template_setup(device_info, device_count)
    _add_template_config_xml(device_info, device_count)
    _replace_macros(device_info, device_count)
    _clean_up(device_info, device_count)
    _build(device_info.ioc_path())
    _add_to_ioc_makefile(device_info.ioc_name())
    _add_macro_to_release_file(device_info)
    def prepare_new_branch(self, branch):
        """
        Args:
            branch: Name of the new branch
        """
        logging.info("Preparing new branch, {}, for repo {}".format(
            branch, self._repo.working_tree_dir))
        if self._repo.is_dirty():
            try:
                option = int(
                    get_input(
                        "Repository {} is dirty, clean it? \n"
                        "    0: No clean\n"
                        "    1: Stash uncommited changes\n"
                        "    2: Clean (-fd). All uncommited changes will be lost\n"
                        "    3: Reset hard to HEAD. All unpushed changes will be lost\n"
                        "    [Default: 0] ".format(
                            self._repo.working_tree_dir)))
            except (ValueError, TypeError):
                option = 0
            logging.info("Option {} selected".format(option))
            try:
                if option == 1:
                    logging.info("Local changes will be stashed")
                    self._repo.git.stash(include_untracked=True)
                elif option == 2 and ask_do_step(
                        "Git clean -fd requested. All uncommited changes will be lost. Are you sure?"
                ):
                    self._repo.git.clean(f=True, d=True)
                elif option == 3 and ask_do_step(
                        "Git reset HEAD --hard requested. All unpushed changes will be lost. Are you sure?"
                ):
                    self._repo.git.reset("HEAD", hard=True)
                else:
                    logging.info("No clean requested")
            except GitCommandError as e:
                logging.warning(
                    "Error whilst scrubbing repository. I'll try to continue anyway: {}"
                ).format(e)

        try:
            logging.info(
                "Switching repo {} to master and fetching latest changes".
                format(self._repo.working_tree_dir))
            self._repo.git.checkout("master")
            self._repo.git.fetch(recurse_submodules=True)
        except GitCommandError as e:
            raise RuntimeError(
                "Could not switch repo back to master: {}".format(e))

        try:
            logging.info("Creating/switching to branch {}".format(branch))
            branch_is_new = branch.upper() not in [
                b.name.upper() for b in self._repo.branches
            ]  # Case insensitive
            self._repo.git.checkout(branch, b=branch_is_new)
            self._repo.git.push("origin", branch, set_upstream=True)
        except GitCommandError as e:
            raise RuntimeError(
                "Error whilst creating git branch, {}".format(e))

        logging.info("Branch {} ready".format(branch))