#NEWLINE# def import_page( self , filename , title , create_only = [ ] , replace = False ) : #NEWLINE# #INDENT# if ( not validate_page_name ( title ) ) : #NEWLINE# #INDENT# raise AdminCommandError ( _ ( "Invalid Wiki page name '%(name)s'" , name = title ) ) #NEWLINE# #UNINDENT# if filename : #NEWLINE# #INDENT# if ( not os . path . isfile ( filename ) ) : #NEWLINE# #INDENT# raise AdminCommandError ( _ ( "'%(name)s' is not a file" , name = path_to_unicode ( title ) ) ) #NEWLINE# #UNINDENT# data = read_file ( filename ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# data = sys . stdin . read ( ) #NEWLINE# #UNINDENT# data = to_unicode ( data , 'utf-8' ) #NEWLINE# with self . env . db_transaction as db : #NEWLINE# #INDENT# old = db ( 'SELECT text FROM wiki WHERE name=%s\n                        ORDER BY version DESC LIMIT 1\n                        ' , ( title , ) ) #NEWLINE# if ( old and ( title in create_only ) ) : #NEWLINE# #INDENT# printout ( _ ( '  %(title)s already exists' , title = title ) ) #NEWLINE# return False #NEWLINE# #UNINDENT# if ( old and ( data == old [ 0 ] [ 0 ] ) ) : #NEWLINE# #INDENT# printout ( _ ( '  %(title)s is already up to date' , title = title ) ) #NEWLINE# return False #NEWLINE# #UNINDENT# if ( replace and old ) : #NEWLINE# #INDENT# db ( 'UPDATE wiki SET text=%s\n                      WHERE name=%s\n                        AND version=(SELECT max(version) FROM wiki\n                                     WHERE name=%s)\n                      ' , ( data , title , title ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# db ( "INSERT INTO wiki(version, name, time, author, ipnr, text)\n                      SELECT 1 + COALESCE(max(version), 0), %s, %s, 'trac',\n                             '127.0.0.1', %s FROM wiki WHERE name=%s\n                      " , ( title , to_utimestamp ( datetime_now ( utc ) ) , data , title ) ) #NEWLINE# #UNINDENT# if ( not old ) : #NEWLINE# #INDENT# del WikiSystem ( self . env ) . pages #NEWLINE# #UNINDENT# #UNINDENT# return True