Pythonista and Google Drive
Is it possible to bring .py files over to pythonista from Google Drive? When I tap "Open..." under "External Files" in the main Pythonista panel, I get a Google Drive icon under the available locations, and I can navigate to and see files stored there...but only .txt files appear to be accessible, anything with .py or .zip is greyed out and can't be opened. I'm wondering if this is an iOS restriction, or a Google Drive restriction, or a Pythonista issue...just so I can determine if it's solvable at my end.
I see this thread about setting up PyDrive in pythonista to allow programmatic access to Google Drive, but that's more complicated than what I need, really...I just want to be able to transfer .py files to and from Pythonista3 via Google Drive, which seemed like it might be possible...
Just as an add-on to this post: if I use a third-party app like "Documents" (from the app store), which is a general file manager/preview app, I can get the files from Google Drive into that app, and then get them from that app into Pythonista without issue. So Google Drive -> Pythonista doesn't work, but Google Drive -> Documents -> Pythonista does. This makes me think it's some kind of iOS/Google Drive/Pythonista thing, where only certain file extensions and/or permissions are allowed? And somehow the Documents app gets those permissions, but Pythonista does not.
@shinyformica you can use the Apple Files app:
- select Google Drive
- select the .py file ( or long press)
- run Pythonista script
- import file
@cvp I tried exactly that...but all .py files are greyed out and unselectable...so I can't get a share sheet for them. Also can't get a share sheet for the folder containing the files, though it is selectable - the share button doesn't become enabled when the folder is selected.
Are you able to select a .py file in Google Drive from the Apple Files app and share it to Pythonista this way?
Oddly, in the Google Drive app, I am able to hit the "..." button on each individual .py file and from that menu, choose "Open in", which gives a "Copy to Pythonista" option. So I can manually move items that way, just not from within Pythonista for some reason.
The thing that's especially good about "Documents", is it lets Pythonista grab the entire containing folder, not just the individual files, which is much more convenient for a large project.
So...I still don't understand it, but somehow only files which were created by Pythonista remain openable by Pythonista via Google Drive, unless I pass them through a third-party app like Documents.
For example, if I create a .py file in Pythonista, edit it, then copy it to Google Drive by sharing it from within Pythonista, or if I create it in iCloud Drive in Pythonista, and then use Apple Files to copy it to Google Drive, in both cases Pythonista will be able to open, read and import it from Google Drive.
However, if I just upload an identical .py file from somewhere else to Google Drive, Pythonista will show it greyed out in the file browser, and it won't be open/read/import-able. At least that's what I've discovered so far...I tried uploading a plain text file created with a tiny bit of boilerplate python in it:
import os def test(): print "hello" test()
Saved it as "test.py". And then uploaded to Google Drive from three different OSes: Linux, Windows NT and Windows 10. All three were not openable by Pythonista, but an identical bit of boilerplate made in Pythonista and then copied to Google Drive as above still works. I even tried a round-trip: downloaded the working file from Google Drive to Windows 10, edited, saved, then uploaded it again, and it stopped being openable. I think Google Drive is mucking around with the file types and preventing Pythonista from seeing these files as plain text/.py files somehow. Would love to know if others experience similar results.
@shinyformica What I explained (share from Files App / Google Drive) was true but I agree that my files come from Pythonista via Google API upload.
Thus I didn't try with files coming from anywhere else
Edit: I think that Files app use "Drive.file" as authorization
Edit: I told you I use pydrive to upload/download to/from Google Drive. I've checked my authorization and it is "drive". I remember that two years ago I got this kind of problems to not be able to read files coming from other sources and that I have had to update my setting from "drive.file" to "drive". It seems your problem is something like that but I don't know where, sorry 😐
go here to check authorizations you gave to applications
shinyformica last edited by shinyformica
@cvp thanks for those links, I think that's exactly what is going on. The Documents app definitely has "Drive" access, and I see no other apps authorized, which means it must be the default "iOS" authorization is "Drive.file" or lower. Which explains what I'm seeing.
I think I might just have to implement my own way of grabbing the files I need using pydrive, to avoid the two-step process via Documents.
I'll go find some good docs on pydrive and see how I would do it. What's your process for using pydrive to get files to and from Google Drive? I was hoping for a way to transfer an entire project directory structure back and forth, not individual files one by one.
@shinyformica I use pydrive for more than one year, without any problem.
The only difficulties I have had were to get access at beginning, solved due to big help of @jonb.
Your user, password and authorization scopes are stored in a settings file.
Once it's done, it is easy to use to, for instance, get a list of files in a folder, then download the files, etc...
You have methods like createfile, listfile, trash, upload, ...
@shinyformica You said "I see no other apps authorized"
Don't you see "My Drive" which is the Google Drive app?
If not, try first to install this app.
I definitely have the Google Drive app installed...without it, I wouldn't be able to see Google Drive in the locations when I hit "Open..." in Pythonista. But it is true that I am not seeing that exact interface you show above, anywhere...how do you get to that specific view of which apps are authorized? For me, neither the Settings->Manage Apps at drive.google.com, nor the app permissions details at myaccount.google.com/permissions show the same thing you see there. And none are showing the Drive app being given explicit permissions. So perhaps that is the issue?
@shinyformica in the Google Drive iOS app, you can get the same info
- left menu
- account at bottom
- manage your account (i translate from French)
- connection and security
- apps having access to your account