Can't write file on iOS using kivy in python - ios

I'm writing an app and attempting to use the mapview module from kivy's garden library, and everything works fine until the downloader module from mapview tries to write the map tile it downloads. It spits out: Downloader error: IOError(1, 'Operation not permitted')
And the file that it is trying to write is: 'cache/26a7511794_11_1041_1360.png' which would be in the cache folder of the app's directory (I assume). I've also tried changing the cache folder (as specified in the CACHE_DIR variable of the __init__.py module from mapview) from cache to /Library/Caches (as done in https://github.com/kivy-garden/garden.mapview/issues/28) but I get a permission error there as well.
What is the correct string for the CACHE_DIR folder to make mapview work on iOS? Or perhaps there's something in Xcode I need to set for this to work?

I followed a great tip from Albert Gao at his post here to solve this issue. I had to make a VERY SIMPLE modification to the mapview module's __init__.py script. The default folder for caches wouldn't work on ios. Here is the code in __init__.py before:
CACHE_DIR = "cache"
here is the code after fixing it to work on iOS:
from kivy.utils import platform
from kivy.app import App
import os.path
if platform == 'ios': # Erik Sandberg fix 10/14/2018
root_folder = App().user_data_dir
CACHE_DIR = os.path.join(root_folder, 'cache')
cache_folder = os.path.join(root_folder, 'cache')
CACHE_DIR = cache_folder
#CACHE_DIR = "Library/Caches"
else:
CACHE_DIR = "cache"
Reasoning: the default folder where it tries to make the "cache" directory is not actually where the main app is running. The main app is truly running from the path gotten from App().user_data_dir. iOS would not let me create files in a folder that was not below where the main app was truly running from.
I hope that helps anyone else running into a similar problem!

Related

Is there any way of loading local resource files in dart? (not flutter)

I want to load the bytes of a file into a variable while testing my flutter application.
I can't use the assets directory as those are bundled with the app and require WidgetsFlutterBinding.ensureInitialized();
I tried searching the file manually with the path package, but this did not seem to work and was rather hacky. That is why i'm searching for a more official approach.
I was thinking way to complicated ...
As Chuck Batson commented, you can just use the path from the projects root for passing it into the (dart:io) File:
File loadResource(String relativePath) {
final filePath = path.join("test", "resources", relativePath);
return File(filePath);
}
(Notice: The above code makes use of the path package for constructing a file path.)

Can you require a file directly from the /after/plugin folder?

I decided to spring-clean and update my nvim config files/plugins, and thought I’d make proper use of the after/plug folder.
While setting up LSP (with mason, mason-lspconfig, and lspconfig), I wanted to move all the lsp language server settings out from after/plugin/lsp/init.lua to their own files (now in after/plugin/lsp/settings).
The problem is I don’t seem to be able to require them into the init.lua file.
Things I’ve tried to no avail:
require(‘after/plugin/lsp/settings/sumneko_lua.lua’)
require(vim.fn.stdpath("config") .. "/after/plugin/lsp/settings/sumneko_lua”)
require(vim.fn.expand('%:h').. ‘/settings/sumneko_lua’)
The attempt using expand works when I resource the file in nvim; but causes an error when starting nvim.
I understand that all the files in after/plugin are automagically sourced at startup. So if I had a file shared.lua:
local M = {}
function M.greet()
vim.notify("Hello!”)
end
return M
in the same folder as after/plugin/lsp/init.lua, how can I get access to the greet() function from init.lua?
Any pointers would be greatly appreciated.
It turned out to be quite a simple solution in the end: I simply updated the paths to be searched in init.lua
-- nvim/init.lua
-- Allow require to look in after/plugin folder
local home_dir = os.getenv("HOME”)
package.path = home_dir .. "/.config/nvim/after/plugin/?.lua;" .. package.path
And then I can require any file inside the after/plugin folder
e.g - require(‘lsp/settings/sumneko’) or require(‘lsp/shared’).greet()

How do you load a file (.csv) into a Beeware/Briefcase application?

I am using kivy as the GUI and Briefcase as a packaging utility. My .kv file is in the appname/project/src/projectName/resources folder. I also need a .csv file, in the same folder, and want to use pandas with it. I have no problem with importing the packages (I added them to the .toml file). I can't use the full path because when I package the app, the path will be different on each computer. Using relative paths to the app.py file does not work, giving me a file not found error. Is there a way to read a file using a relative path (maybe the source parameter in the .toml file)?
kv = Builder.load_file('resources/builder.kv')
df = pd.read_csv('resources/chemdata.csv')
class ChemApp(App):
def build(self):
self.icon = 'resources/elemental.ico'
return kv
I just encountered and solved a similar problem with Briefcase, even though I was using BeeWare's Toga GUI.
In my case, the main Python file app.py had to access a database file resources/data.csv. In the constructor of the class where I create a main window in app.py, I added the following lines (The import line wasn't there, but included here for clarification):
from pathlib import Path
self.resources_folder = Path(__file__).joinpath("../resources").resolve()
self.db_filepath = self.resources_folder.joinpath("data.csv")
Then I used self.db_filepath to successfully open the CSV file on my phone.
__file__ returns the path to the current file on whatever platform or device.

How to get Dart's Web UI to put an image in the out folder

Dart's Web UI performs a compile step which puts the generated files into an "out" folder. I can't figure out how to get an image to be placed in that out folder, though. Does anyone know how?
I have the images in the web folder in a folder called img, although I've also tried putting them directly in web. Should I create a top level folder named resources and put them in there instead?
I had the same problem, and have almost solved it by updating my build.dart to include a copy of the img folder into the out folder.
import 'dart:io';
import 'dart:async';
import 'package:web_ui/component_build.dart';
// Ref: http://www.dartlang.org/articles/dart-web-components/tools.html
// Actually ... https://github.com/sethladd/dart-web-components-tests/blob/master/build.dart
main() {
var args = new List.from(new Options().arguments);
// args.addAll(['--', '--no-rewrite-urls']);
Future dwc = build(args, ['web/index.html']);
dwc
.then((_) => Process.run('cp', ['-fR', 'web/img', 'web/out']));
}
In the above I've added a command to run "cp" (I'm on a Mac) of web/img to web/out.
I say almost solved it because those image in the img folder also end up being copied directly into the out folder as well as out/img, which isn't ideal but doesn't harm anything for me just now. I believe these extra copies are from build.dart being triggered by the copy, haven't found a way to stop this yet.

Pylons + mod_wsgi -> ImportError: No module named paste.deploy

I'm following the example here: http://code.google.com/p/modwsgi/wiki/IntegrationWithPylons
however, it doesn't work - I get "ImportError: No module named paste.deploy" in the apache error log. Googling in this case helps not - I see some stuff about permissions, but all my permissions are fine. Where does paste.deploy really come from? It comes from PasteDeploy-1.3.4-py2.6.egg in site-packages, installed in my pylonsdevenv directory, right? Well, then how is apache supposed to know about that directory? Does the actual pylons project have to be in the pylonsdevenv directory?
thanks!
I added:
import site
site.addsitedir('/<yadayada>/pylonsdevenv/lib/python2.6/site-packages')
to the top of my wsgi file, and then set debug = False in my development.ini file (and later, deployment.ini file, I presume), that seemed to work...
If you can import (from paste.deploy import loadapp) manually it has to be a problem with sys.path. Also make sure that apache uses proper python interpreter. I have something like this in my "passanger_wsgi.py" on Dreamhost:
INTERP = "/home/myuser/bin/python"
if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv)
cwd = os.getcwd()
sys.path.append(os.getcwd())
sys.path.append('/home/myuser/blog')
You can try put some debug and check which paths are inside "sys.path".
Hope this helps.

Resources