<s> import os <EOL> import os . path <EOL> import sys <EOL> import shutil <EOL> import glob <EOL> import logging <EOL> from optparse import OptionParser <EOL> from ksscommand import KssCommand , KssCommandException , KssCommandOptException <EOL> import __cmd__ <EOL> try : <EOL> import karesansui <EOL> from karesansui import __version__ <EOL> from karesansui . lib . virt . virt import KaresansuiVirtConnection , KaresansuiVirtException <EOL> from karesansui . lib . utils import load_locale , is_uuid <EOL> from karesansui . lib . virt . config_export import ExportConfigParam <EOL> from karesansui . lib . virt . config import ConfigParam <EOL> except ImportError , e : <EOL> print >> sys . stderr , "<STR_LIT>" % e <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> _ = load_locale ( ) <EOL> usage = '<STR_LIT>' <EOL> def getopts ( ) : <EOL> optp = OptionParser ( usage = usage , version = __version__ ) <EOL> optp . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , help = _ ( '<STR_LIT>' ) ) <EOL> return optp . parse_args ( ) <EOL> def chkopts ( opts ) : <EOL> if opts . uuid : <EOL> if not is_uuid ( opts . uuid ) : <EOL> raise KssCommandOptException ( '<STR_LIT>' % ( opts . uuid ) ) <EOL> else : <EOL> raise KssCommandOptException ( '<STR_LIT>' ) <EOL> class DeleteExportData ( KssCommand ) : <EOL> def process ( self ) : <EOL> ( opts , args ) = getopts ( ) <EOL> chkopts ( opts ) <EOL> self . up_progress ( <NUM_LIT:10> ) <EOL> kvc = KaresansuiVirtConnection ( ) <EOL> try : <EOL> inactive_pool = [ ] <EOL> active_pool = kvc . list_active_storage_pool ( ) <EOL> pools = inactive_pool + active_pool <EOL> pools . sort ( ) <EOL> export = [ ] <EOL> for pool_name in pools : <EOL> pool = kvc . search_kvn_storage_pools ( pool_name ) <EOL> path = pool [ <NUM_LIT:0> ] . get_info ( ) [ "<STR_LIT:target>" ] [ "<STR_LIT:path>" ] <EOL> if os . path . exists ( path ) : <EOL> for _afile in glob . glob ( "<STR_LIT>" % ( path , ) ) : <EOL> e_param = ExportConfigParam ( ) <EOL> e_param . load_xml_config ( _afile ) <EOL> if e_param . get_uuid ( ) != opts . uuid : <EOL> continue <EOL> e_name = e_param . get_domain ( ) <EOL> _dir = os . path . dirname ( _afile ) <EOL> param = ConfigParam ( e_name ) <EOL> path = "<STR_LIT>" % ( _dir , e_name ) <EOL> if os . path . isfile ( path ) is False : <EOL> raise KssCommandException ( <EOL> '<STR_LIT>' % path ) <EOL> param . load_xml_config ( path ) <EOL> if e_name != param . get_domain_name ( ) : <EOL> raise KssCommandException ( <EOL> '<STR_LIT>' % ( e_name , param . get_name ( ) ) ) <EOL> _dir = os . path . dirname ( _afile ) <EOL> export . append ( { "<STR_LIT>" : _dir , <EOL> "<STR_LIT>" : pool_name , <EOL> "<STR_LIT>" : e_param . get_uuid ( ) , <EOL> "<STR_LIT:name>" : e_name , <EOL> } ) <EOL> if len ( export ) < <NUM_LIT:1> : <EOL> conn = KaresansuiVirtConnection ( readonly = False ) <EOL> try : <EOL> conn . refresh_pools ( ) <EOL> finally : <EOL> conn . close ( ) <EOL> raise KssCommandException ( '<STR_LIT>' % opts . uuid ) <EOL> else : <EOL> export = export [ <NUM_LIT:0> ] <EOL> finally : <EOL> kvc . close ( ) <EOL> self . up_progress ( <NUM_LIT:30> ) <EOL> if os . path . isdir ( export [ '<STR_LIT>' ] ) is False : <EOL> raise KssCommandException ( _ ( "<STR_LIT>" ) % ( _ ( "<STR_LIT>" ) % ( export [ '<STR_LIT>' ] ) ) ) <EOL> uuid = os . path . basename ( export [ '<STR_LIT>' ] ) <EOL> pool_dir = os . path . dirname ( export [ '<STR_LIT>' ] ) <EOL> if not is_uuid ( export [ '<STR_LIT>' ] ) : <EOL> raise KssCommandException ( _ ( "<STR_LIT>" ) % ( _ ( "<STR_LIT>" ) % ( export [ '<STR_LIT>' ] ) ) ) <EOL> shutil . rmtree ( export [ '<STR_LIT>' ] ) <EOL> for _afile in glob . glob ( "<STR_LIT>" % ( export [ '<STR_LIT>' ] ) ) : <EOL> os . remove ( _afile ) <EOL> self . up_progress ( <NUM_LIT:30> ) <EOL> conn = KaresansuiVirtConnection ( readonly = False ) <EOL> try : <EOL> try : <EOL> conn . refresh_pools ( ) <EOL> finally : <EOL> conn . close ( ) <EOL> except : <EOL> pass <EOL> self . logger . info ( '<STR_LIT>' % ( opts . uuid ) ) <EOL> print >> sys . stdout , _ ( '<STR_LIT>' ) % ( opts . uuid ) <EOL> return True <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> target = DeleteExportData ( ) <EOL> sys . exit ( target . run ( ) ) </s>
