Re: [web2py] Re: Method to interactively experiment with web2py

2012-02-26 Thread Phyo Arkar
web2py shell no longer works with latest ipython 0.11 +

On 2/20/12, Massimo Di Pierro  wrote:
> What you use
>
> python web2py.py -S app -M -N
>
> make sure to db.commit() your changes.
>
> On Feb 19, 5:45 pm, davidkw  wrote:
>> I'm wondering if there's some kind of way to use a shell or other IDE
>> to quickly run lines of web2py code and see the result.
>>
>> For example, just entering db(query).select().first() and being able
>> to see the result.
>>
>> I'm learning right now, and it's a little difficult to pick up the
>> syntax without being able to play around. Any advice?
>>
>> Thanks.


[web2py] oauth 2.0 and facebook "expires" parameter

2012-02-26 Thread Can Candan
It appears facebook does not return the 'expires' parameter for web
page sign on, however the code in
oauth20_account.py does not take into account this case. Should it
handle that or am I missing something?


[web2py] Introducing myself

2012-02-26 Thread Luciano Pacheco
Hi all,

I joined the group yesterday.

I've started a small project and in my point of view web2py fits perfectly
in this case.

The client want:

Port a player management to Linux.

A player that handles music and  database update through FTP downloads,
handles the playlist based in programs/schedules sent and stored in
database.

Management interface to handle some configurations (like FTP servers,
schedule updates and others).

Handle backups (data and application).

And the first feature that made me chose web2py, easy deployment.

As the application doesn't have to handle a lot of users, the Rocket server
is more than enough to handle threads to communicate with background
player, ftp and management interface.

I'm very happy to have found a built-in cron on web2py so I can focus in
other features instead of build my own scheduler. :-)

Also the new scheduler seems useful for the FTP update task.

For keep the player working I start a thread (on demand) and it has worked
well, I'll send a specific mail to show the idea and get some feedback.

So far, I found the documentation in web2py community not so well organized
and but this list (and web2py-dev) seem to be very worth, as far as I
navigated in the archives.

I've been working with Django and before I worked with Plone. I started to
play with Python occasionally in 2005 and since 2008 I've been working only
with it. :-)

I looking forward to help the community. :-)

Regards,
-- 
Luciano Pacheco
blog.lucmult.com.br


Re: [web2py] Re: Method to interactively experiment with web2py

2012-02-26 Thread Luciano Pacheco
Hi Phyo,

I'm using web2py and ipython 0.12 normally.

$ ./web2py.py -S instore
web2py Web Framework
Created by Massimo Di Pierro, Copyright 2007-2011
Version 1.99.4 (2011-12-14 14:46:14) stable
Database drivers available: SQLite3, pymysql
Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34)
Type "copyright", "credits" or "license" for more information.

IPython 0.12 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help  -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]:

What's the error you're getting ?

[],
-- 
Luciano Pacheco
blog.lucmult.com.br

On Sun, Feb 26, 2012 at 7:56 PM, Phyo Arkar wrote:

> web2py shell no longer works with latest ipython 0.11 +
>
> On 2/20/12, Massimo Di Pierro  wrote:
> > What you use
> >
> > python web2py.py -S app -M -N
> >
> > make sure to db.commit() your changes.
> >
> > On Feb 19, 5:45 pm, davidkw  wrote:
> >> I'm wondering if there's some kind of way to use a shell or other IDE
> >> to quickly run lines of web2py code and see the result.
> >>
> >> For example, just entering db(query).select().first() and being able
> >> to see the result.
> >>
> >> I'm learning right now, and it's a little difficult to pick up the
> >> syntax without being able to play around. Any advice?
> >>
> >> Thanks.
>


[web2py] Running a player in background - Thread

2012-02-26 Thread Luciano Pacheco
Hi all,

I have to control/manage/automatize a player (music) and I managed to do in
the following way.

I posting here to get feedback and also I liked the solution, so it can be
useful for others. ;-)

Firstly, I chose the mplayer as the player because of multi-platform and
multi-filetypes support. Also, it supports control commands in the stdin. I
have done the same technique using mpg123 as well.

The idea:

Run a class (subclass of threading.Thread) that its main loop stay polling
other process (mplyer or mpg123) and sends commands to them, also getting
data as current music, time elapsed and total time.

Keep in mind that it is my first time playing/coding with threads :-)

Ok! Show me the code!

http://pastebin.com/9nhf6FK0
The same below (who knows how long last a web service) :-)

# file: player.py

import threading
from subprocess import Popen, PIPE
from datetime import datetime



class MPG123Player(threading.Thread):
daemon = True # added to make Ctrl-C and Ctrl-D work when running
python -i player.py

