def main():

    parser = make_parser()
    args = parser.parse_args()

    pathf.check_technical_area(args.area, args.module_name)

    module = args.module_name
    source = pathf.dev_module_path(module, args.area)
    logging.debug(source)

    if vcs_git.is_server_repo(source):
        repo = vcs_git.temp_clone(source)
        releases = vcs_git.list_module_releases(repo)

        if releases:
            last_release_num = releases[-1]
        else:
            print("No release has been done for " + module)
            # return so last_release_num can't be referenced before assignment
            return 1
    else:
        raise Exception(source + " does not exist on the repository.")

    # Get a single log between last release and HEAD
    # If there is one, then changes have been made
    logs = list(repo.iter_commits(last_release_num + "..HEAD", max_count=1))
    if logs:
        print("Changes have been made to " + module + " since release " + last_release_num)
    else:
        print("No changes have been made to " + module + " since most recent release " + last_release_num)

    shutil.rmtree(repo.working_tree_dir)
Пример #2
0
    def test_dev_module(self):

        area = "etc"
        module = "test_module"

        path = path_functions.dev_module_path(module, area)

        self.assertEqual(path, "controlstest/" + area + "/" + module)
Пример #3
0
def main():

    parser = make_parser()
    args = parser.parse_args()

    env.check_epics_version(args.epics_version)
    pathf.check_technical_area(args.area, args.module_name)

    # Force check of repo, not file system, for tools, etc and epics (previous releases are only stored on repo)
    if args.area in ["etc", "tools", "epics"]:
        args.git = True

    # Check for the existence of releases of this module/IOC    
    releases = []
    if args.git:
        # List branches of repository
        target = "the repository"
        source = pathf.dev_module_path(args.module_name, args.area)

        repo = vcs_git.temp_clone(source)
        releases = vcs_git.list_module_releases(repo)
        shutil.rmtree(repo.working_tree_dir)

    else:
        # List branches from prod
        target = "prod"
        source = env.prodArea(args.area)
        if args.area == 'python' and args.rhel_version >= 6:
            source = os.path.join(source, "RHEL{0}-{1}".format(args.rhel_version,
                                                               platform.machine()))
            logging.debug(source)
        release_dir = os.path.join(source, args.module_name)

        if os.path.isdir(release_dir):
            for p in os.listdir(release_dir):
                if os.path.isdir(os.path.join(release_dir, p)):
                    releases.append(p)

    # Check some releases have been made
    if len(releases) == 0:
        if args.git:
            print(args.module_name + ": No releases made in git")
        else:
            print(args.module_name + ": No releases made for " + args.epics_version)
        return 1

    releases = env.sortReleases(releases)

    if args.latest:
        print("The latest release for " + args.module_name + " in " + target +
              " is: " + releases[-1])
    else:
        print("Previous releases for " + args.module_name + " in " + target + ":")
        for release in releases:
            print(release)
Пример #4
0
def main():

    parser = make_parser()
    args = parser.parse_args()
    
    if args.area == "ioc" and args.domain_name:
        print("Modules in " + args.domain_name + ":\n")
        source = pathf.dev_module_path(args.domain_name, args.area)
    else:
        print("Modules in " + args.area + ":\n")
        source = pathf.dev_area_path(args.area)

    print_module_list(source)
Пример #5
0
def main():

    parser = make_parser()
    args = parser.parse_args()

    pathf.check_technical_area(args.area, args.module_name)

    source = pathf.dev_module_path(args.module_name, args.area)

    print("Branches of " + args.module_name + ":\n")

    repo = vcs_git.temp_clone(source)

    branches = vcs_git.list_remote_branches(repo)
    for branch in branches:
        print(branch)
    print("")

    shutil.rmtree(repo.working_tree_dir)
Пример #6
0
    def __init__(self, module, options, mock_repo=""):

        self._module = module
        self.area = options.area
        self._version = None
        self.mock_repo = mock_repo

        if not self.mock_repo:

            server_repo_path = pathf.dev_module_path(self._module, self.area)
            if not is_server_repo(server_repo_path):
                raise VCSGitError("repo not found on gitolite server")

            repo_dir = tempfile.mkdtemp(suffix="_" + self._module.replace("/", "_"))
            self._remote_repo = os.path.join(GIT_SSH_ROOT, server_repo_path)

            self.client = git.Repo.clone_from(self._remote_repo, repo_dir)
        else:
            self._remote_repo = mock_repo
