Exemple #1
0
    def save(self):
        """Save the modules to @_path. If @modules is an empty
        dict, then @_path should be removed.
        """
        root_logger.debug("Saving StateFile to '%s'", self._path)

        for module in list(self.modules.keys()):
            if len(self.modules[module]) == 0:
                del self.modules[module]

        if len(self.modules) == 0:
            root_logger.debug("  -> no modules, removing file")
            if os.path.exists(self._path):
                os.remove(self._path)
            return

        p = SafeConfigParser()
        p.optionxform = str

        for module in self.modules.keys():
            p.add_section(module)
            for (key, value) in self.modules[module].items():
                p.set(module, key, str(value))

        with open(self._path, "w") as f:
            p.write(f)
Exemple #2
0
    def save(self):
        """Save the modules to @_path. If @modules is an empty
        dict, then @_path should be removed.
        """
        root_logger.debug("Saving StateFile to '%s'", self._path)

        for module in list(self.modules):
            if len(self.modules[module]) == 0:
                del self.modules[module]

        if len(self.modules) == 0:
            root_logger.debug("  -> no modules, removing file")
            if os.path.exists(self._path):
                os.remove(self._path)
            return

        p = SafeConfigParser()
        p.optionxform = str

        for module in self.modules:
            p.add_section(module)
            for (key, value) in self.modules[module].items():
                p.set(module, key, str(value))

        with open(self._path, "w") as f:
            p.write(f)
Exemple #3
0
def load_config(config_files=(), overrides=()):
    cp = SafeConfigParser()
    cp.optionxform = str  # make parsing case-sensitive
    cp.read(FILENAMES + config_files)

    for section, option, value in overrides:
        if value is not None:
            if isinstance(value, bool):
                value = int(value)
            cp.set(section, option, str(value))

    return {section: dict(cp.items(section)) for section in cp.sections()}
Exemple #4
0
def init_ini_file(file=args.ini_file):
    cp = SafeConfigParser()
    fp = open(file)
    cp.optionxform = str
    cp.readfp(fp)
    fp.close()

    cp.set('condor', 'lalsuite-install', lalinf_prefix)
    cp.set('analysis', 'engine', args.engine)
    cp.remove_option('analysis', 'nparallel')

    return cp
def init_ini_file(file=args.ini_file):
    cp=SafeConfigParser()
    fp=open(file)
    cp.optionxform = str
    cp.readfp(fp)
    fp.close()

    cp.set('condor','lalsuite-install',lalinf_prefix)
    cp.set('analysis','engine',args.engine)
    cp.remove_option('analysis','nparallel')

    return cp
Exemple #6
0
def read_config_file():
    if not os.path.isfile(config_file_path):
        download_config_file()

    config = SafeConfigParser()
    config.optionxform = str
    list_of_successfully_parsed_files = config.read(config_file_path)
    if config_file_path not in list_of_successfully_parsed_files:
        raise Exception(
            'Could not read {0} succesfully.'.format(config_file_path)
        )
    return config
Exemple #7
0
    def read_ini(cls, path, section=None):
        """read preferences from an .ini file"""

        parser = ConfigParser()
        parser.optionxform = str
        parser.readfp(mozfile.load(path))

        if section:
            if section not in parser.sections():
                raise PreferencesReadError("No section '%s' in %s" % (section, path))
            retval = parser.items(section, raw=True)
        else:
            retval = parser.defaults().items()

        # cast the preferences since .ini is just strings
        return [(i, cls.cast(j)) for i, j in retval]
Exemple #8
0
    def read_ini(cls, path, section=None):
        """read preferences from an .ini file"""

        parser = ConfigParser()
        parser.optionxform = str
        parser.readfp(mozfile.load(path))

        if section:
            if section not in parser.sections():
                raise PreferencesReadError("No section '%s' in %s" % (section, path))
            retval = parser.items(section, raw=True)
        else:
            retval = parser.defaults().items()

        # cast the preferences since .ini is just strings
        return [(i, cls.cast(j)) for i, j in retval]
Exemple #9
0
    def _load(self):
        """Load the file list from the index file. @files will
        be an empty dictionary if the file doesn't exist.
        """

        root_logger.debug("Loading Index file from '%s'", self._index)

        self.files = {}

        p = SafeConfigParser()
        p.optionxform = str
        p.read(self._index)

        for section in p.sections():
            if section == "files":
                for (key, value) in p.items(section):
                    self.files[key] = value
