googledriveannex 0.2.0

Hook program for gitannex to use Google Drive as backend

Requirements:

python2
python-httplib2

Credit for the googledrive api interface goes to google

Install

Clone the git repository in your home folder.

git clone git://github.com/TobiasTheViking/googledriveannex.git 

This should make a ~/googledriveannex folder

Setup

Make the file executable, and link it into PATH

cd ~/googledriveannex; chmod +x git-annex-remote-googledrive; sudo ln -sf `pwd`/git-annex-remote-googledrive /usr/local/bin/git-annex-remote-googledrive

Commands for gitannex:

git annex initremote googledrive type=external externaltype=googledrive encryption=shared folder=gitannex

An oauth authentication link should now be launched in the default browser. Authenticate and you will be proved with a code.

OAUTH='authentication code' git annex initremote googledrive type=external externaltype=googledrive encryption=shared folder=gitannex
git annex describe googledrive "the googledrive library"
I have now configured my Googledrive on Laptop1 according to the guide above, how do I add the same remote on Laptop2? It would be nice if this was described in the guide, include where the encryption keys are stored.

Hi,

I am new to git-annex and I want to use google drive as remote but I can't.

I create syslink to googledriveannex in /usr/local/bin.

When I execute below command, command waiting but not make anything:

$ git annex initremote googledrive type=external externaltype=googledrive encryption=shared folder=gitannex

initremote googledrive (encryption setup) # Waiting but does not do anything.

What I am doing wrong?

Thanks for helps

@Mesut, I think you're doing everything right. It can take a long time for the highly secure gpg key to be generated. Sit tight and let it finish, or you can pass --fast to generate a key that is a tiny bit less secure.
Comment by http://joeyh.name/ Thu Apr 17 20:58:41 2014

Hi Johnny,

I wrote a patch for googledriveannex that fixed this problem for me. First you add the google drive special remote in repo1 then you clone repo1 into repo2. In repo2 you do "git annex enableremote googldrivespecialremotename" and it should work. The problem was that the init method, that is called by git annex when a special remote is first created but also when it is enabled somewhere else, did not factor in the possibility that it had already been created. I will simultaneously submit the patch to the author of the special remote plugin but here it is for you to quickly get going:

diff --git a/git-annex-remote-googledrive b/git-annex-remote-googledrive
index 49cd917..c8e70f3 100755
--- a/git-annex-remote-googledrive
+++ b/git-annex-remote-googledrive
@@ -330,13 +330,16 @@ def initremote(line):
     oauth = os.getenv("OAUTH") or ""
     encryption = common.getConfig("encryption")
     myfolder = common.getConfig("folder")
-    stored_creds = sys.modules["__main__"].login({"oauth": oauth})
-    if len(myfolder) and stored_creds:
-        common.sprint('SETCONFIG myfolder ' + myfolder + '')
-        common.sprint('SETCONFIG stored_creds ' + json.dumps(stored_creds) + '')
-        common.sprint('INITREMOTE-SUCCESS')
+    if not common.getConfig("stored_creds"):
+       stored_creds = sys.modules["__main__"].login({"oauth": oauth})
+       if len(myfolder) and stored_creds:
+           common.sprint('SETCONFIG myfolder ' + myfolder + '')
+           common.sprint('SETCONFIG stored_creds ' + json.dumps(stored_creds) + '')
+           common.sprint('INITREMOTE-SUCCESS')
+       else:
+           common.sprint('INITREMOTE-FAILURE You need to set OAUTH environment variables and folder and encryption parameters when running initremote.')
     else:
-        common.sprint('INITREMOTE-FAILURE You need to set OAUTH environment variables and folder and encryption parameters when running initremote.')
+           common.sprint('INITREMOTE-SUCCESS')
     common.log("Done")

 def prepare(line):
-- 

I moved a big PDF to Google Drive (with shared encryption).

Now, when I try to get it again:

    get Documents/Guyau - The Non-Religion of the Future, nonreligionoffut00guyarich.pdf (from googledrive...) (gpg) 
    Traceback (most recent call last):
      File "/usr/bin/git-annex-remote-googledrive", line 411, in <module>
        common.startRemote()
      File "/usr/share/googledriveannex-git/lib/CommonFunctions.py", line 555, in startRemote
        sys.modules["__main__"].transfer(line)
      File "/usr/bin/git-annex-remote-googledrive", line 372, in transfer
        if getFile(line[2], " ".join(line[3:]), folder):
      File "/usr/bin/git-annex-remote-googledrive", line 257, in getFile
        ret = common.fetchPage({"link": download_url, "headers": [("Authorization", "Bearer " + credentials.access_token)], "progress": "true"})
      File "/usr/share/googledriveannex-git/lib/CommonFunctions.py", line 207, in fetchPage
        totalsize = int(con.headers['content-length'])
      File "/usr/lib/python2.7/rfc822.py", line 388, in __getitem__
        return self.dict[name.lower()]
    KeyError: 'content-length'

It works for smaller files. Is there a limit on the file size?

Comment by hugo Sun Oct 5 19:40:23 2014

The Google Drive interface tells me:

Size 29,776,826 bytes

Comment by hugo Sun Oct 5 19:43:04 2014

Hugo, I didn't write this code, but it looks to me like you could work around the problem by changing line 207 of lib/CommonFunctions.py:

diff --git a/lib/CommonFunctions.py b/lib/CommonFunctions.py
index 050b93e..083f5d6 100644
--- a/lib/CommonFunctions.py
+++ b/lib/CommonFunctions.py
@@ -204,7 +204,7 @@ def fetchPage(params={}):
         if get("progress"):
             data = False
             tdata = ""
-            totalsize = int(con.headers['content-length'])
+            totalsize = 0
             chunksize = totalsize / 100
             if chunksize < 4096:
                 chunksize = 4096

Probably the API used to return a content-length header, and no longer does, or doesn't do so reliably. It does not seem to be used for anything too important -- this change will break git-annex's progress display a little bit, perhaps.

Comment by http://joeyh.name/ Mon Oct 6 15:23:59 2014
Thanks Joey, I was able to get the file after this modification. I’ll make a pull request on Github.
Comment by hugo Mon Oct 6 16:45:03 2014
Comments on this page are closed.