| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """This module allows adding and deleting of projects to the local manifest.""" | 7 """This module allows adding and deleting of projects to the local manifest.""" |
| 8 | 8 |
| 9 import sys | 9 import sys |
| 10 import optparse | 10 import optparse |
| 11 import os | 11 import os |
| 12 import xml.etree.ElementTree as ElementTree | 12 import xml.etree.ElementTree as ElementTree |
| 13 | 13 |
| 14 from cros_build_lib import Die | 14 from cros_build_lib import Die, FindRepoDir |
| 15 | |
| 16 | |
| 17 def _FindRepoDir(): | |
| 18 cwd = os.getcwd() | |
| 19 while cwd != '/': | |
| 20 repo_dir = os.path.join(cwd, '.repo') | |
| 21 if os.path.isdir(repo_dir): | |
| 22 return repo_dir | |
| 23 cwd = os.path.dirname(cwd) | |
| 24 return None | |
| 25 | 15 |
| 26 | 16 |
| 27 def _ReadManifest(manifest, err_not_found=False): | 17 def _ReadManifest(manifest, err_not_found=False): |
| 28 if os.path.isfile(manifest): | 18 if os.path.isfile(manifest): |
| 29 ptree = LocalManifest(open(manifest).read()) | 19 ptree = LocalManifest(open(manifest).read()) |
| 30 elif err_not_found: | 20 elif err_not_found: |
| 31 Die('Manifest file, %s, not found' % manifest) | 21 Die('Manifest file, %s, not found' % manifest) |
| 32 else: | 22 else: |
| 33 ptree = LocalManifest() | 23 ptree = LocalManifest() |
| 34 ptree.Parse() | 24 ptree.Parse() |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 for project in self._root.findall('project'): | 79 for project in self._root.findall('project'): |
| 90 if project.attrib['name'] == name: | 80 if project.attrib['name'] == name: |
| 91 return project | 81 return project |
| 92 return None | 82 return None |
| 93 | 83 |
| 94 def ToString(self): | 84 def ToString(self): |
| 95 return ElementTree.tostring(self._root, encoding='UTF-8') | 85 return ElementTree.tostring(self._root, encoding='UTF-8') |
| 96 | 86 |
| 97 | 87 |
| 98 def main(argv): | 88 def main(argv): |
| 99 repo_dir = _FindRepoDir() | 89 repo_dir = FindRepoDir() |
| 100 if not repo_dir: | 90 if not repo_dir: |
| 101 Die("Unable to find repo dir.") | 91 Die("Unable to find repo dir.") |
| 102 | 92 |
| 103 usage = 'usage: %prog add [options] <name>' | 93 usage = 'usage: %prog add [options] <name>' |
| 104 parser = optparse.OptionParser(usage=usage) | 94 parser = optparse.OptionParser(usage=usage) |
| 105 parser.add_option('-w', '--workon', action='store_true', dest='workon', | 95 parser.add_option('-w', '--workon', action='store_true', dest='workon', |
| 106 default=False, help='Is this a workon package?') | 96 default=False, help='Is this a workon package?') |
| 107 parser.add_option('-f', '--file', dest='local_manifest', | 97 parser.add_option('-f', '--file', dest='local_manifest', |
| 108 default='%s/local_manifest.xml' % repo_dir, | 98 default='%s/local_manifest.xml' % repo_dir, |
| 109 help='Non-default manifest file to read.') | 99 help='Non-default manifest file to read.') |
| (...skipping 20 matching lines...) Expand all Loading... |
| 130 Die('name "%s" already exits with a different path.' % name) | 120 Die('name "%s" already exits with a different path.' % name) |
| 131 | 121 |
| 132 try: | 122 try: |
| 133 print >> open(options.local_manifest, 'w'), local_tree.ToString() | 123 print >> open(options.local_manifest, 'w'), local_tree.ToString() |
| 134 except Exception, e: | 124 except Exception, e: |
| 135 Die('Error writing to manifest: %s' % e) | 125 Die('Error writing to manifest: %s' % e) |
| 136 | 126 |
| 137 | 127 |
| 138 if __name__ == '__main__': | 128 if __name__ == '__main__': |
| 139 main(sys.argv) | 129 main(sys.argv) |
| OLD | NEW |