Mercurial > kallithea
annotate rhodecode/lib/cleanup.py @ 3229:aad51f79d040 beta
added a flag for generating pull-request comments, and force display on pull-requests
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 26 Jan 2013 21:21:11 +0100 |
parents | 742d1b8ca263 |
children | f62d805544a4 |
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 """ |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3 package.rhodecode.lib.cleanup |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
5 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
6 :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
|
7 :author: marcink |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
8 :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
|
9 :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
|
10 """ |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
11 # 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
|
12 # 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
|
13 # 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
|
14 # (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
|
15 # |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
16 # 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
|
17 # 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
|
18 # 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
|
19 # 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
|
20 # |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
21 # 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
|
22 # 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
|
23 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
|
24 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
25 import os |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
26 import sys |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
27 import re |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
28 import shutil |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
29 import logging |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
30 import datetime |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
31 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
32 from os.path import dirname as dn, join as jn |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
33 from rhodecode.model import init_model |
2925
381eea235ae7
fix unicode issues on cleanup-repos script
Marcin Kuzminski <marcin@python-works.com>
parents:
2673
diff
changeset
|
34 from rhodecode.lib.utils2 import engine_from_config, 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
|
35 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
|
36 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
38 #to get the rhodecode import |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
39 sys.path.append(dn(dn(dn(os.path.realpath(__file__))))) |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
40 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
41 from rhodecode.lib.utils import BasePasterCommand, Command, ask_ok,\ |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
42 REMOVED_REPO_PAT, add_cache |
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 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
47 class CleanupCommand(BasePasterCommand): |
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 summary = "Cleanup deleted repos" |
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 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
56 parser = Command.standard_parser(verbose=True) |
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): |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
81 logging.config.fileConfig(self.path_to_ini_file) |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
82 from pylons import config |
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 #get to remove repos !! |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
85 add_cache(config) |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
86 engine = engine_from_config(config, 'sqlalchemy.db1.') |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
87 init_model(engine) |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
88 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
89 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
|
90 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
|
91 for dn, dirs, f in os.walk(safe_str(repos_location)): |
2962
c400f2fbf131
cleanup script walks recursive on dirs to find repos to cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
2925
diff
changeset
|
92 for loc in dirs: |
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): |
c400f2fbf131
cleanup script walks recursive on dirs to find repos to cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
2925
diff
changeset
|
94 to_remove.append([loc, self._extract_date(loc)]) |
2602
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
95 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
96 #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
|
97 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
|
98 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
|
99 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
|
100 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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
107 to_remove = 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
|
108 print >> sys.stdout, 'removing [%s] deleted repos older than %s[%s]' \ |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
109 % (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
|
110 else: |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
111 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
|
112 % 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
|
113 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
|
114 # 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
|
115 remove = True |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
116 else: |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
117 remove = ask_ok('are you sure to remove listed repos \n%s [y/n]?' |
2925
381eea235ae7
fix unicode issues on cleanup-repos script
Marcin Kuzminski <marcin@python-works.com>
parents:
2673
diff
changeset
|
118 % ', \n'.join(['%s removed on %s' |
381eea235ae7
fix unicode issues on cleanup-repos script
Marcin Kuzminski <marcin@python-works.com>
parents:
2673
diff
changeset
|
119 % (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
|
120 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
121 if remove: |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
122 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
|
123 print >> sys.stdout, 'removing repository %s' % name |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
124 shutil.rmtree(os.path.join(repos_location, name)) |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
125 else: |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
126 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
|
127 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
|
128 |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
129 def update_parser(self): |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
130 self.parser.add_option('--older-than', |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
131 action='store', |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
132 dest='older_than', |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
133 help=( |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
134 "only remove repos that have been removed " |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
135 "at least given time ago " |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
136 "ex. --older-than=30d deletes repositores " |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
137 "removed more than 30days ago. Possible options " |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
138 "d[ays]/h[ours]/m[inutes]/s[seconds]. OPTIONAL"), |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
139 ) |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
140 self.parser.add_option('--dont-ask', |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
141 action='store_true', |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
142 dest='dont_ask', |
17083006a33d
Added cleanup repos script that allows to cleanup removed repos from rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
143 help=("Don't ask to remove repos")) |