diff --git a/common.py b/common.py index 7cc9445..fb6ed64 100644 --- a/common.py +++ b/common.py @@ -10,14 +10,12 @@ import socket import uuid -# TODO(jrebeiro): Move the CONFIG_FILE variable to the main runnable module CONFIG_FILE = os.path.expanduser("~/pc-autobackup.cfg") def LoadOrCreateConfig(): """Load an existing configuration or create one.""" config = ConfigParser.RawConfigParser() - # TODO(jrebeiro): Move the CONFIG_FILE variable to the main runnable module config.read(CONFIG_FILE) if not config.has_section('AUTOBACKUP'): @@ -29,4 +27,4 @@ with open(CONFIG_FILE, 'wb') as config_file: config.write(config_file) - return config \ No newline at end of file + return config diff --git a/mediaserver.py b/mediaserver.py index 101caef..80b27f9 100644 --- a/mediaserver.py +++ b/mediaserver.py @@ -1,12 +1,16 @@ #!/usr/bin/python # # Copyright 2013 Jeff Rebeiro (jeff@rebeiro.net) All rights reserved -# Simple UPNP implementation for PC Autobackup +# Simple UPNP MediaServer implementation for PC Autobackup __author__ = 'jeff@rebeiro.net (Jeff Rebeiro)' import HTMLParser +from twisted.internet import reactor +from twisted.web.resource import Resource +from twisted.web.server import Site + import common X_BACKUP_RESPONSE = ''' @@ -55,9 +59,37 @@ ''' +class MediaServer(Resource): + + isLeaf = True + + def __init__(self): + self.config = common.LoadOrCreateConfig() + + def render_GET(self, request): + if request.path == '/DMS/SamsungDmsDesc.xml': + return self.GetDMSDescription() + + def GetDMSDescription(self): + response = DMS_DESC % {'friendly_name': self.config.get('AUTOBACKUP', + 'server_name'), + 'uuid': self.config.get('AUTOBACKUP', 'uuid')} + if __name__ == '__main__': + print "Response:" + print response + + return response + +def StartMediaServer(): + resource = MediaServer() + factory = Site(resource) + reactor.listenTCP(52235, factory) + reactor.run() + + def main(): - config = common.LoadOrCreateConfig() + StartMediaServer() if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/ssdp.py b/ssdp.py index 2cc1cb4..11cfd69 100644 --- a/ssdp.py +++ b/ssdp.py @@ -51,11 +51,13 @@ Args: address: A tuple of destination IP and Port as strings """ - # TODO(jrebeiro): Make this send the UDP response once the HTTP server is - # ready. - # self.transport.write(SSDP_RESPONSE, address) - print "Response:" - print SSDP_RESPONSE % (address[0], self.config.get('AUTOBACKUP', 'uuid')) + response = SSDP_RESPONSE % (self.config.get('AUTOBACKUP', + 'default_interface'), + self.config.get('AUTOBACKUP', 'uuid')) + self.transport.write(response, address) + if __name__ == '__main__': + print "Response:" + print response def StartSSDPServer():