<s> '''<STR_LIT>''' <EOL> import os <EOL> from xml . dom import minidom <EOL> import goslate <EOL> from sqlalchemy import create_engine <EOL> from sqlalchemy . orm import sessionmaker <EOL> from sqlalchemy . pool import StaticPool <EOL> from DataAccess import DataString <EOL> __author__ = '<STR_LIT>' <EOL> class ImportData ( ) : <EOL> def deleteAllData ( self ) : <EOL> scriptdir = os . path . dirname ( os . path . abspath ( __file__ ) ) <EOL> sp_file_db = os . path . join ( scriptdir , "<STR_LIT>" ) <EOL> engine = create_engine ( r'<STR_LIT>' , connect_args = { '<STR_LIT>' : True } , poolclass = StaticPool ) <EOL> session = sessionmaker ( ) <EOL> session . configure ( bind = engine ) <EOL> s = session ( ) <EOL> try : <EOL> for tsr in s . query ( DataString ) . all ( ) : <EOL> s . delete ( tsr ) <EOL> s . commit ( ) <EOL> s . close ( ) <EOL> except Exception as e : <EOL> print e <EOL> s . rollback ( ) <EOL> s . close ( ) <EOL> def importFile ( self , window , path , languageTo ) : <EOL> self . deleteAllData ( ) <EOL> file = open ( path ) <EOL> gs = goslate . Goslate ( ) <EOL> doc = minidom . parse ( file ) <EOL> data = doc . getElementsByTagName ( '<STR_LIT:string>' ) <EOL> engine = create_engine ( '<STR_LIT>' , connect_args = { '<STR_LIT>' : True } , poolclass = StaticPool ) <EOL> session = sessionmaker ( ) <EOL> session . configure ( bind = engine ) <EOL> s = session ( ) <EOL> for d in range ( len ( data ) ) : <EOL> window . lbProcess . setText ( '<STR_LIT>' % ( d , len ( data ) ) ) <EOL> attr_name = data [ d ] . attributes [ '<STR_LIT:name>' ] . value <EOL> text = data [ d ] . firstChild . nodeValue <EOL> translation = gs . translate ( text , languageTo ) <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" , len ( data ) <EOL> print "<STR_LIT>" , attr_name <EOL> print "<STR_LIT>" , text <EOL> print "<STR_LIT>" , translation <EOL> print "<STR_LIT>" , languageTo <EOL> try : <EOL> ins = DataString ( name = attr_name , <EOL> value = text , <EOL> translation = translation , <EOL> language_translation = languageTo ) <EOL> s . add ( ins ) <EOL> s . commit ( ) <EOL> except Exception as e : <EOL> window . lbProcess . setText ( str ( e ) ) <EOL> print e <EOL> s . rollback ( ) <EOL> window . lbProcess . setText ( '<STR_LIT>' ) <EOL> window . btExportFile . setEnabled ( True ) </s>
