annotate rhodecode/lib/paster_commands/cleanup.py @ 3915:a42bfe8a9335 beta

moved make-index command to paster_commands module - optimized imports and code
author Marcin Kuzminski <marcin@python-works.com>
date Thu, 30 May 2013 00:01:16 +0200
parents 4839bc1d89fa
children 5293d4bbb1ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
3340
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents: 3336
diff changeset
35 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
36 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
37 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
38
3915
a42bfe8a9335 moved make-index command to paster_commands module
Marcin Kuzminski <marcin@python-works.com>
parents: 3703
diff changeset
39 # fix rhodecode import
a42bfe8a9335 moved make-index command to paster_commands module
Marcin Kuzminski <marcin@python-works.com>
parents: 3703
diff changeset
40 from os.path import dirname as dn
a42bfe8a9335 moved make-index command to paster_commands module
Marcin Kuzminski <marcin@python-works.com>
parents: 3703
diff changeset
41 rc_path = dn(dn(dn(os.path.realpath(__file__))))
a42bfe8a9335 moved make-index command to paster_commands module
Marcin Kuzminski <marcin@python-works.com>
parents: 3703
diff changeset
42 sys.path.append(rc_path)
2602
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 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
45
17083006a33d Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
46
3340
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents: 3336
diff changeset
47 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
48
17083006a33d Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
49 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
50 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
51
17083006a33d Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
52 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
53 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
54 takes_config_file = -1
3340
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents: 3336
diff changeset
55 parser = BasePasterCommand.standard_parser(verbose=True)
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents: 3336
diff changeset
56 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
57
17083006a33d Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
58 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
59 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
60 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
61 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
62 return
17083006a33d Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
63 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
64 time_params = {}
17083006a33d Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
65 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
66 if param:
17083006a33d Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
67 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
68 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
69
17083006a33d Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
70 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
71 """
17083006a33d Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
72 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
73 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
74
17083006a33d Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
75 :param name:
17083006a33d Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
76 """
17083006a33d Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
77 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
78 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
79
17083006a33d Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
80 def command(self):
3340
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents: 3336
diff changeset
81 #get SqlAlchemy session
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents: 3336
diff changeset
82 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
83
17083006a33d Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
84 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
85 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
86 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
87 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
88 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
89 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
90 '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
91 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
92 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
93 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
94 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
95 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
96 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
97 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
98
17083006a33d Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
99 #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
100 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
101 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
102 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
103 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
104 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
105 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
106 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
107 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
108 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
109
17083006a33d Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
110 to_remove = to_remove_filtered
3594
381c1466141d paster cleanup: improve texts
Mads Kiilerich <madski@unity3d.com>
parents: 3395
diff changeset
111 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
112 % (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
113 else:
17083006a33d Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
114 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
115 % 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
116 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
117 # 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
118 remove = True
17083006a33d Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
119 else:
3594
381c1466141d paster cleanup: improve texts
Mads Kiilerich <madski@unity3d.com>
parents: 3395
diff changeset
120 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
121 '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
122 % ', \n'.join(['%s removed on %s'
381eea235ae7 fix unicode issues on cleanup-repos script
Marcin Kuzminski <marcin@python-works.com>
parents: 2673
diff changeset
123 % (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
124
17083006a33d Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
125 if remove:
3383
c8fd8cca71f2 cleanup: remove superfluous os.path.join on absolute path
Marcin Kuzminski <marcin@python-works.com>
parents: 3340
diff changeset
126 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
127 print >> sys.stdout, 'removing repository %s' % path
3395
4b84f435594b fixed cleanup command
Marcin Kuzminski <marcin@python-works.com>
parents: 3384
diff changeset
128 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
129 else:
17083006a33d Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
130 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
131 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
132
17083006a33d Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
133 def update_parser(self):
3395
4b84f435594b fixed cleanup command
Marcin Kuzminski <marcin@python-works.com>
parents: 3384
diff changeset
134 self.parser.add_option(
4b84f435594b fixed cleanup command
Marcin Kuzminski <marcin@python-works.com>
parents: 3384
diff changeset
135 '--older-than',
4b84f435594b fixed cleanup command
Marcin Kuzminski <marcin@python-works.com>
parents: 3384
diff changeset
136 action='store',
4b84f435594b fixed cleanup command
Marcin Kuzminski <marcin@python-works.com>
parents: 3384
diff changeset
137 dest='older_than',
4b84f435594b fixed cleanup command
Marcin Kuzminski <marcin@python-works.com>
parents: 3384
diff changeset
138 help=("only remove repos that have been removed "
3594
381c1466141d paster cleanup: improve texts
Mads Kiilerich <madski@unity3d.com>
parents: 3395
diff changeset
139 "at least given time ago. "
381c1466141d paster cleanup: improve texts
Mads Kiilerich <madski@unity3d.com>
parents: 3395
diff changeset
140 "The default is to remove all removed repositories. "
381c1466141d paster cleanup: improve texts
Mads Kiilerich <madski@unity3d.com>
parents: 3395
diff changeset
141 "Possible suffixes: "
381c1466141d paster cleanup: improve texts
Mads Kiilerich <madski@unity3d.com>
parents: 3395
diff changeset
142 "d (days), h (hours), m (minutes), s (seconds). "
381c1466141d paster cleanup: improve texts
Mads Kiilerich <madski@unity3d.com>
parents: 3395
diff changeset
143 "For example --older-than=30d deletes repositories "
381c1466141d paster cleanup: improve texts
Mads Kiilerich <madski@unity3d.com>
parents: 3395
diff changeset
144 "removed more than 30 days ago.")
3395
4b84f435594b fixed cleanup command
Marcin Kuzminski <marcin@python-works.com>
parents: 3384
diff changeset
145 )
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 self.parser.add_option(
4b84f435594b fixed cleanup command
Marcin Kuzminski <marcin@python-works.com>
parents: 3384
diff changeset
148 '--dont-ask',
4b84f435594b fixed cleanup command
Marcin Kuzminski <marcin@python-works.com>
parents: 3384
diff changeset
149 action="store_true",
4b84f435594b fixed cleanup command
Marcin Kuzminski <marcin@python-works.com>
parents: 3384
diff changeset
150 dest="dont_ask",
3594
381c1466141d paster cleanup: improve texts
Mads Kiilerich <madski@unity3d.com>
parents: 3395
diff changeset
151 help="remove repositories without asking for confirmation."
3395
4b84f435594b fixed cleanup command
Marcin Kuzminski <marcin@python-works.com>
parents: 3384
diff changeset
152 )