Exemple #10
0
    def _load(self):
        """Load the file list from the index file. @files will
        be an empty dictionary if the file doesn't exist.
        """

        root_logger.debug("Loading Index file from '%s'", self._index)

        self.files = {}

        p = SafeConfigParser()
        p.optionxform = str
        p.read(self._index)

        for section in p.sections():
            if section == "files":
                for (key, value) in p.items(section):
                    self.files[key] = value
Exemple #11
0
    def _load(self):
        """Load the modules from the file @_path. @modules will
        be an empty dictionary if the file doesn't exist.
        """
        root_logger.debug("Loading StateFile from '%s'", self._path)

        self.modules = {}

        p = SafeConfigParser()
        p.optionxform = str
        p.read(self._path)

        for module in p.sections():
            self.modules[module] = {}
            for (key, value) in p.items(module):
                if value == str(True):
                    value = True
                elif value == str(False):
                    value = False
                self.modules[module][key] = value
Exemple #12
0
    def _load(self):
        """Load the modules from the file @_path. @modules will
        be an empty dictionary if the file doesn't exist.
        """
        root_logger.debug("Loading StateFile from '%s'", self._path)

        self.modules = {}

        p = SafeConfigParser()
        p.optionxform = str
        p.read(self._path)

        for module in p.sections():
            self.modules[module] = {}
            for (key, value) in p.items(module):
                if value == str(True):
                    value = True
                elif value == str(False):
                    value = False
                self.modules[module][key] = value
Exemple #13
0
    def save(self):
        """Save the file list to @_index. If @files is an empty
        dict, then @_index should be removed.
        """
        root_logger.debug("Saving Index File to '%s'", self._index)

        if len(self.files) == 0:
            root_logger.debug("  -> no files, removing file")
            if os.path.exists(self._index):
                os.remove(self._index)
            return

        p = SafeConfigParser()
        p.optionxform = str

        p.add_section('files')
        for (key, value) in self.files.items():
            p.set('files', key, str(value))

        with open(self._index, "w") as f:
            p.write(f)
Exemple #14
0
    def save(self):
        """Save the file list to @_index. If @files is an empty
        dict, then @_index should be removed.
        """
        root_logger.debug("Saving Index File to '%s'", self._index)

        if len(self.files) == 0:
            root_logger.debug("  -> no files, removing file")
            if os.path.exists(self._index):
                os.remove(self._index)
            return

        p = SafeConfigParser()
        p.optionxform = str

        p.add_section('files')
        for (key, value) in self.files.items():
            p.set('files', key, str(value))

        with open(self._index, "w") as f:
            p.write(f)
Exemple #15
0
def newScheme():
	parser = SafeConfigParser()
	parser.optionxform = str
	return parser
