|
Line 0
Link Here
|
|
|
1 |
#!/usr/bin/python2.6 |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
# |
| 4 |
# Univention App Center |
| 5 |
# univention-rename-app |
| 6 |
# |
| 7 |
# Copyright 2014 Univention GmbH |
| 8 |
# |
| 9 |
# http://www.univention.de/ |
| 10 |
# |
| 11 |
# All rights reserved. |
| 12 |
# |
| 13 |
# The source code of this program is made available |
| 14 |
# under the terms of the GNU Affero General Public License version 3 |
| 15 |
# (GNU AGPL V3) as published by the Free Software Foundation. |
| 16 |
# |
| 17 |
# Binary versions of this program provided by Univention to you as |
| 18 |
# well as other copyrighted, protected or trademarked materials like |
| 19 |
# Logos, graphics, fonts, specific documentations and configurations, |
| 20 |
# cryptographic keys etc. are subject to a license agreement between |
| 21 |
# you and Univention and not subject to the GNU AGPL V3. |
| 22 |
# |
| 23 |
# In the case you use this program under the terms of the GNU AGPL V3, |
| 24 |
# the program is provided in the hope that it will be useful, |
| 25 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 26 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 27 |
# GNU Affero General Public License for more details. |
| 28 |
# |
| 29 |
# You should have received a copy of the GNU Affero General Public |
| 30 |
# License with the Debian GNU/Linux or Univention distribution in file |
| 31 |
# /usr/share/common-licenses/AGPL-3; if not, see |
| 32 |
# <http://www.gnu.org/licenses/>. |
| 33 |
# |
| 34 |
|
| 35 |
import sys |
| 36 |
from optparse import OptionParser |
| 37 |
|
| 38 |
from univention.lib.package_manager import PackageManager |
| 39 |
from univention.updater import UniventionUpdater |
| 40 |
from univention.config_registry import ConfigRegistry |
| 41 |
from univention.management.console.modules.appcenter.util import ComponentManager, install_opener |
| 42 |
from univention.management.console.modules.appcenter.app_center import Application |
| 43 |
|
| 44 |
ucr = ConfigRegistry() |
| 45 |
ucr.load() |
| 46 |
|
| 47 |
def rename(old_id, new_id): |
| 48 |
install_opener(ucr) |
| 49 |
app = Application.find(old_id) |
| 50 |
if not app: |
| 51 |
app = Application.find(new_id) |
| 52 |
if not app: |
| 53 |
sys.stderr.write('Found neither OLD_ID nor NEW_ID.\n') |
| 54 |
raise ValueError() |
| 55 |
uu = UniventionUpdater(False) |
| 56 |
component_manager = ComponentManager(ucr, uu) |
| 57 |
package_manager = PackageManager(lock=False) |
| 58 |
|
| 59 |
if not app.is_installed(package_manager, strict=False): |
| 60 |
sys.stdout.write('%s is not installed. Fine, nothing to do.\n' % app.name) |
| 61 |
return |
| 62 |
|
| 63 |
app.set_id(old_id) |
| 64 |
app.unregister_all_and_register(None, component_manager, package_manager) |
| 65 |
app.tell_ldap(ucr, package_manager, inform_about_error=False) |
| 66 |
|
| 67 |
app.set_id(new_id) |
| 68 |
app.register(component_manager, package_manager) |
| 69 |
app.tell_ldap(ucr, package_manager, inform_about_error=False) |
| 70 |
|
| 71 |
if __name__ == '__main__': |
| 72 |
usage = '%prog OLD_ID NEW_ID' |
| 73 |
description = '%prog changes the internal ID of an application. This means:' \ |
| 74 |
'(1) unregister OLD_ID, remove from LDAP' \ |
| 75 |
'(2) register NEW_ID, add to LDAP' |
| 76 |
parser = OptionParser(usage=usage, description=description) |
| 77 |
options, args = parser.parse_args() |
| 78 |
try: |
| 79 |
old_id, new_id = args |
| 80 |
except ValueError: |
| 81 |
parser.print_usage() |
| 82 |
sys.exit(1) |
| 83 |
try: |
| 84 |
rename(old_id, new_id) |
| 85 |
except Exception as exc: |
| 86 |
sys.stderr.write('univention-rename-app did not succeed.\n') |
| 87 |
sys.exit(1) |
| 88 |
else: |
| 89 |
sys.stdout.write('Rename done.\n') |
| 90 |
sys.exit(0) |
| 91 |
|