boxee :: forums  

Go Back   boxee :: forums > boxee developers > boxee applications

Reply
 
Thread Tools Display Modes
  #11  
Old March 30th, 2010, 02:22 PM
DPK DPK is offline
Super Moderator
 
Join Date: Feb 2009
Posts: 1,606
Default

It's important to note that Boxee has an internal python version of 2.4 and sqlite3 requires 2.5. So you can't just import and use it. Just fyi.
__________________
Common issues w/ Boxee:
Beta Important Info | FAQ & Support Requests | Hulu Mature Content | Search

UnBoxeed app development:
Comics.com | ESPN360 | Weather

For more info, follow app development on Twitter!
Reply With Quote
  #12  
Old April 1st, 2010, 08:48 PM
skierdb526
Guest
 
Posts: n/a
Default

So is it possible to use sqlite3 on it then? And if so how do you go about doing it?

Thanks
Reply With Quote
  #13  
Old January 30th, 2011, 05:29 AM
sutki72 sutki72 is offline
Junior Member
 
Join Date: Dec 2010
Posts: 2
Default

Quote:
Originally Posted by skierdb526 View Post
So is it possible dle модули to use sqlite3 on it then? And if so how do you go about doing it?порно

Thanks

I am also very interested in it? join issue
квартиры посуточно в тюмени

Last edited by sutki72; September 10th, 2011 at 08:24 PM.
Reply With Quote
  #14  
Old February 23rd, 2011, 06:55 AM
morii morii is offline
Junior Member
 
Join Date: Feb 2011
Posts: 6
Default

What about storing variables in module?
In my app I made a module and in __init__.py I defined some variables. Now i can access to these variables across different windows/event

Code:
space/:
__init__.py
cache = 0
To access to this variable I need to import this module and that's all.
Code:
import space
space.cache += 1
Reply With Quote
  #15  
Old March 14th, 2011, 01:24 PM
phikai phikai is offline
Senior Member
 
Join Date: Apr 2009
Posts: 382
Send a message via AIM to phikai
Default

Does anyone know if text files work on the Boxee Box for storage? Or what to do about sqlite3? Looking for a persistent storage solution...
__________________
~Kai
Website: http://kaiarmstrong.com
Twitter: @phikai
Boxee Development: Think One Zero Boxee Development - Feel free to donate here to help support it!
Twitter: @ThinkOneZero - Support/News/Updates/Statues about Think One Zero Services
Reply With Quote
  #16  
Old May 12th, 2011, 07:41 AM
bartsidee bartsidee is offline
Senior Member
 
Join Date: Nov 2010
Posts: 488
Default

I've modified an small python db program to work with the boxee api to store data. PyDbLite is a lite in memory db app made by Pierre Quentel. It is very fast almost equal to sqlite. You can use it with a nice pythonic syntax. When you make a save commit the data will be stored in the boxee settings.xml file (compressed). The advantage that it is that the data is persistent and not cleared on app upgrades or when the user reboots the box.

Confirmed working with the latest firmware 1.1.

Depending on what you store in the database, make sure you clean it if you use large amounts of data (remove non used/old records). The box has limited space and keep in mind the data is loaded in memory.

Download the module here :
http://bartsidee.nl

Some example code:
Code:
    # Init database, replace 'dummy' with your own id tag
    from PyDbLite import Base
    db = Base('dummy')
    # create new base with field names
    db.create('name','age','size')
    # create new base with field names and open if already exists (also possible mode = 'override')
    db.create('name','age','size', mode = 'open')
    # existing base
    db.open()
    # insert new record
    db.insert(name='homer',age=23,size=1.84)
    # records are dictionaries with a unique integer key __id__
    # simple selection by field value
    records = db(name="homer")
    # complex selection by list comprehension
    res = [ r for r in db if 30 > r['age'] >= 18 and r['size'] < 2 ]
    # or generator expression
    for r in (r for r in db if r['name'] in ('homer','marge') ):
    # delete a record or a list of records
    db.delete(one_record)
    db.delete(list_of_records)
    # delete a record by its id
    del db[rec_id]
    # direct access by id
    record = db[rec_id] # the record such that record['__id__'] == rec_id
    # create an index on a field
    db.create_index('age')
    # update
    db.update(record,age=24)
    # add and drop fields
    db.add_field('new_field',default=0)
    db.drop_field('name')
    # save changes to boxee storage
    db.commit()