Пример #7
0
def main():

    parser = make_parser()
    args = parser.parse_args()

    if args.module_name == "":
        answer = raw_input("Would you like to checkout the whole " +
                           args.area + " area? This may take some time. Enter Y or N: ")
        if answer.upper() != "Y":
            return

    check_technical_area(args.area, args.module_name)

    module = args.module_name

    if module == "":
        # Set source to area folder
        source = pathf.dev_area_path(args.area)
    else:
        # Set source to module in area folder
        source = pathf.dev_module_path(module, args.area)

    if module == "":
        print("Checking out entire " + args.area + " area...\n")
        vcs_git.clone_multi(source)
    elif module.endswith('/') and args.area == 'ioc':
        print("Checking out " + module + " technical area...")
        vcs_git.clone_multi(source)
    else:
        print("Checking out " + module + " from " + args.area + " area...")
        repo = vcs_git.clone(source, module)

        if args.branch:
            # Get branches list
            branches = vcs_git.list_remote_branches(repo)
            if args.branch in branches:
                vcs_git.checkout_remote_branch(args.branch, repo)
            else:
                # Invalid branch name, print branches list and exit
                print("Branch '" + args.branch + "' does not exist in " + source +
                      "\nBranch List:\n")
                for entry in branches:
                    print(entry)
Пример #8
0
    def __init__(self, module_path, area, module_template_cls,
                 **kwargs):
        """Default initialisation of all object attributes.

        Args:
            module_path: The relative module path.
                Used in messages and exceptions for user-friendliness.
            area: The development area of the module to be created.
                In particular, this specifies the exact template files to be
                created as well as affecting the repository server path.
            module_template_cls: Class for module_template object.
                Must be a non-abstract subclass of ModuleTemplate.
            kwargs: Additional arguments for module creation.

        """
        self._area = area
        self._cwd = os.getcwd()

        self._module_path = module_path
        self._module_name = os.path.basename(os.path.normpath(
                                             self._module_path))

        self.abs_module_path = os.path.join(self._cwd, self._module_path)
        self._server_repo_path = pathf.dev_module_path(self._module_path,
                                                       self._area)

        template_args = {'module_name': self._module_name,
                         'module_path': self._module_path,
                         'user_login': getuser()}

        if kwargs:
            template_args.update(kwargs)

        self._module_template = module_template_cls(template_args)

        self._remote_repo_valid = False

        # These boolean values allow us to call the methods in any order
        self._can_create_local_module = False
        self._can_push_repo_to_remote = False
Пример #9
0
def main():

    parser = make_parser()
    args = parser.parse_args()

    check_parsed_args_compatible(args.imp, args.modules, args.contact, args.cc, parser)

    # Create the list of modules from args, or the gitolite server if none provided
    modules = []
    if args.modules:
        for module in args.modules:
            modules.append(module)
    else:
        for module in get_area_module_list(args.area):
            modules.append(module)

    # If no contacts or csv file provided to edit, default script operation: print contacts
    if not (args.contact or args.cc or args.imp):

        print_out = []
        for module in modules:
            source = pathf.dev_module_path(module, args.area)
            repo = vcs_git.temp_clone(source)

            # Retrieve contact info
            contact = repo.git.check_attr("module-contact", ".").split(' ')[-1]
            cc_contact = repo.git.check_attr("module-cc", ".").split(' ')[-1]

            if args.csv:
                print_out.append(output_csv_format(contact, cc_contact, module))
            else:
                print_out.append("Contact: " + contact + " (CC: " + cc_contact + ")")

            shutil.rmtree(repo.working_tree_dir)

        if args.csv:
            print("Module,Contact,Contact Name,CC,CC Name")
        for entry in print_out:
            print(entry)

        return 0

    # If we get to this point, we are assigning contacts

    if args.imp:
        contacts = import_from_csv(modules, args.area, args.imp)
    else:
        # If no csv file provided, retrieve contacts from args
        contacts = []
        for module in modules:
            contacts.append((module, args.contact, args.cc))

    # Checkout modules and change contacts
    for module, contact, cc in contacts:

        print("Cloning " + module + " from " + args.area + " area...")
        source = pathf.dev_module_path(module, args.area)
        repo = vcs_git.temp_clone(source)

        edit_summary = edit_contact_info(repo, contact, cc,)

        if edit_summary != 0:
            index = repo.index
            index.add(['.gitattributes'])
            index.commit(edit_summary)

            origin = repo.remotes.origin
            origin.push(repo.active_branch)

        shutil.rmtree(repo.working_tree_dir)