def __init__(self, music=''):
self.music = music
threading.Thread.__init__(self)
self._kill_me = False
self.player = self.init_player()

def finish_it(self):
self._kill_me = True

def init_player(self):
return Popen(['mpg123', '--remote', self.music], shell=False,
stdout=PIPE, stdin=PIPE)

def run(self):
'''Thread method that is called when a Thread is started,
this is the "main loop" of it'''
try:
self.player_loop()
finally:
self.quit()

def play(self, music=''):
music = music or self.music
if music:
cmd = 'LOAD ' + music
self.player_cmd(cmd)

def stop(self):
self.player_cmd('STOP')

def player_cmd(self, cmd):
'''Protocol to talk to the mpg123 '''
self.player.stdin.write(cmd + '\n')

def quit(self):
self.player.terminate()

def player_loop(self):
player = self.player

self.play()

while not self._kill_me:
status = player.stdout.readline()
'''here we have to keep reading the stdout, because if we don't
read from it this buffer get full and the mpg123 stops working.

I give from it because of this issue, mplayer.py has a better
approach
'''
#print status
if status.startswith('@F'):
cmd_name, cur_frame,  frames_left, cur_seconds,
seconds_left = status.split()
if cmd_name == '@F' and cur_seconds == '0.00':
self.total_seconds = float(seconds_left)
cur_seconds = float(cur_seconds)
self.cur_seconds = cur_seconds


class Mplayer(threading.Thread, BasePlayer):
daemon = True # added to make Ctrl-C and Ctrl-D work when running
python -i player.py

def __init__(self, music=''):
threading.Thread.__init__(self)

def init_player(self):
# it is using mplayer.py - https://github.com/baudm/mplayer.py
return mplayer.Player(stderr=subprocess.PIPE)
# but the basic idea is run the mplayer with this options, but
# mplayer.py has some convenient api
#
#return Popen(['mplayer', '-slave', '-idle', #'-msglevel',
'global=4',
#'-quiet', 'nodefault-bindings', '-noconfig', 'all',
#self.music], shell=False, stdout=PIPE, stdin=PIPE,
#stderr=subprocess.STDOUT)

def run(self):
try:
self.player_loop()
finally:
self.quit()

def play(self, music=''):
music = music or self.music
if music:
cmd = self.player.loadfile(music)
def stop(self):
self.player.stop()

def quit(self):
self.player.quit()
#self.player.terminate()

def player_loop(self):
player = self.player

while not self._kill_me:
self.total_seconds = player.length or 0.0
self.cur_seconds = player.time_pos or 0.0

if (self.total_seconds - self.cur_seconds) <= 0.05:
# if it's about to finish the music dispatch the logic to
get
# the next music
print '[%s] ended:' % datetime.now(), player.filename


player = Mplayer('/path/to/a/file/199.mp3')
#player = MPG123Player('199.mp3')

player.start()


# you can play with the player using python console
# python -i player.py
# >>> player.play('file')
# >>> player.stop()
# I put this file in my application/myapp/modules/player.py
# and in my controllers I can from player import player
# def index()
# return '%s of %s' % (player.cur_seconds, player.total_seconds)

[],

-- 
Luciano Pacheco
blog.lucmult.com.br


[web2py] Re: Obtaining URL to image blob in GAE

2012-02-26 Thread Anthony
On Sunday, February 26, 2012 12:19:17 AM UTC-5, Peter G. wrote:
>
> How would one obtain the URL to a image blob stored on GAE's 
> datastore? A lot of the threads I've looked at were all for generating 
> an download output for views, but I need this for the Controller since 
> I'm returning this as a JSON element. 
>
> For example, the auth_user table has a field 'avatar' and another blob 
> field 'avatar_blob'. Ideally I can simply return a JSON like: 
> { "avatar": "http:avatars/username_avatar.gif" } 
>
> Where username_avatar.gif would map to the stored blob image for that 
> user's avatar.


Assuming you use web2py's standard "upload" field type to upload the 
images, then you would still use the standard download process as well. See 
the "Uploading files in database" section 
in http://web2py.com/books/default/chapter/29/13 for details on setting up 
database storage of uploads. And for downloading, see the 
response.downloaddescription here: 
http://web2py.com/books/default/chapter/29/4#response. In 
your case, it would be something like:

db.define_table('auth_user',
...,
Field('avatar', 'upload', uploadfield='avatar_blob'),
Field('avatar_blob', 'blob'), ...)

def download():
return response.download(request, db)

URL for a particular user's avatar:

URL('default', 'download', args=auth.user.avatar)

Anthony



[web2py] Re: Introducing myself

