Package: annexremote
AnnexRemoteHelper module to easily develop special remotes forgit annex.
AnnexRemote handles all the protocol stuff for you, so you can focus on the remote itself.
It implements the completeexternal special remote protocoland fulfils all specifications regarding whitespaces etc. This is ensured by an excessive test suite.Documentation(Also have a look at theexamplesandgit-annex-remote-googledrivewhich is based on AnnexRemote.)Getting startedPrerequisitesYou need python3 installed on your system.Installingpip3 install annexremoteRunning the testsIf you want to run the tests, copy the content of thetestsfolder to the same location asannexremote.py.
Then use a test discovery likepytestto run them.UsageImport the necessary classesfromannexremoteimportMasterfromannexremoteimportSpecialRemotefromannexremoteimportRemoteErrorNow create your special remote class. It must subtypeSpecialRemoteand implement at least the 6 basic methods:classMyRemote(SpecialRemote):definitremote(self):# initialize the remote, eg. create the folders# raise RemoteError if the remote couldn't be initializeddefprepare(self):# prepare to be used, eg. open TCP connection, authenticate with the server etc.# raise RemoteError if not ready to usedeftransfer_store(self,key,filename):# store the file in `filename` to a unique location derived from `key`# raise RemoteError if the file couldn't be storeddeftransfer_retrieve(self,key,filename):# get the file identified by `key` and store it to `filename`# raise RemoteError if the file couldn't be retrieveddefcheckpresent(self,key):# return True if the key is present in the remote# return False if the key is not present# raise RemoteError if the presence of the key couldn't be determined, eg. in case of connection errordefremove(self,key):# remove the key from the remote# raise RemoteError if it couldn't be removed# note that removing a not existing key isn't considered an errorIn yourmainfunction, link your remote to the master class and initialize the protocol:defmain():master=Master()remote=MyRemote(master)master.LinkRemote(remote)master.Listen()if__name__=="__main__":main()Now save your program asgit-annex-remote-$somethingand make it executable.chmod +x git-annex-remote-$something(You'll need the sheebang line#!/usr/bin/env python3)That's it. Now you've created your special remote.Export remotesImport and subtypeExportRemoteinstead ofSpecialRemote:# ...fromannexremoteimportExportRemoteclassMyRemote(ExportRemote):# implement the remote methods just like in the above example and then additionally:deftransferexport_store(self,key,local_file,remote_file):# store the file located at `local_file` to `remote_file` on the remote# raise RemoteError if the file couldn't be storeddeftransferexport_retrieve(self,key,local_file,remote_file):# get the file located at `remote_file` from the remote and store it to `local_file`# raise RemoteError if the file couldn't be retrieveddefcheckpresentexport(self,key,remote_file):# return True if the file `remote_file` is present in the remote# return False if not# raise RemoteError if the presence of the file couldn't be determined, eg. in case of connection errordefremoveexport(self,key,remote_file):# remove the file in `remote_file` from the remote# raise RemoteError if it couldn't be removed# note that removing a not existing key isn't considered an errordefremoveexportdirectory(self,remote_directory):# remove the directory `remote_directory` from the remote# raise RemoteError if it couldn't be removed# note that removing a not existing directory isn't considered an errordefrenameexport(self,key,filename,new_filename):# move the remote file in `name` to `new_name`# raise RemoteError if it couldn't be movedLoggingThis module includes a StreamHandler to send log records to git annex via the special remote protocol (using DEBUG). You can use it like this:...importlogging...defmain():master=Master()remote=MyRemote(master)master.LinkRemote(remote)logger=logging.getLogger()logger.addHandler(master.LoggingHandler())master.Listen()if__name__=="__main__":main()LicenseThis project is licensed under GPLv3 - see theLICENSEfile for details