OSDN Git Service

Merge branch 'dev' of ssh://raid.local.hde.co.jp/hde/karesansui/karesansui into dev
[karesansui/karesansui.git] / bin / update_software.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # This file is part of Karesansui.
5 #
6 # Copyright (C) 2009-2010 HDE, Inc.
7 #
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License
10 # as published by the Free Software Foundation; either version 2
11 # of the License, or (at your option) any later version.
12 #
13
14 """ 
15 <description>
16
17 @file:   update_software.py
18 @author: Kei Funagayama <kei@karesansui-project.info>
19 @copyright:    
20
21 <comment-ja>
22 Karesansuiパッケージをアップデートする。
23
24  使用方法: update_software.py [オプション]
25
26   オプション:
27     --version             プログラムのバージョンを表示
28     -h, --help            使用方法を表示
29 </comment-ja>
30 <comment-en>
31 </comment-en>
32 """
33
34 import os
35 import sys
36 import logging
37 from optparse import OptionParser
38
39 from ksscommand import KssCommand, KssCommandException
40
41 import __cmd__
42
43 try:
44     import karesansui
45     from karesansui import __version__
46     from karesansui.lib.virt.virt import KaresansuiVirtConnection
47     from karesansui.lib.utils import load_locale
48 except ImportError:
49     print >>sys.stderr, "[Error] karesansui package was not found."
50     sys.exit(1)
51
52 _ = load_locale()
53
54 usage = '%prog [options]'
55
56 def getopts():
57     optp = OptionParser(usage=usage, version=__version__)
58     return optp.parse_args()
59
60 def chkopts(opts):
61     pass
62
63 class UpdateSoftware(KssCommand):
64
65     def process(self):
66         (opts, args) = getopts()
67         chkopts(opts)
68         self.up_progress(10)
69
70         import karesansui.plus.updater
71         yu = karesansui.plus.updater.YumUpdater(karesansui.config)
72         try:
73             self.up_progress(20)
74             yu.refresh()
75             self.up_progress(20)
76             ret = yu.update()
77             self.up_progress(40)
78         except:
79             raise KssCommandException('failed to update software.')
80             
81         if ret:
82             self.logger.info('Has been updated.')
83             print >>sys.stderr, 'Has been updated.'
84         else:
85             self.logger.info('Which did not have to be updated..')
86             print >>sys.stderr, 'Which did not have to be updated.'
87
88         self.up_progress(10)
89
90         return True
91
92 if __name__ == "__main__":
93     target = UpdateSoftware()
94     sys.exit(target.run())