@Dragonfyre
>have something in the
>controller display realtime like the print command, instead of display
>all of the information at once)

You got it!
I need a solution to run standard Python scripts and render the output
in my browser. with less effort.
+a solution to update the Progressbar from my functions (1. donload
text file in %, 2. import text file line by line to the DB in %) to
show the Progress in browser window.

Best regards,

Dieter Asman

- AsmanCom -
Germany

On 24 Feb., 23:01, Dragonfyre13 <dragonfyr...@gmail.com> wrote:
> So, let me make sure I understand this right, you want to stream the
> response, from the server, to the browser. (have something in the
> controller display realtime like the print command, instead of display
> all of the information at once)
>
> Or, are you talking about actually using print, and having it output
> to the page? For that I redirect stdout to a stringIO var, and then
> simply read the variable out to the view.
>
> On Feb 24, 11:33 am, AsmanCom <d.as...@web.de> wrote:
>
> > Hi Tiango,
>
> > no i need an equivalent for print, like:
>
> > def print_1():
> >     print "1"
> >     print "2"
> > =
> > 1
> > 2
>
> > def print_2():
> >     while True:
> >         print "1"
> > =
> > 1
> > 1
> > 1
> > 1
> > ...
>
> > I need to execute scripts like in terminal, but output rendered in
> > html. (should be very simple?)
>
> > Best regards,
>
> > Dieter Asman
>
> > - AsmanCom -
> > Germany
>
> > On 24 Feb., 18:17, Tiago Almeida <tiago.b.alme...@gmail.com> wrote:
>
> > > > for quick development-shots, i need to execute my untouched(may i
> > > > could change "print" to "return") Python scripts(..with loops) in the
> > > > Controller.
> > > > The output should be renderd direct via http, without long-winded
> > > > setting up the view for each function.
> > > > Is that possible?
>
> > > If I understand you want to return a string directly without being 
> > > processed
> > > by the view.
> > > On a controller function, if you return a string (not a dict) it will be
> > > rendered as is.
>
> > > Tiago
> > > --
>
> > > On Wed, Feb 24, 2010 at 4:48 PM, AsmanCom <d.as...@web.de> wrote:
> > > > Hi,
>
> > > > for quick development-shots, i need to execute my untouched(may i
> > > > could change "print" to "return") Python scripts(..with loops) in the
> > > > Controller.
> > > > The output should be renderd direct via http, without long-winded
> > > > setting up the view for each function.
> > > > Is that possible?
>
> > > > To my next concern....
>
> > > > On my actual Project i have simple form field with submit button on my
> > > > controller:
> > > > form = SQLFORM.factory(Field('update_url', default='http://.domain.org/
> > > > text_file.txt <http://domain.org/%0Atext_file.txt>',
> > > > requires=IS_NOT_EMPTY()))
>
> > > > On Submit the text file should be downloaded to Server indicated by an
> > > > Progress Bar on the Page.
> > > > Next the file should be inserted to the DB line by line(for loop with
> > > > regex) and again indicated by the same Progress Bar .....
>
> > > > My Code so far(... relies on clienttools example specifically on
> > > > jqueryUI-progressbar and an urllib2 +report_hook snippet i´ve found
> > > > somewhere):
> > > > _______________________________________________________________________
> > > > def chunk_report(bytes_so_far, chunk_size, total_size):
> > > >    percent = float(bytes_so_far) / total_size
> > > >    percent = round(percent*100)
> > > >    return percent
>
> > > >    if bytes_so_far >= total_size:
> > > >        return ('100.0')
>
> > > > def chunk_read(response, chunk_size=8192, report_hook=None):
> > > >    total_size = response.info().getheader('Content-Length').strip()
> > > >    total_size = int(total_size)
> > > >    bytes_so_far = 0
>
> > > >    while 1:
> > > >        chunk = response.read(chunk_size)
> > > >        bytes_so_far += len(chunk)
>
> > > >        if not chunk:
> > > >            break
>
> > > >        if report_hook:
> > > >            report_hook(bytes_so_far, chunk_size, total_size)
>
> > > >    percent = float(bytes_so_far) / total_size
> > > >    percent = round(percent*100)
> > > >    return percent #bytes_so_far
>
> > > > def url_progress():
> > > >    wrapper = DIV(progress,_style="width:400px;")
> > > >    jqueryui_progress()
> > > >    form = SQLFORM.factory(Field('update_url',
> > > > default='http://.domain.org/text_file.txt', requires=IS_NOT_EMPTY()))
> > > >    if form.accepts(request.vars, session):
> > > >        response.flash = "Got it!"
> > > >        try:
> > > >            import urllib2
> > > >            openurl = urllib2.urlopen(request.vars.update_url)
> > > >            chunk_read(openurl, report_hook=chunk_report)
> > > >        except Exception, e:
> > > >            session.flash = DIV(T('Unable to download from url
> > > > because:'),PRE(str(e)))
> > > >            redirect(URL(r=request))
> > > >    event.listen('submit',"form","return confirm('Are you sure?');") #
> > > > adds a confirmation to submit
> > > >    page.ready(jq("update_oui").focus()())
> > > > #    return dict(form=form)
> > > >    return dict(wrapper=wrapper, form=form)
>
> > > > # jQuery progress bar
> > > > progress = DIV(_id="progress")
> > > > def jqueryui_progress():
> > > >    wrapper = DIV(progress,_style="width:400px;")
> > > >    page.include("http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/
> > > > jquery-ui.min.js<http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/%0Ajquery-ui.min.js>",
> > > > download=True)
> > > >    page.include("http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/
> > > > themes/ui-darkness/jquery-ui.css<http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/%0Athemes/ui-dark...>",
> > > > download=True)
> > > >    callback = js.call_function(get_progress)
> > > >    page.ready(jq(progress).progressbar( dict(value='0') )() )
> > > >    page.ready(js.timer(callback,2000))
> > > >    return dict(wrapper=wrapper)
>
> > > > def get_progress():
> > > >    return jq(progress).progressbar('option', 'value',
> > > > request.now.second)()#
> > > > ________________________________________________________________
>
> > > > But now i stuck.... can anyone put me on the right way?
> > > > When the Page is loaded,  both elemts show up correctly.
> > > > When i do the submit:
> > > > - The Progressbar freezes(Callback dont work while downloading the
> > > > file...)
> > > > - The Download works and shows 100% when completed(but the while 1
> > > > loop, which calls the report_hook dont work at all! and i need it to
> > > > update the Progress bar... I think?)
>
> > > > + I need to change the Progressbar callback source when updating DB
> > > > after downloading the file...
>
> > > > Anyone any suggestions?
>
> > > > Best regards,
>
> > > > Dieter Asman
>
> > > > - AsmanCom -
> > > > Germany
>
> > > > --
> > > > You received this message because you are subscribed to the Google 
> > > > Groups
> > > > "web2py-users" group.
> > > > To post to this group, send email to web...@googlegroups.com.
> > > > To unsubscribe from this group, send email to
> > > > web2py+unsubscr...@googlegroups.com<web2py%2bunsubscr...@googlegroups.com>
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/web2py?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.

Reply via email to