settings.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # Copyright (c) 2011 The Chromium OS Authors.
  2. #
  3. # See file CREDITS for list of people who contributed to this
  4. # project.
  5. #
  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.
  10. #
  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.
  15. #
  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,
  19. # MA 02111-1307 USA
  20. #
  21. import ConfigParser
  22. import os
  23. import re
  24. import command
  25. def ReadGitAliases(fname):
  26. """Read a git alias file. This is in the form used by git:
  27. alias uboot u-boot@lists.denx.de
  28. alias wd Wolfgang Denk <wd@denx.de>
  29. Args:
  30. fname: Filename to read
  31. """
  32. try:
  33. fd = open(fname, 'r')
  34. except IOError:
  35. print "Warning: Cannot find alias file '%s'" % fname
  36. return
  37. re_line = re.compile('alias\s+(\S+)\s+(.*)')
  38. for line in fd.readlines():
  39. line = line.strip()
  40. if not line or line[0] == '#':
  41. continue
  42. m = re_line.match(line)
  43. if not m:
  44. print "Warning: Alias file line '%s' not understood" % line
  45. continue
  46. list = alias.get(m.group(1), [])
  47. for item in m.group(2).split(','):
  48. item = item.strip()
  49. if item:
  50. list.append(item)
  51. alias[m.group(1)] = list
  52. fd.close()
  53. def Setup(config_fname=''):
  54. """Set up the settings module by reading config files.
  55. Args:
  56. config_fname: Config filename to read ('' for default)
  57. """
  58. settings = ConfigParser.SafeConfigParser()
  59. if config_fname == '':
  60. config_fname = '%s/.patman' % os.getenv('HOME')
  61. if config_fname:
  62. settings.read(config_fname)
  63. for name, value in settings.items('alias'):
  64. alias[name] = value.split(',')
  65. # These are the aliases we understand, indexed by alias. Each member is a list.
  66. alias = {}