2012-02-26 Thread whowhywhat
Hi Luciano,
You said that right, web2py has a great community :) .. welcome
aboard. I'm sure you will find web2py a superb web development
framework.
I have been using web2py casually for the last one year or so, and on
a serious basis for the last 2 months.
If you are happy about the inbuilt cron i think you will be overjoyed
when you check out the in built scheduler :D
take a look at:
http://web2py.com/books/default/chapter/29/4?search=scheduler#Scheduler-(experimental)
http://web2py.com/books/default/chapter/29/8?search=scheduler

and watch this video:
http://vimeo.com/27478796

I Personally think the web2py documentation (the book) is a great
resource. A new CookBook is being published by PacktPub
And as you rightly pointed out, the google group is one of web2py's
biggest strengths.



On Feb 26, 3:29 pm, Luciano Pacheco  wrote:
> Hi all,
>
> I joined the group yesterday.
>
> I've started a small project and in my point of view web2py fits perfectly
> in this case.
>
> The client want:
>
> Port a player management to Linux.
>
> A player that handles music and  database update through FTP downloads,
> handles the playlist based in programs/schedules sent and stored in
> database.
>
> Management interface to handle some configurations (like FTP servers,
> schedule updates and others).
>
> Handle backups (data and application).
>
> And the first feature that made me chose web2py, easy deployment.
>
> As the application doesn't have to handle a lot of users, the Rocket server
> is more than enough to handle threads to communicate with background
> player, ftp and management interface.
>
> I'm very happy to have found a built-in cron on web2py so I can focus in
> other features instead of build my own scheduler. :-)
>
> Also the new scheduler seems useful for the FTP update task.
>
> For keep the player working I start a thread (on demand) and it has worked
> well, I'll send a specific mail to show the idea and get some feedback.
>
> So far, I found the documentation in web2py community not so well organized
> and but this list (and web2py-dev) seem to be very worth, as far as I
> navigated in the archives.
>
> I've been working with Django and before I worked with Plone. I started to
> play with Python occasionally in 2005 and since 2008 I've been working only
> with it. :-)
>
> I looking forward to help the community. :-)
>
> Regards,
> --
> Luciano Pacheco
> blog.lucmult.com.br


