From 581bc085164b42f72a2535dc2f161899e819a0dc Mon Sep 17 00:00:00 2001 From: ftyers Date: Wed, 21 Nov 2007 12:32:49 +0000 Subject: [PATCH] Changing functionality and updating readme git-svn-id: https://apertium.svn.sourceforge.net/svnroot/apertium@2543 72bbbca6-d526-0410-a7d9-f06f51895060 --- apertium-forms-server/README | 31 +++++++++++++++++++---- apertium-forms-server/apertium-forms-server.py | 20 +++++++++++++++ apertium-forms-server/interface.py | 10 ++++---- apertium-forms-server/pair.py | 34 ++++++++++++++------------ 4 files changed, 70 insertions(+), 25 deletions(-) diff --git a/apertium-forms-server/README b/apertium-forms-server/README index 122c905f..77e2789c 100644 --- a/apertium-forms-server/README +++ b/apertium-forms-server/README @@ -1,10 +1,31 @@ apertium-forms-server +====================================================== You need: -* python >= 2.4 -* python-webpy -* python-4suite-xml +* python (>= 2.4) +* python-4suite-xml (>= 1.0.2) +* python-webpy (= 0.22) + +On debian you can get them by apt-get installing those +package names. I'm fairly sure the first two won't change +much and break anything, but for python-webpy, as it is +quite alpha, I'm only guarantee'ing with this version. + +Running it: + +Set up the config file in config/config.xml, then run: + + $ python apertium-forms-server.py + +then navigate to: + + http://localhost:8080 + +You can keep adding entries, when you want to save the +entries to the files, navigate to: + + http://localhost:8080/commit/ Known bugs: @@ -43,8 +64,8 @@ webpy to show them Coding style: I like braces, they make blocks easier to distinguish. I -use them in python even thought often it makes coding -difficult. For example, I try to avoid using if/elseif/else +use them in python even though it often it makes coding +difficult. For example, I try to avoid using if/elif/else blocks, because python does not provide a way to use my preferred coding style: diff --git a/apertium-forms-server/apertium-forms-server.py b/apertium-forms-server/apertium-forms-server.py index 84bbab72..1d5888f9 100644 --- a/apertium-forms-server/apertium-forms-server.py +++ b/apertium-forms-server/apertium-forms-server.py @@ -19,9 +19,29 @@ i = Interface(); urls = ( '/add', 'add', + '/commit/(.*)', 'commit', '/(.*)', 'form' ) +class commit: #{ + + def GET(self, name): #{ + print >> sys.stderr , 'Commit called for ' + name; + pairs = Globals.config.get_pairs(); + if name in pairs: #{ + print ''; + print 'Commit called for ' + name + '
'; + pair = pairs[name]; + print 'Comitting...
'; + pair.commit(); + print 'Committed.'; + return; + #} + + print 'Error in commit.'; + #} +#} + class form: #{ def GET(self, name): #{ diff --git a/apertium-forms-server/interface.py b/apertium-forms-server/interface.py index 782e0e2a..c9d9653b 100644 --- a/apertium-forms-server/interface.py +++ b/apertium-forms-server/interface.py @@ -33,11 +33,9 @@ class Interface: #{ selected_pair = post_data['selected_pair']; pairs = post_data['pairs']; - post_data['left_dictionary'].commit(left_entrada); - post_data['bidix_dictionary'].commit(bidix_entrada); - post_data['right_dictionary'].commit(right_entrada); - -# pairs[selected_pair].commit(left_entrada, bidix_entrada, right_entrada); + post_data['left_dictionary'].append(left_entrada); + post_data['bidix_dictionary'].append(bidix_entrada); + post_data['right_dictionary'].append(right_entrada); print 'again!'; @@ -262,6 +260,8 @@ class Interface: #{ print ''; print ''; print ''; + + return ''; #} def show_preview(self, post_data, _side): # diff --git a/apertium-forms-server/pair.py b/apertium-forms-server/pair.py index bad1930d..2dbba169 100644 --- a/apertium-forms-server/pair.py +++ b/apertium-forms-server/pair.py @@ -278,7 +278,7 @@ class Dictionary: #{ entrada = entrada + '

' + "\n"; entrada = entrada + '' + "\n"; - if _comment != "": #{ + if _comment != '': #{ entrada = entrada + '' + "\n"; #} @@ -302,29 +302,32 @@ class Dictionary: #{ return r.encode('utf-8'); #} - def commit(self, _entrada): #{ + def append(self, _entrada): #{ print >> sys.stderr, '> ' , self.file; - print >> sys.stderr, self.side + ' commit('; + print >> sys.stderr, self.side + ' append('; print >> sys.stderr, _entrada; print >> sys.stderr, ')'; for section in self.doc.xpath('.//section'): #{ print >> sys.stderr , '+ section : ' + section.getAttributeNS(None, 'id'); if section.getAttributeNS(None, 'id') == 'main': #{ - print >> sys.stderr , 'Writing to file....'; + print >> sys.stderr , 'Appending to section....'; insertion_point = section; child_doc = NonvalidatingReader.parseString(_entrada.encode('utf-8'), 'urn:bogus:dummy'); child_node = child_doc.xpath('.//e')[0]; insertion_point.appendChild(child_node); - - f = open(self.file, 'w'); - Print(self.doc, stream=f); - f.close(); - print >> sys.stderr, 'Written.'; + print >> sys.stderr , 'Appended.'; #} #} + #} + + def commit(self): #{ + print >> sys.stderr, 'Writing out DOM to ' + self.file; + f = open(self.file, 'w'); + Print(self.doc, stream=f); + f.close(); + print >> sys.stderr, 'Written.'; - print >> sys.stderr, 'Failed :('; #} #} @@ -372,10 +375,11 @@ class Pair: #{ return self.tags; #} - def commit(self, _left, _bidix, _right): #{ - print >> sys.stderr , 'commit()'; - self.dictionary['left'].commit(_left); - self.dictionary['bidix'].commit(_bidix); - self.dictionary['right'].commit(_right); + def commit(self): #{ + print >> sys.stderr , self.name + ' commit()'; + + self.dictionary['left'].commit(); + self.dictionary['bidix'].commit(); + self.dictionary['right'].commit(); #} #} -- 2.11.4.GIT