| 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'): | |
| 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 | |
| 44 class SCMWrapper(object): | 30 class SCMWrapper(object): |
| 45 """Add necessary glue between all the supported SCM. | 31 """Add necessary glue between all the supported SCM. |
| 46 | 32 |
| 47 This is the abstraction layer to bind to different SCM. Since currently only | 33 This is the abstraction layer to bind to different SCM. Since currently only |
| 48 subversion is supported, a lot of subersionism remains. This can be sorted out | 34 subversion is supported, a lot of subersionism remains. This can be sorted out |
| 49 once another SCM is supported.""" | 35 once another SCM is supported.""" |
| 50 def __init__(self, url, root_dir, relpath, scm_name='svn'): | 36 def __init__(self, url=None, root_dir=None, relpath=None, |
| 37 scm_name='svn'): |
| 38 # TODO(maruel): Deduce the SCM from the url. |
| 51 self.scm_name = scm_name | 39 self.scm_name = scm_name |
| 52 self.url = url | 40 self.url = url |
| 53 self._root_dir = root_dir.replace('/', os.sep) | 41 self._root_dir = root_dir |
| 54 self.relpath = relpath.replace('/', os.sep) | 42 if self._root_dir: |
| 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) |
| 55 | 47 |
| 56 def FullUrlForRelativeUrl(self, url): | 48 def FullUrlForRelativeUrl(self, url): |
| 57 # Find the forth '/' and strip from there. A bit hackish. | 49 # Find the forth '/' and strip from there. A bit hackish. |
| 58 return '/'.join(self.url.split('/')[:4]) + url | 50 return '/'.join(self.url.split('/')[:4]) + url |
| 59 | 51 |
| 60 def RunCommand(self, command, options, args, file_list=None): | 52 def RunCommand(self, command, options, args, file_list=None): |
| 61 # file_list will have all files that are modified appended to it. | 53 # file_list will have all files that are modified appended to it. |
| 62 if file_list is None: | 54 if file_list is None: |
| 63 file_list = [] | 55 file_list = [] |
| 64 | 56 |
| 65 commands = ['cleanup', 'export', 'update', 'revert', | 57 commands = { |
| 66 'status', 'diff', 'pack', 'runhooks'] | 58 'cleanup': self.cleanup, |
| 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 if not command in dir(self): | 71 return commands[command](options, args, file_list) |
| 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 """ | |
| 80 | 72 |
| 81 def cleanup(self, options, args, file_list): | 73 def cleanup(self, options, args, file_list): |
| 82 """Cleanup working copy.""" | 74 """Cleanup working copy.""" |
| 83 command = ['cleanup'] | 75 command = ['cleanup'] |
| 84 command.extend(args) | 76 command.extend(args) |
| 85 RunSVN(command, os.path.join(self._root_dir, self.relpath)) | 77 RunSVN(command, os.path.join(self._root_dir, self.relpath)) |
| 86 | 78 |
| 87 def diff(self, options, args, file_list): | 79 def diff(self, options, args, file_list): |
| 88 # NOTE: This function does not currently modify file_list. | 80 # NOTE: This function does not currently modify file_list. |
| 89 command = ['diff'] | 81 command = ['diff'] |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 os.path.join(self._root_dir, self.relpath)) | 251 os.path.join(self._root_dir, self.relpath)) |
| 260 accumulated_paths = [p] | 252 accumulated_paths = [p] |
| 261 accumulated_length = len(p) | 253 accumulated_length = len(p) |
| 262 else: | 254 else: |
| 263 accumulated_paths.append(p) | 255 accumulated_paths.append(p) |
| 264 accumulated_length += len(p) | 256 accumulated_length += len(p) |
| 265 if accumulated_paths: | 257 if accumulated_paths: |
| 266 RunSVN(command + accumulated_paths, | 258 RunSVN(command + accumulated_paths, |
| 267 os.path.join(self._root_dir, self.relpath)) | 259 os.path.join(self._root_dir, self.relpath)) |
| 268 | 260 |
| 269 def runhooks(self, options, args, file_list): | |
| 270 self.status(options, args, file_list) | |
| 271 | |
| 272 def status(self, options, args, file_list): | 261 def status(self, options, args, file_list): |
| 273 """Display status information.""" | 262 """Display status information.""" |
| 274 path = os.path.join(self._root_dir, self.relpath) | 263 path = os.path.join(self._root_dir, self.relpath) |
| 275 command = ['status'] | 264 command = ['status'] |
| 276 command.extend(args) | 265 command.extend(args) |
| 277 if not os.path.isdir(path): | 266 if not os.path.isdir(path): |
| 278 # svn status won't work if the directory doesn't exist. | 267 # svn status won't work if the directory doesn't exist. |
| 279 print("\n________ couldn't run \'%s\' in \'%s\':\nThe directory " | 268 print("\n________ couldn't run \'%s\' in \'%s\':\nThe directory " |
| 280 "does not exist." | 269 "does not exist." |
| 281 % (' '.join(command), path)) | 270 % (' '.join(command), path)) |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 xml_props_status) | 568 xml_props_status) |
| 580 # Col 2 | 569 # Col 2 |
| 581 if wc_status[0].getAttribute('wc-locked') == 'true': | 570 if wc_status[0].getAttribute('wc-locked') == 'true': |
| 582 statuses[2] = 'L' | 571 statuses[2] = 'L' |
| 583 # Col 3 | 572 # Col 3 |
| 584 if wc_status[0].getAttribute('copied') == 'true': | 573 if wc_status[0].getAttribute('copied') == 'true': |
| 585 statuses[3] = '+' | 574 statuses[3] = '+' |
| 586 item = (''.join(statuses), file) | 575 item = (''.join(statuses), file) |
| 587 results.append(item) | 576 results.append(item) |
| 588 return results | 577 return results |
| OLD | NEW |