Exemple #1
0
 def reloadconf(self):
     if self.warnflush("load a new configuration"):
         return
     self._conf = SafeConfigParser()
     if len(self._paths) > 1:
         self._ui.status(_("\nSelect configuration to edit:\n"))
         for i in range(len(self._paths)):
             print " %s.  %s" % (str(i), self.pathclass(self._paths[i]))
         index = self._ui.promptchoice(
             self.getPrompt(), ["&" + str(num) for num in range(len(self._paths))], len(self._paths) - 1
         )
         self._path = self._paths[index]
     elif len(self._paths) == 1:
         self._path = self._paths[0]
     else:
         # This is a little silly, since without a valid config file
         # how could this extension be loaded? But for completeness...
         self._path = default = util.user_rcpath()[0]
         msg = _("Unable to find configuration file." " Would you like to make one at %s?") % default
         index = self._ui.promptchoice(msg, [_("&yes"), _("&no")], 0)
         if index == 1:
             self._ui.status(_("No configuration to edit"))
             sys.exit(0)
         open(default, "ab")
     self._conf.read((self._path))
     self._conf.data.clean_format()
     self._dirty = False
     self._ui.status(_("Configuration at '%s' loaded.\n") % self._path)
Exemple #2
0
def defaultpath(pathtype, ui, path=""):
    if pathtype == "user":
        paths = util.user_rcpath()
        path = os.path.abspath(paths[len(paths) - 1])
    elif pathtype == "global":
        if os.name == "posix":
            path = "/etc/mercurial/hgrc"
        else:
            ui.warn(
                _(
                    "Default system path only supported on"
                    + " POSIX-style systems. Please use '-f' instead to"
                    + " specify a file."
                )
            )
            path = "<Not Supported>"
            return path
    elif pathtype == "environment":
        paths = os.environ["HGRCPATH"].split(os.pathsep)
        path = os.path.abspath(paths[len(paths) - 1])
    elif pathtype == "local":
        path = repoconfpath()
    elif pathtype == "file":
        path = os.path.abspath(path)
    else:
        raise "Invalid Path Type"
    checkexists(path, "default %s" % pathtype, ui)
    return path
Exemple #3
0
def getrcpath():
    if 'HGRCPATH' in os.environ:
        path = os.environ['HGRCPATH'].split(os.pathsep)[0]
    else:
        path = util.user_rcpath()[0]
    if not os.path.exists(path):
        with open(path, "wb") as _empty:
            pass # create empty file
    return path
Exemple #4
0
 def pathclass(self, path):
     pathtype = "[other]"
     if path == repoconfpath():
         pathtype = "[repository]"
     if path in util.user_rcpath():
         pathtype = "[user]"
     elif path in util.system_rcpath():
         pathtype = "[system-wide]"
     elif "HGRCPATH" in os.environ:
         if path in os.environ["HGRCPATH"].split(os.pathsep):
             pathtype = "[environment]"
     return "%s\t%s" % (path, pathtype)
Exemple #5
0
def setuser(ui, **opts):
    """
    Sets ui.username field in Mercurial configuration.
    Username saved in format: First Last <*****@*****.**>.
    If a -u option is passed, it overrides and
    username will be set to given string.

    Examples:

    hg setuser
    (Launches interactive editor to set username and password in default
     user configurationg file)

    hg setuser -n "Jerry Garcia" -e "*****@*****.**" -l
    (Sets username for the current local repository as
     'Jerry Garcia <*****@*****.**>')

    hg setuser -u "Paul Ringo John and George"
    (Sets default username to 'Paul Ringo John and George'.)
    """
    if opts["local"]:
        if not existslocalrepo():
            raise error.RepoLookupError(_("No local repository found"))
        path = repoconfpath()
    elif "HGRCPATH" in os.environ:
        path = os.environ["HGRCPATH"].split(os.pathsep)[0]
    else:
        path = util.user_rcpath()[0]
    if not os.path.exists(path):
        with open(path, "wb") as _empty:
            pass  # create empty file
    conf = SafeConfigParser()
    conf.read(path)
    if opts["username"]:
        username = opts["username"]
    else:
        if opts["name"]:
            name = opts["name"]
        else:
            name = ui.prompt(_("Full Name: "), "")
        if opts["email"]:
            email = opts["email"]
        else:
            email = ui.prompt(_("Email: "), "")
        email = " <%s>" % email if email else ""
        username = "******" % (name, email)
    if "ui" not in conf.sections():
        conf.add_section("ui")
    conf.set("ui", "username", username)
    savepretty(conf, path)
    ui.status(_("Username saved in %s\n") % path)