| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import optparse | 5 import optparse |
| 6 import os | 6 import os |
| 7 import shutil | 7 import shutil |
| 8 import sys | 8 import sys |
| 9 | 9 |
| 10 | 10 |
| 11 def CleanUpOldVersions(path_to_app, keep_version, stamp_path): | 11 def CleanUpOldVersions(path_to_app, keep_version, stamp_path): |
| 12 versions_dir = os.path.join(path_to_app, 'Contents', 'Versions') | 12 versions_dir = os.path.join(path_to_app, 'Contents', 'Versions') |
| 13 if not os.path.exists(versions_dir): |
| 14 return |
| 15 |
| 13 for version in os.listdir(versions_dir): | 16 for version in os.listdir(versions_dir): |
| 14 if version != keep_version: | 17 if version != keep_version: |
| 15 shutil.rmtree(os.path.join(versions_dir, version)) | 18 shutil.rmtree(os.path.join(versions_dir, version)) |
| 16 | 19 |
| 17 open(stamp_path, 'w').close() | 20 open(stamp_path, 'w').close() |
| 18 os.utime(stamp_path, None) | 21 os.utime(stamp_path, None) |
| 19 | 22 |
| 20 | 23 |
| 21 def Main(): | 24 def Main(): |
| 22 parser = optparse.OptionParser( | 25 parser = optparse.OptionParser( |
| 23 usage='%prog path/to/Chromium.app keep_version stamp_path') | 26 usage='%prog path/to/Chromium.app keep_version stamp_path') |
| 24 opts, args = parser.parse_args() | 27 opts, args = parser.parse_args() |
| 25 if len(args) != 3: | 28 if len(args) != 3: |
| 26 parser.error('missing arguments') | 29 parser.error('missing arguments') |
| 27 return 1 | 30 return 1 |
| 28 | 31 |
| 29 CleanUpOldVersions(*args) | 32 CleanUpOldVersions(*args) |
| 30 return 0 | 33 return 0 |
| 31 | 34 |
| 32 if __name__ == '__main__': | 35 if __name__ == '__main__': |
| 33 sys.exit(Main()) | 36 sys.exit(Main()) |
| OLD | NEW |