Commit 87d65558efe50bb2cc3617bafd8399695212c0e5
Committed by
Wolfgang Denk
1 parent
2b36c75d7b
Exists in
master
and in
54 other branches
patman: Handle creation of patman config file
patman shouts when it couldn't find a $(HOME)/.patman file. Handle it in a sane way by creating a new one for the user. It looks for a user.name and user.email in the global .gitconfig file, waits for the user input if it can't find there. Update the same in the README Signed-off-by: Vikram Narayanan <vikram186@gmail.com> Acked-by: Simon Glass <sjg@chromium.org> Cc: Simon Glass <sjg@chromium.org> Cc: Wolfgang Denk <wd@denx.de>
Showing 3 changed files with 55 additions and 3 deletions Side-by-side Diff
tools/patman/README
... | ... | @@ -68,6 +68,9 @@ |
68 | 68 | For most cases patman will locate and use the file 'doc/git-mailrc' in |
69 | 69 | your U-Boot directory. This contains most of the aliases you will need. |
70 | 70 | |
71 | +During the first run patman creates a config file for you by taking the default | |
72 | +user name and email address from the global .gitconfig file. | |
73 | + | |
71 | 74 | To add your own, create a file ~/.patman like this: |
72 | 75 | |
73 | 76 | >>>> |
tools/patman/gitutil.py
... | ... | @@ -357,6 +357,24 @@ |
357 | 357 | fname = os.path.join(GetTopLevel(), fname.strip()) |
358 | 358 | return fname |
359 | 359 | |
360 | +def GetDefaultUserName(): | |
361 | + """Gets the user.name from .gitconfig file. | |
362 | + | |
363 | + Returns: | |
364 | + User name found in .gitconfig file, or None if none | |
365 | + """ | |
366 | + uname = command.OutputOneLine('git', 'config', '--global', 'user.name') | |
367 | + return uname | |
368 | + | |
369 | +def GetDefaultUserEmail(): | |
370 | + """Gets the user.email from the global .gitconfig file. | |
371 | + | |
372 | + Returns: | |
373 | + User's email found in .gitconfig file, or None if none | |
374 | + """ | |
375 | + uemail = command.OutputOneLine('git', 'config', '--global', 'user.email') | |
376 | + return uemail | |
377 | + | |
360 | 378 | def Setup(): |
361 | 379 | """Set up git utils, by reading the alias files.""" |
362 | 380 | settings.Setup('') |
tools/patman/settings.py
... | ... | @@ -24,8 +24,8 @@ |
24 | 24 | import re |
25 | 25 | |
26 | 26 | import command |
27 | +import gitutil | |
27 | 28 | |
28 | - | |
29 | 29 | def ReadGitAliases(fname): |
30 | 30 | """Read a git alias file. This is in the form used by git: |
31 | 31 | |
... | ... | @@ -61,6 +61,33 @@ |
61 | 61 | |
62 | 62 | fd.close() |
63 | 63 | |
64 | +def CreatePatmanConfigFile(config_fname): | |
65 | + """Creates a config file under $(HOME)/.patman if it can't find one. | |
66 | + | |
67 | + Args: | |
68 | + config_fname: Default config filename i.e., $(HOME)/.patman | |
69 | + | |
70 | + Returns: | |
71 | + None | |
72 | + """ | |
73 | + name = gitutil.GetDefaultUserName() | |
74 | + if name == None: | |
75 | + name = raw_input("Enter name: ") | |
76 | + | |
77 | + email = gitutil.GetDefaultUserEmail() | |
78 | + | |
79 | + if email == None: | |
80 | + email = raw_input("Enter email: ") | |
81 | + | |
82 | + try: | |
83 | + f = open(config_fname, 'w') | |
84 | + except IOError: | |
85 | + print "Couldn't create patman config file\n" | |
86 | + raise | |
87 | + | |
88 | + print >>f, "[alias]\nme: %s <%s>" % (name, email) | |
89 | + f.close(); | |
90 | + | |
64 | 91 | def Setup(config_fname=''): |
65 | 92 | """Set up the settings module by reading config files. |
66 | 93 | |
... | ... | @@ -70,8 +97,12 @@ |
70 | 97 | settings = ConfigParser.SafeConfigParser() |
71 | 98 | if config_fname == '': |
72 | 99 | config_fname = '%s/.patman' % os.getenv('HOME') |
73 | - if config_fname: | |
74 | - settings.read(config_fname) | |
100 | + | |
101 | + if not os.path.exists(config_fname): | |
102 | + print "No config file found ~/.patman\nCreating one...\n" | |
103 | + CreatePatmanConfigFile(config_fname) | |
104 | + | |
105 | + settings.read(config_fname) | |
75 | 106 | |
76 | 107 | for name, value in settings.items('alias'): |
77 | 108 | alias[name] = value.split(',') |