Mercurial > kallithea
annotate rhodecode/lib/paster_commands/cleanup.py @ 3774:60335b702a00 beta
invalidation: don't create CacheInvalidation records on startup
Creating the records early gave an advantage before lightweight was introduced.
With lightweight it is no longer necessary.
The records will be created on demand anyway and there is no reason to create and
maintain them before they are used.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Wed, 03 Apr 2013 15:56:12 +0200 |
parents | 4839bc1d89fa |
children | a42bfe8a9335 |
rev | line source |
---|---|
2602
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2 """ |
3703
4839bc1d89fa
small fixes backported from stable
Marcin Kuzminski <marcin@python-works.com>
parents:
3594
diff
changeset
|
3 rhodecode.lib.paster_commands.cleanup |
4839bc1d89fa
small fixes backported from stable
Marcin Kuzminski <marcin@python-works.com>
parents:
3594
diff
changeset
|
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
3340
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
3336
diff
changeset
|
5 |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
3336
diff
changeset
|
6 cleanup-repos paster command for RhodeCode |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
3336
diff
changeset
|
7 |
2602
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
8 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 :created_on: Jul 14, 2012 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
10 :author: marcink |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
11 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com> |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 :license: GPLv3, see COPYING for more details. |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
13 """ |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
14 # This program is free software: you can redistribute it and/or modify |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
15 # it under the terms of the GNU General Public License as published by |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
16 # the Free Software Foundation, either version 3 of the License, or |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
17 # (at your option) any later version. |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
18 # |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
19 # This program is distributed in the hope that it will be useful, |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
22 # GNU General Public License for more details. |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 # |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
24 # You should have received a copy of the GNU General Public License |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
25 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
26 from __future__ import with_statement |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
27 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
28 import os |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
29 import sys |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
30 import re |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
31 import shutil |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
32 import logging |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
33 import datetime |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
34 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
35 from os.path import dirname as dn, join as jn |
3340
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
3336
diff
changeset
|
36 #to get the rhodecode import |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
3336
diff
changeset
|
37 rc_path = dn(dn(dn(os.path.realpath(__file__)))) |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
3336
diff
changeset
|
38 sys.path.append(rc_path) |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
3336
diff
changeset
|
39 from rhodecode.lib.utils import BasePasterCommand, ask_ok, REMOVED_REPO_PAT |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
3336
diff
changeset
|
40 |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
3336
diff
changeset
|
41 from rhodecode.lib.utils2 import safe_str |
2602
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
42 from rhodecode.model.db import RhodeCodeUi |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
43 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
44 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
45 log = logging.getLogger(__name__) |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
46 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
47 |
3340
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
3336
diff
changeset
|
48 class Command(BasePasterCommand): |
2602
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
49 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
50 max_args = 1 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
51 min_args = 1 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
52 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
53 usage = "CONFIG_FILE" |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
54 group_name = "RhodeCode" |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
55 takes_config_file = -1 |
3340
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
3336
diff
changeset
|
56 parser = BasePasterCommand.standard_parser(verbose=True) |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
3336
diff
changeset
|
57 summary = "Cleanup deleted repos" |
2602
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
58 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
59 def _parse_older_than(self, val): |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
60 regex = re.compile(r'((?P<days>\d+?)d)?((?P<hours>\d+?)h)?((?P<minutes>\d+?)m)?((?P<seconds>\d+?)s)?') |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
61 parts = regex.match(val) |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
62 if not parts: |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
63 return |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
64 parts = parts.groupdict() |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
65 time_params = {} |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
66 for (name, param) in parts.iteritems(): |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
67 if param: |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
68 time_params[name] = int(param) |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
69 return datetime.timedelta(**time_params) |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
70 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
71 def _extract_date(self, name): |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
72 """ |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
73 Extract the date part from rm__<date> pattern of removed repos, |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
74 and convert it to datetime object |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
75 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
76 :param name: |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
77 """ |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
78 date_part = name[4:19] # 4:19 since we don't parse milisecods |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
79 return datetime.datetime.strptime(date_part, '%Y%m%d_%H%M%S') |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
80 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
81 def command(self): |
3340
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
3336
diff
changeset
|
82 #get SqlAlchemy session |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
3336
diff
changeset
|
83 self._init_session() |
2602
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
84 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
85 repos_location = RhodeCodeUi.get_repos_location() |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
86 to_remove = [] |
2963
742d1b8ca263
use str() on os.walk passing unicode can lead to UnicodeDecode errors when iterating
Marcin Kuzminski <marcin@python-works.com>
parents:
2962
diff
changeset
|
87 for dn, dirs, f in os.walk(safe_str(repos_location)): |
3384
95c38de476a7
cleanup would recurse into every leaf and could thus not be used on lots of
Marcin Kuzminski <marcin@python-works.com>
parents:
3383
diff
changeset
|
88 alldirs = list(dirs) |
95c38de476a7
cleanup would recurse into every leaf and could thus not be used on lots of
Marcin Kuzminski <marcin@python-works.com>
parents:
3383
diff
changeset
|
89 del dirs[:] |
95c38de476a7
cleanup would recurse into every leaf and could thus not be used on lots of
Marcin Kuzminski <marcin@python-works.com>
parents:
3383
diff
changeset
|
90 if ('.hg' in alldirs or |
95c38de476a7
cleanup would recurse into every leaf and could thus not be used on lots of
Marcin Kuzminski <marcin@python-works.com>
parents:
3383
diff
changeset
|
91 'objects' in alldirs and ('refs' in alldirs or 'packed-refs' in f)): |
95c38de476a7
cleanup would recurse into every leaf and could thus not be used on lots of
Marcin Kuzminski <marcin@python-works.com>
parents:
3383
diff
changeset
|
92 continue |
95c38de476a7
cleanup would recurse into every leaf and could thus not be used on lots of
Marcin Kuzminski <marcin@python-works.com>
parents:
3383
diff
changeset
|
93 for loc in alldirs: |
2962
c400f2fbf131
cleanup script walks recursive on dirs to find repos to cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
2925
diff
changeset
|
94 if REMOVED_REPO_PAT.match(loc): |
3336
f62d805544a4
fixes issue #756 cleanup repos didn't properly compose paths of repos to be cleaned up.
Marcin Kuzminski <marcin@python-works.com>
parents:
2963
diff
changeset
|
95 to_remove.append([os.path.join(dn, loc), |
f62d805544a4
fixes issue #756 cleanup repos didn't properly compose paths of repos to be cleaned up.
Marcin Kuzminski <marcin@python-works.com>
parents:
2963
diff
changeset
|
96 self._extract_date(loc)]) |
3384
95c38de476a7
cleanup would recurse into every leaf and could thus not be used on lots of
Marcin Kuzminski <marcin@python-works.com>
parents:
3383
diff
changeset
|
97 else: |
95c38de476a7
cleanup would recurse into every leaf and could thus not be used on lots of
Marcin Kuzminski <marcin@python-works.com>
parents:
3383
diff
changeset
|
98 dirs.append(loc) |
2602
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
99 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
100 #filter older than (if present)! |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
101 now = datetime.datetime.now() |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
102 older_than = self.options.older_than |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
103 if older_than: |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
104 to_remove_filtered = [] |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
105 older_than_date = self._parse_older_than(older_than) |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
106 for name, date_ in to_remove: |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
107 repo_age = now - date_ |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
108 if repo_age > older_than_date: |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
109 to_remove_filtered.append([name, date_]) |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
110 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
111 to_remove = to_remove_filtered |
3594
381c1466141d
paster cleanup: improve texts
Mads Kiilerich <madski@unity3d.com>
parents:
3395
diff
changeset
|
112 print >> sys.stdout, 'removing %s deleted repos older than %s (%s)' \ |
2602
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
113 % (len(to_remove), older_than, older_than_date) |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
114 else: |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
115 print >> sys.stdout, 'removing all [%s] deleted repos' \ |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
116 % len(to_remove) |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
117 if self.options.dont_ask or not to_remove: |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
118 # don't ask just remove ! |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
119 remove = True |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
120 else: |
3594
381c1466141d
paster cleanup: improve texts
Mads Kiilerich <madski@unity3d.com>
parents:
3395
diff
changeset
|
121 remove = ask_ok('the following repositories will be deleted completely:\n%s\n' |
381c1466141d
paster cleanup: improve texts
Mads Kiilerich <madski@unity3d.com>
parents:
3395
diff
changeset
|
122 'are you sure you want to remove them [y/n]?' |
2925
381eea235ae7
fix unicode issues on cleanup-repos script
Marcin Kuzminski <marcin@python-works.com>
parents:
2673
diff
changeset
|
123 % ', \n'.join(['%s removed on %s' |
381eea235ae7
fix unicode issues on cleanup-repos script
Marcin Kuzminski <marcin@python-works.com>
parents:
2673
diff
changeset
|
124 % (safe_str(x[0]), safe_str(x[1])) for x in to_remove])) |
2602
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
125 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
126 if remove: |
3383
c8fd8cca71f2
cleanup: remove superfluous os.path.join on absolute path
Marcin Kuzminski <marcin@python-works.com>
parents:
3340
diff
changeset
|
127 for path, date_ in to_remove: |
c8fd8cca71f2
cleanup: remove superfluous os.path.join on absolute path
Marcin Kuzminski <marcin@python-works.com>
parents:
3340
diff
changeset
|
128 print >> sys.stdout, 'removing repository %s' % path |
3395
4b84f435594b
fixed cleanup command
Marcin Kuzminski <marcin@python-works.com>
parents:
3384
diff
changeset
|
129 shutil.rmtree(path) |
2602
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
130 else: |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
131 print 'nothing done exiting...' |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
132 sys.exit(0) |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
133 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
134 def update_parser(self): |
3395
4b84f435594b
fixed cleanup command
Marcin Kuzminski <marcin@python-works.com>
parents:
3384
diff
changeset
|
135 self.parser.add_option( |
4b84f435594b
fixed cleanup command
Marcin Kuzminski <marcin@python-works.com>
parents:
3384
diff
changeset
|
136 '--older-than', |
4b84f435594b
fixed cleanup command
Marcin Kuzminski <marcin@python-works.com>
parents:
3384
diff
changeset
|
137 action='store', |
4b84f435594b
fixed cleanup command
Marcin Kuzminski <marcin@python-works.com>
parents:
3384
diff
changeset
|
138 dest='older_than', |
4b84f435594b
fixed cleanup command
Marcin Kuzminski <marcin@python-works.com>
parents:
3384
diff
changeset
|
139 help=("only remove repos that have been removed " |
3594
381c1466141d
paster cleanup: improve texts
Mads Kiilerich <madski@unity3d.com>
parents:
3395
diff
changeset
|
140 "at least given time ago. " |
381c1466141d
paster cleanup: improve texts
Mads Kiilerich <madski@unity3d.com>
parents:
3395
diff
changeset
|
141 "The default is to remove all removed repositories. " |
381c1466141d
paster cleanup: improve texts
Mads Kiilerich <madski@unity3d.com>
parents:
3395
diff
changeset
|
142 "Possible suffixes: " |
381c1466141d
paster cleanup: improve texts
Mads Kiilerich <madski@unity3d.com>
parents:
3395
diff
changeset
|
143 "d (days), h (hours), m (minutes), s (seconds). " |
381c1466141d
paster cleanup: improve texts
Mads Kiilerich <madski@unity3d.com>
parents:
3395
diff
changeset
|
144 "For example --older-than=30d deletes repositories " |
381c1466141d
paster cleanup: improve texts
Mads Kiilerich <madski@unity3d.com>
parents:
3395
diff
changeset
|
145 "removed more than 30 days ago.") |
3395
4b84f435594b
fixed cleanup command
Marcin Kuzminski <marcin@python-works.com>
parents:
3384
diff
changeset
|
146 ) |
4b84f435594b
fixed cleanup command
Marcin Kuzminski <marcin@python-works.com>
parents:
3384
diff
changeset
|
147 |
4b84f435594b
fixed cleanup command
Marcin Kuzminski <marcin@python-works.com>
parents:
3384
diff
changeset
|
148 self.parser.add_option( |
4b84f435594b
fixed cleanup command
Marcin Kuzminski <marcin@python-works.com>
parents:
3384
diff
changeset
|
149 '--dont-ask', |
4b84f435594b
fixed cleanup command
Marcin Kuzminski <marcin@python-works.com>
parents:
3384
diff
changeset
|
150 action="store_true", |
4b84f435594b
fixed cleanup command
Marcin Kuzminski <marcin@python-works.com>
parents:
3384
diff
changeset
|
151 dest="dont_ask", |
3594
381c1466141d
paster cleanup: improve texts
Mads Kiilerich <madski@unity3d.com>
parents:
3395
diff
changeset
|
152 help="remove repositories without asking for confirmation." |
3395
4b84f435594b
fixed cleanup command
Marcin Kuzminski <marcin@python-works.com>
parents:
3384
diff
changeset
|
153 ) |