If you want to store objects, lists or dicts in the database just use pickle:

Code:
try: import cPickle
except: import pickle as cPickle
#example dict
dict = {'test1':True, ''test2':'new', 'platform':'boxee'}
#Convert dict to pickled string
string = cPickle.dumps(dict, cPickle.HIGHEST_PROTOCOL)
#Convert pickled string back to dict
dict = cPickle.loads(string)

Last edited by bartsidee; May 12th, 2011 at 07:58 AM.
Reply With Quote
  #17  
Old August 18th, 2011, 07:41 AM
liran liran is offline
Junior Member
 
Join Date: Aug 2011
Posts: 10
Default

Maybe this is old thread, and at the newer versions it's different ?

My app has:
(It's with classes, but the same is true for regular Python files I think)

shared.py # A Python file, located at the app's folder.
Code:
class Shared:
    def __init__(self):
        self.x = 3


main.xml:
...
Code:
...
from shared import Shared
shared = Shared()
mc.LogDebug("x value: "+str(shared.x)) # -> 3
...
other.xml:
Code:
...
# No need for import / define 'shared' again.
mc.LogDebug("x value: "+str(shared.x)) # -> 3
...
So it's working for me, and can share variables !
How come it is not documented ?
Maybe something is wrong here ?
Reply With Quote
  #18  
Old August 18th, 2011, 07:50 AM
bartsidee bartsidee is offline
Senior Member
 
Join Date: Nov 2010
Posts: 488
Default

This topic is more about persistant storage so it would be better to open a seperate thread for it. You can indeed share variables, but the way you have proposed is not recommended as it will not work 100% in all situations. It is better actually to launch an app with a python file instead of a skin file and declare all you variables there. Those will then be accessable from all windows and dialogs.
__________________
Have a look at my repo at www.bartsidee.nl
Reply With Quote
  #19  
Old August 18th, 2011, 08:17 AM
liran liran is offline
Junior Member
 
Join Date: Aug 2011
Posts: 10
Default

Quote:
"as it will not work 100% in all situations":
Why ? I need some Python variables, not only strings, to be shared among the XML files. And my way is seems to be working. Why will it not work ?
Reply With Quote
  #20  
Old August 18th, 2011, 08:46 AM
bartsidee bartsidee is offline
Senior Member
 
Join Date: Nov 2010
Posts: 488
Default

I'm not saying you can't use the variables, I'm saying it is not recommended to have a setup like you have. Although all windows share the same global space, not all windows are declared right away or exist the entire app length. Which makes them vulnerable to be deleted by the python garage collector.

Also as you are declaring your variable in one window, it will only exist as global as long as it as has been declared.

So this might will work

Code:
main.xml  - declare  variables
  |
 other.xml
but this not

Code:
start.xml
  |
main.xml - declare  variables
  |
other.xml
Or for example when you are going to use window states there is the possibility that to global var is reset as the window is called again.

Code:
start.xml
  |
main.xml - declare  variables
  |
other.xml
 | 
main.xml - declare  variables (resets to original values)

Code wise it is much better to do it like this:

Code:
default.py  - declare  variables
   |
main.xml   - other2.xml
  |
others.xml
This way you have a nice separation between gui and back-end coding and you have declared you global vars at start-up in the python environment which guarantees they are available no matter which windows configuration you are going to use. Default.py will also only be called on the launch of the app.

It is to bad there are no examples of this on the wiki, I generally can say starting your app with a skin file (although speedy for very simple apps) is a bad way of coding.

for some examples see also:
http://github.com/bartsidee
__________________
Have a look at my repo at www.bartsidee.nl
Reply With Quote
Reply

Bookmarks

Tags
database, persistence, pizza, sqlite, storage

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 08:25 PM.


skin based on greenzero from vBSkins.com

 
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2011, vBulletin Solutions, Inc.