We have moved to a new Sailfish OS Forum. Please start new discussions there.
0

Python filesystem access

asked 2020-01-19 03:33:51 +0200

sasharp gravatar image

I am developing an app with Python. I need to create a sqlite database in the way like this:

 path = '.local/share/harbour-myapp'
    if (not os.path.isdir(path)):
        os.mkdir(path)
 db = os.path.join(path, 'harbour-myapp.db')
 self.con = sqlite3.connect(db)

When I deploy the app everything works every time fine. When I close and start it again, I get:

sqlite3.OperationalError: unable to open database file

What does cause the error?

edit retag flag offensive close delete

2 Answers

Sort by » oldest newest most voted
2

answered 2020-01-19 04:32:18 +0200

lethe gravatar image

Not sure if that will solve your issue, but "path" should really be an absolute path. The way it is specified now, it will be relative to your working directory from where you started the program (which may differ from where deploy starts it).

edit flag offensive delete publish link more

Comments

1

It seems to work now with the absolute path '/home/nemo/.local/share/harbour-myapp' Thanks!

sasharp ( 2020-01-19 14:10:24 +0200 )edit
1

answered 2020-01-19 04:46:03 +0200

0xe4524ffe gravatar image

You don't have permissions. I just checked, and cwd of harbour apps I launced was \.

You can use HOME enviroment variable to get user home directory. XDG_CONFIG_HOME is not set on Sailfish OS, sadly.

edit flag offensive delete publish link more

Comments

1

Fortunately HOME is not needed. Python offers

path = os.path.expanduser('~/.local/share/harbour-myapp')
Eierkopp ( 2020-01-19 06:31:08 +0200 )edit

os.environ['HOME'] returns also in my case /home/nemo it should be joined to my path. Thanks!

sasharp ( 2020-01-19 14:27:19 +0200 )edit

os.path.expanduser('~/.local/share/harbour-myapp') is the shortest way. Thanks!

sasharp ( 2020-01-19 14:28:20 +0200 )edit

BTW, the Harbour FAQ say apps should use the XDG paths, such as HOME for data storage: https://harbour.jolla.com/faq

MartinK ( 2020-01-19 16:23:23 +0200 )edit

Ok, but how to access them from Python? PyXDG?

sasharp ( 2020-01-19 17:18:37 +0200 )edit
Login/Signup to Answer

Question tools

Follow
2 followers

Stats

Asked: 2020-01-19 03:33:51 +0200

Seen: 287 times

Last updated: Jan 19 '20