Exemple #16
0
    def parseOptions(self):
        """Parse the command line options."""
        log = LOGGER.getChild("Options")

        conf_parser = argparse.ArgumentParser(
            "Dirac Release Notes",
            formatter_class=argparse.RawTextHelpFormatter,
            add_help=False,
        )
        conf_parser.add_argument("-c", "--configFile", help="Specify config file", metavar="FILE", dest="configFile")
        conf_parser.add_argument("-t", "--token", help="API token to use", default="")
        conf_parser.add_argument("-d", "--debug", action="count", dest="debug", help="d, dd, ddd", default=0)
        args, _remaining_argv = conf_parser.parse_known_args()
        self.token = args.token
        self.printLevel = _parsePrintLevel(args.debug)
        LOGGER.setLevel(self.printLevel)
        log.debug("Parsing options")
        defaults = {}
        if args.configFile:
            log.debug("Parsing configFile: %r", args.configFile)
            config = ConfigParser()
            config.optionxform = str
            config.read([args.configFile])
            defaults.update(dict(config.items("ReleaseNotes")))
            log.info("Settings from config file: %r", defaults)

            if config.has_section("ReleaseNotes.Categories"):
                items = config.items("ReleaseNotes.Categories")
                log.info("Found Categories: %r", items)
                for short, system in items:
                    self.names[short] = system

        parser = argparse.ArgumentParser(
            description=__doc__,
            formatter_class=argparse.RawDescriptionHelpFormatter,
            # Inherit options from config_parser
            parents=[conf_parser],
        )
        parser.add_argument(
            "--branches",
            action="store",
            default=self.branches,
            dest="branches",
            nargs="+",
            help="branches to get release notes for",
        )

        parser.add_argument(
            "--date",
            action="store",
            default=self.startDate,
            dest="date",
            help="date and optionally time after which PRs are checked (ISO 8601),\
                         accepting 2020-01-08 or 2018-05-20T15:23:45Z,\
                         default (two weeks ago): %s"
            % self.startDate,
        )

        parser.add_argument(
            "--sinceLatestTag",
            action="store_true",
            dest="sinceLatestTag",
            default=self.sinceLatestTag,
            help="get release notes since latest tag (incompatible with --date)",
        )

        parser.add_argument(
            "--headerMessage",
            action="store",
            default=self.headerMessage,
            dest="headerMessage",
            help="Header message to add between the release name and the list of PR. If it is a path,\
                         read the content of the file",
        )

        parser.add_argument(
            "--footerMessage",
            action="store",
            default=self.footerMessage,
            dest="footerMessage",
            help="Footer message to add after the list of PR. If it is a path,\
                      read the content of the file",
        )

        parser.add_argument(
            "--openPRs",
            action="store_true",
            dest="openPRs",
            default=self.openPRs,
            help="get release notes for open (unmerged) PRs, for testing purposes",
        )

        parser.add_argument(
            "-r",
            "--repo",
            action="store",
            dest="repo",
            help="Github repository to check: [Group/]Repo",
            default="DiracGrid/Dirac",
        )

        parser.add_argument(
            "-g", "--gitlab", action="store_true", dest="gitlab", help="Using gitlab instance", default=False
        )

        parser.add_argument(
            "-u",
            "--gitlabUrl",
            action="store",
            dest="gitlabUrl",
            help="URL of the gitlab instance",
            default="https://gitlab.cern.ch",
        )

        parser.add_argument(
            "-i",
            "--gitlabProjectID",
            action="store",
            dest="gitlabProjectID",
            help="ID of the project in Gitlab",
            default="0",
        )

        parser.add_argument(
            "--deployRelease",
            action="store_true",
            dest="deployRelease",
            help="Convert an existing tag into a github/gitlab release. Requires --releaseNotes and --tagName",
            default=self.deployRelease,
        )

        parser.add_argument(
            "--tagName",
            action="store",
            dest="tagName",
            help="Name of the tag to release (with --deployRelease)",
            default=self.tagName,
        )

        parser.add_argument(
            "--releaseNotes",
            action="store",
            dest="releaseNotes",
            help="Path to the file containing release notes for this version (with --deployRelease)",
            default=self.releaseNotes,
        )

        parser.set_defaults(**defaults)

        parsed = parser.parse_args()

        for var, val in sorted(vars(parsed).items()):
            log.info("Parsed options: %s = %s", var, pformat(val))

        self.branches = listify(parsed.branches)
        log.info("Getting PRs for: %s", self.branches)

        # If the date parsed does not correspond to the default,
        # and latestTag is asked, we throw an error
        if (parsed.date != self.startDate) and parsed.sinceLatestTag:
            raise RuntimeError("--sinceLatestTag incompatible with --date")

        self.sinceLatestTag = parsed.sinceLatestTag

        if self.sinceLatestTag:
            log.info("Starting from the latest tag")
            self.startDate = None
            del parsed.date
        else:
            if not isinstance(parsed.date, datetime.date):
                parsed.date = dateutil.parser.isoparse(parsed.date)
            if parsed.date.tzinfo is None or parsed.date.tzinfo.utcoffset(parsed.date) is None:
                self.startDate = pytz.utc.localize(parsed.date)
            else:
                self.startDate = parsed.date
            log.info("Starting from: %s", self.startDate)

        self.openPRs = parsed.openPRs
        log.info("Also including openPRs?: %s", self.openPRs)

        self.headerMessage = parsed.headerMessage
        if self.headerMessage:
            log.info("Using header message: %s", self.headerMessage)

        self.footerMessage = parsed.footerMessage
        if self.footerMessage:
            log.info("Using footer message: %s", self.footerMessage)

        self.useGitlab = parsed.gitlab if isinstance(parsed.gitlab, bool) else parsed.gitlab.lower() == "true"
        self.useGithub = not self.useGitlab

        self.gitlabUrl = parsed.gitlabUrl
        self.glProjectID = int(parsed.gitlabProjectID)

        self.deployRelease = parsed.deployRelease
        self.releaseNotes = parsed.releaseNotes
        self.tagName = parsed.tagName

        if self.deployRelease:
            if not (self.releaseNotes and self.tagName):
                raise RuntimeError("--deployRelease requires --releaseNotes and --tagName")
            if not os.path.isfile(self.releaseNotes):
                raise RuntimeError("--releaseNotes should point to an existing file")

        repo = parsed.repo
        repos = repo.split("/")
        if len(repos) == 1:
            self.repo = repo
        elif len(repos) == 2:
            self.owner = repos[0]
            self.repo = repos[1]
        else:
            raise RuntimeError("Cannot parse repo option: %s" % repo)

        for var, val in sorted(vars(parsed).items()):
            log.info("Using options: %s = %s", var, pformat(val))