1 # Copyright (c) 2011 The Chromium OS Authors.
3 # See file CREDITS for list of people who contributed to this
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation; either version 2 of
9 # the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 def ReadGitAliases(fname):
30 """Read a git alias file. This is in the form used by git:
32 alias uboot u-boot@lists.denx.de
33 alias wd Wolfgang Denk <wd@denx.de>
36 fname: Filename to read
41 print "Warning: Cannot find alias file '%s'" % fname
44 re_line = re.compile('alias\s+(\S+)\s+(.*)')
45 for line in fd.readlines():
47 if not line or line[0] == '#':
50 m = re_line.match(line)
52 print "Warning: Alias file line '%s' not understood" % line
55 list = alias.get(m.group(1), [])
56 for item in m.group(2).split(','):
60 alias[m.group(1)] = list
64 def CreatePatmanConfigFile(config_fname):
65 """Creates a config file under $(HOME)/.patman if it can't find one.
68 config_fname: Default config filename i.e., $(HOME)/.patman
73 name = gitutil.GetDefaultUserName()
75 name = raw_input("Enter name: ")
77 email = gitutil.GetDefaultUserEmail()
80 email = raw_input("Enter email: ")
83 f = open(config_fname, 'w')
85 print "Couldn't create patman config file\n"
88 print >>f, "[alias]\nme: %s <%s>" % (name, email)
91 def Setup(config_fname=''):
92 """Set up the settings module by reading config files.
95 config_fname: Config filename to read ('' for default)
97 settings = ConfigParser.SafeConfigParser()
98 if config_fname == '':
99 config_fname = '%s/.patman' % os.getenv('HOME')
101 if not os.path.exists(config_fname):
102 print "No config file found ~/.patman\nCreating one...\n"
103 CreatePatmanConfigFile(config_fname)
105 settings.read(config_fname)
107 for name, value in settings.items('alias'):
108 alias[name] = value.split(',')
111 # These are the aliases we understand, indexed by alias. Each member is a list.