[web2py] How do you define a column name on summed field (i.e. how to do the equivalent of an sql 'select ..... as colname'

2012-02-26 Thread Paul
In the dal I'm selecting two summed fields and adding them together,
the column name in the set object ends up being called
'(SUM(t_appointment.miles_to) + SUM(t_appointment.miles_from))', how
would I define the dal query to get an better column name (e.g.
total_miles) ?

Current query is:


def mileage():
mysum = db.t_appointment.miles_to.sum()
+db.t_appointment.miles_from.sum()
groupmm = db.t_appointment.f_start_time.year()|
db.t_appointment.f_start_time.month()
rows = db().select(
mysum,
db.t_appointment.f_start_time.year(),
db.t_appointment.f_start_time.month(),
groupby=groupmm)

return dict(rows=rows, sql = db._lastsql)


Thanks,

Paul



[web2py] cron setup

2012-02-26 Thread Sanjeet Kumar
Can anyone give me the brief description to how I set the cron to run the 
task in background with example.


[web2py] Re: How do you define a column name on summed field (i.e. how to do the equivalent of an sql 'select ..... as colname'

2012-02-26 Thread Anthony
I'm not sure you can do that. In order to access the mysum column in the 
result, you would do:

row[mysum]

Anthony

On Sunday, February 26, 2012 11:05:59 AM UTC-5, Paul wrote:
>
> In the dal I'm selecting two summed fields and adding them together, 
> the column name in the set object ends up being called 
> '(SUM(t_appointment.miles_to) + SUM(t_appointment.miles_from))', how 
> would I define the dal query to get an better column name (e.g. 
> total_miles) ? 
>
> Current query is: 
>
>
> def mileage(): 
> mysum = db.t_appointment.miles_to.sum() 
> +db.t_appointment.miles_from.sum() 
> groupmm = db.t_appointment.f_start_time.year()| 
> db.t_appointment.f_start_time.month() 
> rows = db().select( 
> mysum, 
> db.t_appointment.f_start_time.year(), 
> db.t_appointment.f_start_time.month(), 
> groupby=groupmm) 
>
> return dict(rows=rows, sql = db._lastsql) 
>
>
> Thanks, 
>
> Paul 
>
>

[web2py] Web2py and SSLH

2012-02-26 Thread Doug Elkin
I'm thinking about setting up SSLH on my personal server.

>From http://freecode.com/projects/sslh:


> sslh accepts HTTPS, SSH, OpenVPN, tinc, and XMPP connections on the
> same port. This makes it possible to connect to any of these servers
> on port 443 (e.g., from inside a corporate firewall, which almost
> never blocks port 443) while still serving HTTPS on that port.

In short summary (and to my limited understanding), SSLH works by
forwarding the connection from the sslh daemon to either the ssh server
or the web-server (among other options). This means all SSL connections
will ultimately appear to be connecting to apache/web2py via 127.0.0.1.

Are there any security concerns with this? Should I disable admin and
appadmin completely?

How are session cookies affected?

Would any other functionality be affected?


[web2py] Re: Why does this not work for mysql?

2012-02-26 Thread simon
Thanks that is helpful. The postgres script looks like it will work
for mysql.

Would be nice if this could be incorporated into web2py so you can use
auto_import to look at non-web2py databases from existing systems.

On Feb 25, 9:59 pm, Anthony  wrote:
> > db1 = DAL('sqlite://storage.sqlite', folder='c:/web2py/applications/
> > crm/databases', auto_import=True)
> > db2 = DAL('mysql://root@localhost/opencart', auto_import=True)
> > print(db1.tables)
> > print(db2.tables)
> > a=db2.executesql("show tables")
> > print(a)
>
> > This lists the tables for sqlite database; and lists the tables for
> > mysql with the "show tables" command. However it shows an empty list
> > for the mysql db.tables.
>
> auto_import works by reading the *.table files in the /databases folder of
> the web2py app that defines the models for the database in question. Has
> the MySQL database been accessed by another web2py app that explicitly
> defined models for it? If not, auto_import won't provide any information
> about what's in the database. auto_import does not inspect the database
> itself -- it is simply a way to allow one app to access the database of
> another app without having to repeat the original app's model definitions.
>
> If the MySQL database is a legacy database and you want to automatically
> build models for it by directly inspecting the database, you can try this
> script:http://code.google.com/p/web2py/source/browse/scripts/extract_mysql_m
> There's also a newer (and I think more comprehensive) script originally
> designed to read Postgres db's, but will probably work for MySQL with
> minimal tweaking (see the
> docstring):http://code.google.com/p/web2py/source/browse/scripts/extract_pgsql_m
>
> Anthony


[web2py] Access to app variables in modules

2012-02-26 Thread Ed Greenberg
I create lots of modules which need to interact with my app.   I've
been passing things into them and wonder if I'm doing the simplest and
best practice:


aObj=local_import("a",reload=True)

a=aObj(db,auth,settings,session,module_specific_params)

Then, in the class, I use them as self.settings.foo (or whatever)

Is there a good way to make more of the environment available to my
module, or am I doing the right thing?

Thanks,

Ed


Re: [web2py] Access to app variables in modules

2012-02-26 Thread Vinicius Assef
See what documentation says about "current".

It makes session, request, response, etc. available to your module.

--
Vinicius Assef



On Sun, Feb 26, 2012 at 4:11 PM, Ed Greenberg  wrote:
> I create lots of modules which need to interact with my app.   I've
> been passing things into them and wonder if I'm doing the simplest and
> best practice:
>
>
> aObj=local_import("a",reload=True)
>
> a=aObj(db,auth,settings,session,module_specific_params)
>
> Then, in the class, I use them as self.settings.foo (or whatever)
>
> Is there a good way to make more of the environment available to my
> module, or am I doing the right thing?
>
> Thanks,
>
> Ed


Re: [web2py] Access to app variables in modules

2012-02-26 Thread Bruno Rocha
On Sun, Feb 26, 2012 at 4:11 PM, Ed Greenberg wrote:

> aObj=local_import("a",reload=True)
>

local_import is now deprecated.

Use newest web2py version and you can use the new importer with the syntax.

*from a import aOb*j or just* import a
*
inside the module you can do

from gluon import current and access current. for
(session|request|response|cache|T)


-- 

Bruno Rocha
[http://rochacbruno.com.br]


[web2py] Re: Why does this not work for mysql?

2012-02-26 Thread simon
Actually I just discovered previous post which suggests exactly this
addition and which has some code attached and Massimo says he will
review. However I could not find it in web2py. Is it there somewhere?

Previous post is here:
http://groups.google.com/group/web2py/browse_thread/thread/c347e86a6644432a

On Feb 26, 6:44 pm, simon  wrote:
> Thanks that is helpful. The postgres script looks like it will work
> for mysql.
>
> Would be nice if this could be incorporated into web2py so you can use
> auto_import to look at non-web2py databases from existing systems.
>
> On Feb 25, 9:59 pm, Anthony  wrote:
>
>
>
>
>
>
>
> > > db1 = DAL('sqlite://storage.sqlite', folder='c:/web2py/applications/
> > > crm/databases', auto_import=True)
> > > db2 = DAL('mysql://root@localhost/opencart', auto_import=True)
> > > print(db1.tables)
> > > print(db2.tables)
> > > a=db2.executesql("show tables")
> > > print(a)
>
> > > This lists the tables for sqlite database; and lists the tables for
> > > mysql with the "show tables" command. However it shows an empty list
> > > for the mysql db.tables.
>
> > auto_import works by reading the *.table files in the /databases folder of
> > the web2py app that defines the models for the database in question. Has
> > the MySQL database been accessed by another web2py app that explicitly
> > defined models for it? If not, auto_import won't provide any information
> > about what's in the database. auto_import does not inspect the database
> > itself -- it is simply a way to allow one app to access the database of
> > another app without having to repeat the original app's model definitions.
>
> > If the MySQL database is a legacy database and you want to automatically
> > build models for it by directly inspecting the database, you can try this
> > script:http://code.google.com/p/web2py/source/browse/scripts/extract_mysql_m
> > There's also a newer (and I think more comprehensive) script originally
> > designed to read Postgres db's, but will probably work for MySQL with
> > minimal tweaking (see the
> > docstring):http://code.google.com/p/web2py/source/browse/scripts/extract_pgsql_m
>
> > Anthony


[web2py] Re: How do you define a column name on summed field (i.e. how to do the equivalent of an sql 'select ..... as colname'

2012-02-26 Thread Alan Etkin
I know you want to modify the query, but you could replace the string
when the rows are passed to a helper instance.

On 26 feb, 13:05, Paul  wrote:
> In the dal I'm selecting two summed fields and adding them together,
> the column name in the set object ends up being called
> '(SUM(t_appointment.miles_to) + SUM(t_appointment.miles_from))', how
> would I define the dal query to get an better column name (e.g.
> total_miles) ?
>
> Current query is:
>
> def mileage():
>     mysum = db.t_appointment.miles_to.sum()
> +db.t_appointment.miles_from.sum()
>     groupmm = db.t_appointment.f_start_time.year()|
> db.t_appointment.f_start_time.month()
>     rows = db().select(
>         mysum,
>         db.t_appointment.f_start_time.year(),
>         db.t_appointment.f_start_time.month(),
>     groupby=groupmm)
>
>     return dict(rows=rows, sql = db._lastsql)
>
> Thanks,
>
> Paul


[web2py] Re: cron setup

2012-02-26 Thread Alan Etkin
It's all in the book (if you haven't seen yet)

http://web2py.com/books/default/chapter/29/4#Cron

By the way, The link in web2py to cron (http://web2py.com/books/
default/reference/29/cron) is broken (returns an invalid function
message)

On 26 feb, 13:09, Sanjeet Kumar  wrote:
> Can anyone give me the brief description to how I set the cron to run the
> task in background with example.


[web2py] Re: Sporadic ImportError with custom module

2012-02-26 Thread Alan Etkin
I guess that there is code in the app that could be rendering the
module readable or not between requests. Why would web2py or the
operating system find the module randomly?

On 24 feb, 10:46, spiffytech  wrote:
> My web2py app is hosted on Apache with mod_wsgi. Sometimes I'm
> browsing through it and web2py encounters an error:
>
>     ImportError: No module named mobileblur.modules.newsblur
>
> Caused by this line in my models file:
>
>     nb_module = local_import("newsblur")
>
> This only happens occasionally, but on seemingly any page. Funny thing
> is, if I hit the browser's refresh button the page loads fine. And
> since nearly every page on the site requires that module, I know the
> import works most of the time.
>
> The permissions on the module are -rw-r--r--, apache:apache (the same
> user:group Apache is configured to use).
>
> The full source code can be found here[0], and I can provide
> additional information on the server if needed.
>
> What could be going wrong?
>
> [0]https://github.com/spiffytech/MobileBlur/tree/master/applications/mob...


Re: [web2py] Re: cron setup

2012-02-26 Thread Luciano Pacheco
I think Sanjeet means, I example of the task.

What is a good practice in the task, or what kind of variables are present
in the local namespace "automagically", etc. A task should be a class a
function, a python module?

I had the same question last week when I was reading this chapter. :-)

Regards,
-- 
Luciano Pacheco
blog.lucmult.com.br

On Mon, Feb 27, 2012 at 10:08 AM, Alan Etkin  wrote:

> It's all in the book (if you haven't seen yet)
>
> http://web2py.com/books/default/chapter/29/4#Cron
>
> By the way, The link in web2py to cron (http://web2py.com/books/
> default/reference/29/cron) is broken (returns an invalid function
> message)
>
> On 26 feb, 13:09, Sanjeet Kumar  wrote:
> > Can anyone give me the brief description to how I set the cron to run the
> > task in background with example.
>


Re: [web2py] Re: Sporadic ImportError with custom module

2012-02-26 Thread Luciano Pacheco
On Mon, Feb 27, 2012 at 10:22 AM, Alan Etkin  wrote:

> I guess that there is code in the app that could be rendering the
> module readable or not between requests. Why would web2py or the
> operating system find the module randomly?
>

Concurrency, race conditions and those things.

"spiffytech", how is your process/threads apache and wsgi conf?

"spiffytech", have you noticed if this errors happen when traffic is higher
or similar?


>
> On 24 feb, 10:46, spiffytech  wrote:
> > My web2py app is hosted on Apache with mod_wsgi. Sometimes I'm
> > browsing through it and web2py encounters an error:
> >
> > ImportError: No module named mobileblur.modules.newsblur
> >
> > Caused by this line in my models file:
> >
> > nb_module = local_import("newsblur")
> >
> > This only happens occasionally, but on seemingly any page. Funny thing
> > is, if I hit the browser's refresh button the page loads fine. And
> > since nearly every page on the site requires that module, I know the
> > import works most of the time.
> >
> > The permissions on the module are -rw-r--r--, apache:apache (the same
> > user:group Apache is configured to use).
> >
> > The full source code can be found here[0], and I can provide
> > additional information on the server if needed.
> >
> > What could be going wrong?
> >
> > [0]
> https://github.com/spiffytech/MobileBlur/tree/master/applications/mob...


[],
-- 
Luciano Pacheco
blog.lucmult.com.br


[web2py] Re: Running a player in background - Thread

2012-02-26 Thread Alan Etkin
Cool!. Don't know if there are tools like that for other environments,
but I think this could be used for controlling more sofisticated sound
playing systems than the standard desktop application like those used
for music events.

On 26 feb, 08:01, Luciano Pacheco  wrote:
> Hi all,
>
> I have to control/manage/automatize a player (music) and I managed to do in
> the following way.
>
> I posting here to get feedback and also I liked the solution, so it can be
> useful for others. ;-)
>
> Firstly, I chose the mplayer as the player because of multi-platform and
> multi-filetypes support. Also, it supports control commands in the stdin. I
> have done the same technique using mpg123 as well.
>
> The idea:
>
> Run a class (subclass of threading.Thread) that its main loop stay polling
> other process (mplyer or mpg123) and sends commands to them, also getting
> data as current music, time elapsed and total time.
>
> Keep in mind that it is my first time playing/coding with threads :-)
>
> Ok! Show me the code!
>
> http://pastebin.com/9nhf6FK0
> The same below (who knows how long last a web service) :-)
>
> # file: player.py
>
> import threading
> from subprocess import Popen, PIPE
> from datetime import datetime
>
> class MPG123Player(threading.Thread):
>     daemon = True # added to make Ctrl-C and Ctrl-D work when running
> python -i player.py
>
>     def __init__(self, music=''):
>         self.music = music
>         threading.Thread.__init__(self)
>         self._kill_me = False
>         self.player = self.init_player()
>
>     def finish_it(self):
>         self._kill_me = True
>
>     def init_player(self):
>         return Popen(['mpg123', '--remote', self.music], shell=False,
> stdout=PIPE, stdin=PIPE)
>
>     def run(self):
>         '''Thread method that is called when a Thread is started,
>         this is the "main loop" of it'''
>         try:
>             self.player_loop()
>         finally:
>             self.quit()
>
>     def play(self, music=''):
>         music = music or self.music
>         if music:
>             cmd = 'LOAD ' + music
>             self.player_cmd(cmd)
>
>     def stop(self):
>         self.player_cmd('STOP')
>
>     def player_cmd(self, cmd):
>         '''Protocol to talk to the mpg123 '''
>         self.player.stdin.write(cmd + '\n')
>
>     def quit(self):
>         self.player.terminate()
>
>     def player_loop(self):
>         player = self.player
>
>         self.play()
>
>         while not self._kill_me:
>             status = player.stdout.readline()
>             '''here we have to keep reading the stdout, because if we don't
>             read from it this buffer get full and the mpg123 stops working.
>
>             I give from it because of this issue, mplayer.py has a better
> approach
>             '''
>             #print status
>             if status.startswith('@F'):
>                 cmd_name, cur_frame,  frames_left, cur_seconds,
> seconds_left = status.split()
>                 if cmd_name == '@F' and cur_seconds == '0.00':
>                     self.total_seconds = float(seconds_left)
>                 cur_seconds = float(cur_seconds)
>                 self.cur_seconds = cur_seconds
>
> class Mplayer(threading.Thread, BasePlayer):
>     daemon = True # added to make Ctrl-C and Ctrl-D work when running
> python -i player.py
>
>     def __init__(self, music=''):
>         threading.Thread.__init__(self)
>
>     def init_player(self):
>         # it is using mplayer.py -https://github.com/baudm/mplayer.py
>         return mplayer.Player(stderr=subprocess.PIPE)
>         # but the basic idea is run the mplayer with this options, but
>         # mplayer.py has some convenient api
>         #
>         #return Popen(['mplayer', '-slave', '-idle', #'-msglevel',
> 'global=4',
>         #            '-quiet', 'nodefault-bindings', '-noconfig', 'all',
>         #            self.music], shell=False, stdout=PIPE, stdin=PIPE,
>         #            stderr=subprocess.STDOUT)
>
>     def run(self):
>         try:
>             self.player_loop()
>         finally:
>             self.quit()
>
>     def play(self, music=''):
>         music = music or self.music
>         if music:
>             cmd = self.player.loadfile(music)
>     def stop(self):
>         self.player.stop()
>
>     def quit(self):
>         self.player.quit()
>         #self.player.terminate()
>
>     def player_loop(self):
>         player = self.player
>
>         while not self._kill_me:
>             self.total_seconds = player.length or 0.0
>             self.cur_seconds = player.time_pos or 0.0
>
>             if (self.total_seconds - self.cur_seconds) <= 0.05:
>                 # if it's about to finish the music dispatch the logic to
> get
>                 # the next music
>                 print '[%s] ended:' % datetime.now(), player.filename
>
> player = Mplayer('/path/to/a/file/199.mp3')
> #player = MPG123Player('199.mp3')
>
> player.start()
>
> # you can play with the player usi