Пример #10
0
def get_module_creator_ioc(module_name, fullname=False):
    """Returns a :class:`ModuleCreatorIOC` subclass object.

    Returns an object of a subclass of :class:`ModuleCreatorIOC`, depending
    on the arguments given.

    IOC module name format:
        New-Style module (preferred):
            Format: "BL02I-VA-IOC-03"
                "<beamline>-<technical_area>-IOC-<ioc_number>"
            Alternative: "BL02I/VA/03", with fullname = True
                "<beamline>/<technical_area>/<ioc_number>", fullname = True

            If the alternative is used, if the IOC number is omitted
            (eg. <beamline>/<technical_area>) it defaults to "01"

        Old-Style module (deprecated, except for BL modules):
            Format: "BL02I/VA/03", with fullname = False (or omitted)
                "<beamline>/<technical_area>/<ioc_number>"

    Args:
        module_name: The name of the module.
        fullname: Create new-style module from old-style input.
            If True and module_name given in old-style format, then a
            new-style module is created.

    Returns:
        ModuleCreatorIOC: :class:`ModuleCreatorIOC` subclass object

    Raises:
        ParsingError: If the module cannot be split by '-' or '/'.

    """
    area = "ioc"

    dash_separated, cols = split_ioc_module_name(module_name)

    domain = cols[0]
    technical_area = cols[1]

    if technical_area == "BL":
        if dash_separated:
            app_name = module_name
            module_path = domain + "/" + app_name
        else:
            app_name = domain
            module_path = domain + "/" + technical_area

        return mc.ModuleCreatorWithApps(module_path, area,
                                        mt.ModuleTemplateIOCBL,
                                        app_name=app_name)

    module_template_cls = mt.ModuleTemplateIOC

    if dash_separated:
        app_name = module_name
        module_path = domain + "/" + app_name
        return mc.ModuleCreatorWithApps(module_path, area, module_template_cls,
                                        app_name=app_name)

    if len(cols) == 3 and cols[2]:
        ioc_number = cols[2]
    else:
        ioc_number = "01"

    app_name = "-".join([domain, technical_area, "IOC", ioc_number])

    if fullname:
        module_path = domain + "/" + app_name
        return mc.ModuleCreatorWithApps(module_path, area, module_template_cls,
                                        app_name=app_name)
    else:
        # This part is here to retain compatibility with "old-style" modules,
        # in which a single repo (or module) named "domain/technical_area"
        # contains multiple domain-technical_area-IOC-xxApp's. This code is
        # included in here to retain compatibility with the older svn scripts.
        # The naming is ambiguous, however. I will continue to use the name
        # 'module' to refer to the repo, but be aware that start_new_module and
        # module_creator don't have to actually create new modules (repos)
        # on the server in this instance.
        module_path = domain + "/" + technical_area
        server_repo_path = pathf.dev_module_path(module_path, area)
        if vcs_git.is_server_repo(server_repo_path):
            # Adding new App to old style "domain/tech_area" module that
            # already exists on the remote server.
            return mc.ModuleCreatorAddAppToModule(module_path, area,
                                                  module_template_cls,
                                                  app_name=app_name)
        else:
            # Otherwise, the behaviour is exactly the same as that given
            # by the ordinary IOC class as module_path is the only thing
            # that is different
            return mc.ModuleCreatorWithApps(module_path, area,
                                            module_template_cls,
                                            app_name=app_name)
Пример #11
0
def main():

    parser = make_parser()
    args = parser.parse_args()

    raw = set_raw_argument(args.raw)
    pathf.check_technical_area(args.area, args.module_name)
    check_parsed_args_compatible(args.releases, args.earlier_release, args.later_release, parser)
    check_releases_valid(args.releases, parser)

    source = pathf.dev_module_path(args.module_name, args.area)
    if vcs_git.is_server_repo(source):
        repo = vcs_git.temp_clone(source)
        releases = vcs_git.list_module_releases(repo)
        logging.debug(releases)
    else:
        raise Exception("Module " + args.module_name + " doesn't exist in " + source)

    # Set start and end releases and check they exist, set to defaults if not given
    start, end = set_log_range(args.module_name, args.releases, args.earlier_release, args.later_release, releases)

    # Create log info from log messages
    # log_info is a dictionary in the form {logs(list), commit_objects(dict), max_author_length(int)}
    log_info = get_log_messages(repo)

    if len(releases) > 0:

        if start == "":
            tag_start = releases[0]
        else:
            tag_start = start

        # Append tag info to log info from tag messages
        tags = get_tags_list(repo, tag_start, end, releases[-1])
        log_info = get_tag_messages(tags, log_info)

    # Check if there are any logs, exit if not
    if not log_info['logs']:
        print("No logs for " + args.module_name + " between releases " +
              args.earlier_release + " and " + args.later_release)
        return 0

    # Sort tags and commits chronologically by the UNIX time stamp in index 0
    log_info['logs'] = sorted(log_info['logs'], key=itemgetter(0))

    # Make list of printable log entries
    formatted_logs = format_log_messages(log_info, raw, args.verbose)

    if end == 'HEAD':
        print_bool = True
    else:
        print_bool = False

    release_marker = "(RELEASE: {})"
    for log in formatted_logs:
        if log.endswith(release_marker.format(end)):
            print_bool = True
        if print_bool:
            print(log)
        if log.endswith(release_marker.format(start)):
            break

    shutil.rmtree(repo.working_tree_dir)