#!/usr/bin/python3 -u # -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*- # # Copyright (C) 2014-2015, 2017 Bashton Ltd # Copyright (C) 2017 JaquerEspeis # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3 as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # IPFS transport for apt. # This is based on apt-transport-s3: # https://github.com/BashtonLtd/apt-transport-s3 import sys class IPFS_method(): __eof = False def __init__(self): self.send_capabilities() def send_capabilities(self): self._send(100, { 'Version': '1.1', 'Single-Instance': 'true', 'Send-Config': 'true'}) def _send(self, code, headers): message = APTMessage(code, headers) sys.stdout.write(message.encode()) def run(self): pass class APTMessage(): _MESSAGE_CODES = { 100: 'Capabilities', 102: 'Status', 200: 'URI Start', 201: 'URI Done', 400: 'URI Failure', 600: 'URI Acquire', 601: 'Configuration' } def __init__(self, code, headers): self._code = code self._headers = headers def encode(self): result = '{0} {1}\n'.format( self._code, self._MESSAGE_CODES[self._code]) for header_key in self._headers: if self._headers[header_key] is not None: result += '{0}: {1}\n'.format( header_key, self._headers[header_key]) return result + '\n' if __name__ == '__main__': try: method = IPFS_method() exitcode = method.run() sys.exit(exitcode) except KeyboardInterrupt: pass