[web2py] In plugin_wiki meta-code tables i cannot upload data :(

2012-02-26 Thread smogzer
I'm trying to create a meta-database that can be defined via meta-code and
i've come to a bug : i can't upload data to fields in that database.
Could anybody fix the problem ? here is a sample code for testing.

http://127.0.0.1/apagar/plugin_wiki/page_edit/meta-code
code:
db.define_table('imagex',
Field('id','id',represent=lambda id:SPAN(id,'
',A('edit',_href=URL('page',args='edit',vars=dict(table='imagex',rec=id),
Field('name'),
Field('type'),
Field('picture', 'upload',requires=IS_IMAGE()),
format = '%(name)s')

for testing
http://127.0.0.1/apagar/plugin_wiki/page/edit?table=imagex&rec=1
code:
``
{{=plugin_wiki.widget('create',table='imagex')}}
``:template

``
{{=plugin_wiki.widget('read',table=str(request.vars.table),record_id=str(request.vars.rec))}}
``:template

``
{{=plugin_wiki.widget('update',table=str(request.vars.table),record_id=str(request.vars.rec))}}
``:template


[web2py] Re: cron setup

2012-02-26 Thread Anthony

>
> By the way, The link in web2py to cron (http://web2py.com/books/ 
> default/reference/29/cron) 
> is broken (returns an invalid function 
> message) 
>

Actually, there's a bug in the book app -- all the "reference" links are 
broken.


[web2py] Re: Access to app variables in modules

2012-02-26 Thread Anthony
See 
http://web2py.com/books/default/chapter/29/4#Accessing-the-API-from-Python-modules.
 
Note, "from gluon import *" imports the entire web2py API, including the 
"current" thread local object containing the environment variables.

Anthony

On Sunday, February 26, 2012 2:11:40 PM UTC-5, Ed Greenberg wrote:
>
> I create lots of modules which need to interact with my app.   I've 
> been passing things into them and wonder if I'm doing the simplest and 
> best practice: 
>
>
> aObj=local_import("a",reload=True) 
>
> a=aObj(db,auth,settings,session,module_specific_params) 
>
> Then, in the class, I use them as self.settings.foo (or whatever) 
>
> Is there a good way to make more of the environment available to my 
> module, or am I doing the right thing? 
>
> Thanks, 
>
> Ed



Re: [web2py] Re: cron setup

2012-02-26 Thread Sanjeet Kumar
Exactly I need the examples

On Mon, Feb 27, 2012 at 4:56 AM, Luciano Pacheco  wrote:

> I think Sanjeet means, I example of the task.
>
> What is a good practice in the task, or what kind of variables are present
> in the local namespace "automagically", etc. A task should be a class a
> function, a python module?
>
> I had the same question last week when I was reading this chapter. :-)
>
> Regards,
> --
> Luciano Pacheco
> blog.lucmult.com.br
>
> On Mon, Feb 27, 2012 at 10:08 AM, Alan Etkin  wrote:
>
>> It's all in the book (if you haven't seen yet)
>>
>> http://web2py.com/books/default/chapter/29/4#Cron
>>
>> By the way, The link in web2py to cron (http://web2py.com/books/
>> default/reference/29/cron)
>> is broken (returns an invalid function
>> message)
>>
>> On 26 feb, 13:09, Sanjeet Kumar  wrote:
>> > Can anyone give me the brief description to how I set the cron to run
>> the
>> > task in background with example.
>>
>
>
>
>


[web2py] Re: request.user_agent() dumping [closed]

2012-02-26 Thread weheh
Indeed. Fixed in latest stable web2py 1.99.4.

On Feb 22, 10:15 pm, Massimo Di Pierro 
wrote:
> I think this was fixed in a later version.
>
> On Feb 21, 9:52 pm, weheh  wrote:
>
>
>
>
>
>
>
> > I'm trying to detect the browser being used to access my web2py app.
> > The literature seems to recommend reading request.env.http_user_agent.
> > But the results are a little confusing, so I'm trying
> > request.user_agent(), which uses "gluon/contrib/
> > user_agent_parser.py" (as per the doc). This throws the following
> > ticket:
>
> > Traceback (most recent call last):
> >   File "N:\web2py\gluon\main.py", line 518, in wsgibase
> >     session._try_store_on_disk(request, response)
> >   File "N:\web2py\gluon\globals.py", line 528, in _try_store_on_disk
> >     cPickle.dump(dict(self), response.session_file)
> > PicklingError: Can't pickle : it's not the
> > same object as storage.Storage
>
> > I'm on web2py v1.99.2
>
> > Thanks.


[web2py] Re: request.user_agent() dumping

2012-02-26 Thread weheh
And, I might add, this is simply awesome. It would also be very cool
if it could give me the dimensions of the browser window. I know I can
get it via jQuery, but it would save a step.

On Feb 22, 10:15 pm, Massimo Di Pierro 
wrote:
> I think this was fixed in a later version.
>
> On Feb 21, 9:52 pm, weheh  wrote:
>
>
>
>
>
>
>
> > I'm trying to detect the browser being used to access my web2py app.
> > The literature seems to recommend reading request.env.http_user_agent.
> > But the results are a little confusing, so I'm trying
> > request.user_agent(), which uses "gluon/contrib/
> > user_agent_parser.py" (as per the doc). This throws the following
> > ticket:
>
> > Traceback (most recent call last):
> >   File "N:\web2py\gluon\main.py", line 518, in wsgibase
> >     session._try_store_on_disk(request, response)
> >   File "N:\web2py\gluon\globals.py", line 528, in _try_store_on_disk
> >     cPickle.dump(dict(self), response.session_file)
> > PicklingError: Can't pickle : it's not the
> > same object as storage.Storage
>
> > I'm on web2py v1.99.2
>
> > Thanks.


[web2py] Re: How do you define a column name on summed field (i.e. how to do the equivalent of an sql 'select ..... as colname'

2012-02-26 Thread Paul
Thanks Anthony,

That syntax works and I can use that to refer to the data, I could see
that a row object had an '_extra' dict for the selected expressions
but could not see that the data could be referred to be the name of
the expression 'mysum' (its in there somewhere but not sure where!!)

On Feb 26, 4:40 pm, Anthony  wrote:
> I'm not sure you can do that. In order to access the mysum column in the
> result, you would do:
>
> row[mysum]
>
> Anthony
>
>
>
>
>
>
>
> On Sunday, February 26, 2012 11:05:59 AM UTC-5, Paul wrote:
>
> > In the dal I'm selecting two summed fields and adding them together,
> > the column name in the set object ends up being called
> > '(SUM(t_appointment.miles_to) + SUM(t_appointment.miles_from))', how
> > would I define the dal query to get an better column name (e.g.
> > total_miles) ?
>
> > Current query is:
>
> > def mileage():
> >     mysum = db.t_appointment.miles_to.sum()
> > +db.t_appointment.miles_from.sum()
> >     groupmm = db.t_appointment.f_start_time.year()|
> > db.t_appointment.f_start_time.month()
> >     rows = db().select(
> >         mysum,
> >         db.t_appointment.f_start_time.year(),
> >         db.t_appointment.f_start_time.month(),
> >     groupby=groupmm)
>
> >     return dict(rows=rows, sql = db._lastsql)
>
> > Thanks,
>
> > Paul