Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2009 Google Inc. All Rights Reserved. | 1 # Copyright 2009 Google Inc. All Rights Reserved. |
| 2 # | 2 # |
| 3 # Licensed under the Apache License, Version 2.0 (the "License"); | 3 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 # you may not use this file except in compliance with the License. | 4 # you may not use this file except in compliance with the License. |
| 5 # You may obtain a copy of the License at | 5 # You may obtain a copy of the License at |
| 6 # | 6 # |
| 7 # http://www.apache.org/licenses/LICENSE-2.0 | 7 # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 # | 8 # |
| 9 # Unless required by applicable law or agreed to in writing, software | 9 # Unless required by applicable law or agreed to in writing, software |
| 10 # distributed under the License is distributed on an "AS IS" BASIS, | 10 # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 # See the License for the specific language governing permissions and | 12 # See the License for the specific language governing permissions and |
| 13 # limitations under the License. | 13 # limitations under the License. |
| 14 | 14 |
| 15 | 15 |
| 16 import os | 16 import os |
| 17 import re | 17 import re |
| 18 import subprocess | 18 import subprocess |
| 19 import sys | 19 import sys |
| 20 import xml.dom.minidom | 20 import xml.dom.minidom |
| 21 | 21 |
| 22 import gclient_utils | 22 import gclient_utils |
| 23 | 23 |
| 24 SVN_COMMAND = "svn" | 24 SVN_COMMAND = "svn" |
| 25 | 25 |
| 26 | 26 |
| 27 ### SCM abstraction layer | 27 ### SCM abstraction layer |
| 28 | 28 |
| 29 | 29 |
| 30 # Factory Method for SCM wrapper creation | |
| 31 | |
| 32 def create_scm(url, root_dir, relpath, scm_name='svn'): | |
|
M-A Ruel
2009/09/17 20:56:15
Functions should be CamelCase too.
| |
| 33 # TODO(maruel): Deduce the SCM from the url. | |
| 34 scm_map = { | |
| 35 'svn' : SVNWrapper, | |
| 36 } | |
| 37 if not scm_name in scm_map: | |
| 38 raise gclient_utils.Error('Unsupported scm %s' % scm_name) | |
| 39 return scm_map[scm_name](url, root_dir, relpath, scm_name) | |
| 40 | |
| 41 | |
| 42 # SCMWrapper base class | |
| 43 | |
| 30 class SCMWrapper(object): | 44 class SCMWrapper(object): |
| 31 """Add necessary glue between all the supported SCM. | 45 """Add necessary glue between all the supported SCM. |
| 32 | 46 |
| 33 This is the abstraction layer to bind to different SCM. Since currently only | 47 This is the abstraction layer to bind to different SCM. Since currently only |
| 34 subversion is supported, a lot of subersionism remains. This can be sorted out | 48 subversion is supported, a lot of subersionism remains. This can be sorted out |
| 35 once another SCM is supported.""" | 49 once another SCM is supported.""" |
| 36 def __init__(self, url=None, root_dir=None, relpath=None, | 50 def __init__(self, url, root_dir, relpath, scm_name='svn'): |
| 37 scm_name='svn'): | |
| 38 # TODO(maruel): Deduce the SCM from the url. | |
| 39 self.scm_name = scm_name | 51 self.scm_name = scm_name |
| 40 self.url = url | 52 self.url = url |
| 41 self._root_dir = root_dir | 53 self._root_dir = root_dir.replace('/', os.sep) |
| 42 if self._root_dir: | 54 self.relpath = relpath.replace('/', os.sep) |
| 43 self._root_dir = self._root_dir.replace('/', os.sep) | |
| 44 self.relpath = relpath | |
| 45 if self.relpath: | |
| 46 self.relpath = self.relpath.replace('/', os.sep) | |
| 47 | 55 |
| 48 def FullUrlForRelativeUrl(self, url): | 56 def FullUrlForRelativeUrl(self, url): |
| 49 # Find the forth '/' and strip from there. A bit hackish. | 57 # Find the forth '/' and strip from there. A bit hackish. |
| 50 return '/'.join(self.url.split('/')[:4]) + url | 58 return '/'.join(self.url.split('/')[:4]) + url |
| 51 | 59 |
| 52 def RunCommand(self, command, options, args, file_list=None): | 60 def RunCommand(self, command, options, args, file_list=None): |
| 53 # file_list will have all files that are modified appended to it. | 61 # file_list will have all files that are modified appended to it. |
| 54 if file_list is None: | 62 if file_list is None: |
| 55 file_list = [] | 63 file_list = [] |
| 56 | 64 |
| 57 commands = { | 65 commands = ['cleanup', 'export', 'update', 'revert', |
| 58 'cleanup': self.cleanup, | 66 'status', 'diff', 'pack', 'runhooks'] |
| 59 'export': self.export, | |
| 60 'update': self.update, | |
| 61 'revert': self.revert, | |
| 62 'status': self.status, | |
| 63 'diff': self.diff, | |
| 64 'pack': self.pack, | |
| 65 'runhooks': self.status, | |
| 66 } | |
| 67 | 67 |
| 68 if not command in commands: | 68 if not command in commands: |
| 69 raise gclient_utils.Error('Unknown command %s' % command) | 69 raise gclient_utils.Error('Unknown command %s' % command) |
| 70 | 70 |
| 71 return commands[command](options, args, file_list) | 71 if not command in dir(self): |
| 72 raise gclient_utils.Error('Command %s not implemnted in %s wrapper' % ( | |
| 73 command, self.scm_name)) | |
| 74 | |
| 75 return getattr(self, command)(options, args, file_list) | |
| 76 | |
| 77 | |
| 78 class SVNWrapper(SCMWrapper): | |
| 79 """ Wrapper for SVN """ | |
| 72 | 80 |
| 73 def cleanup(self, options, args, file_list): | 81 def cleanup(self, options, args, file_list): |
| 74 """Cleanup working copy.""" | 82 """Cleanup working copy.""" |
| 75 command = ['cleanup'] | 83 command = ['cleanup'] |
| 76 command.extend(args) | 84 command.extend(args) |
| 77 RunSVN(command, os.path.join(self._root_dir, self.relpath)) | 85 RunSVN(command, os.path.join(self._root_dir, self.relpath)) |
| 78 | 86 |
| 79 def diff(self, options, args, file_list): | 87 def diff(self, options, args, file_list): |
| 80 # NOTE: This function does not currently modify file_list. | 88 # NOTE: This function does not currently modify file_list. |
| 81 command = ['diff'] | 89 command = ['diff'] |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 os.path.join(self._root_dir, self.relpath)) | 259 os.path.join(self._root_dir, self.relpath)) |
| 252 accumulated_paths = [p] | 260 accumulated_paths = [p] |
| 253 accumulated_length = len(p) | 261 accumulated_length = len(p) |
| 254 else: | 262 else: |
| 255 accumulated_paths.append(p) | 263 accumulated_paths.append(p) |
| 256 accumulated_length += len(p) | 264 accumulated_length += len(p) |
| 257 if accumulated_paths: | 265 if accumulated_paths: |
| 258 RunSVN(command + accumulated_paths, | 266 RunSVN(command + accumulated_paths, |
| 259 os.path.join(self._root_dir, self.relpath)) | 267 os.path.join(self._root_dir, self.relpath)) |
| 260 | 268 |
| 269 def runhooks(self, options, args, file_list): | |
| 270 self.status(options, args, file_list) | |
| 271 | |
| 261 def status(self, options, args, file_list): | 272 def status(self, options, args, file_list): |
| 262 """Display status information.""" | 273 """Display status information.""" |
| 263 path = os.path.join(self._root_dir, self.relpath) | 274 path = os.path.join(self._root_dir, self.relpath) |
| 264 command = ['status'] | 275 command = ['status'] |
| 265 command.extend(args) | 276 command.extend(args) |
| 266 if not os.path.isdir(path): | 277 if not os.path.isdir(path): |
| 267 # svn status won't work if the directory doesn't exist. | 278 # svn status won't work if the directory doesn't exist. |
| 268 print("\n________ couldn't run \'%s\' in \'%s\':\nThe directory " | 279 print("\n________ couldn't run \'%s\' in \'%s\':\nThe directory " |
| 269 "does not exist." | 280 "does not exist." |
| 270 % (' '.join(command), path)) | 281 % (' '.join(command), path)) |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 568 xml_props_status) | 579 xml_props_status) |
| 569 # Col 2 | 580 # Col 2 |
| 570 if wc_status[0].getAttribute('wc-locked') == 'true': | 581 if wc_status[0].getAttribute('wc-locked') == 'true': |
| 571 statuses[2] = 'L' | 582 statuses[2] = 'L' |
| 572 # Col 3 | 583 # Col 3 |
| 573 if wc_status[0].getAttribute('copied') == 'true': | 584 if wc_status[0].getAttribute('copied') == 'true': |
| 574 statuses[3] = '+' | 585 statuses[3] = '+' |
| 575 item = (''.join(statuses), file) | 586 item = (''.join(statuses), file) |
| 576 results.append(item) | 587 results.append(item) |
| 577 return results | 588 return results |
| OLD | NEW |