diff --git a/common.py b/common.py
new file mode 100644
index 0000000..0c4256c
--- /dev/null
+++ b/common.py
@@ -0,0 +1,30 @@
+#!/usr/bin/python
+#
+# Copyright 2013 Jeff Rebeiro (jeff@rebeiro.net) All rights reserved
+# Common functions for PC Autobackup
+
+__author__ = 'jeff@rebeiro.net (Jeff Rebeiro)'
+
+import ConfigParser
+import os
+
+# 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'):
+ config.add_section('AUTOBACKUP')
+ config.set('AUTOBACKUP', 'uuid', uuid.uuid4())
+ config.set('AUTOBACKUP', 'default_interface',
+ socket.gethostbyname(socket.gethostname()))
+ config.set('AUTOBACKUP', 'server_name', '[PC]AutoBackup')
+ with open(CONFIG_FILE, 'wb') as config_file:
+ config.write(config_file)
+
+ return config
\ No newline at end of file
diff --git a/mediaserver.py b/mediaserver.py
new file mode 100644
index 0000000..101caef
--- /dev/null
+++ b/mediaserver.py
@@ -0,0 +1,63 @@
+#!/usr/bin/python
+#
+# Copyright 2013 Jeff Rebeiro (jeff@rebeiro.net) All rights reserved
+# Simple UPNP implementation for PC Autobackup
+
+__author__ = 'jeff@rebeiro.net (Jeff Rebeiro)'
+
+import HTMLParser
+
+import common
+
+X_BACKUP_RESPONSE = '''
+
+
+
+
+'''
+
+DMS_DESC = '''
+
+
+ 1
+ 0
+
+
+ DMS-1.50
+ urn:schemas-upnp-org:device:MediaServer:1
+ %(friendly_name)s
+ Samsung Electronics
+ http://www.samsung.com
+ Samsung PC AutoBackup
+ WiselinkPro
+ 1.0
+ http://www.samsung.com
+ 20080818WiselinkPro
+ smi,DCM10,getMediaInfo.sec,getCaptionInfo.sec
+ uuid:%(uuid)s
+
+
+ urn:schemas-upnp-org:service:ContentDirectory:1
+ urn:upnp-org:serviceId:ContentDirectory
+ /upnp/control/ContentDirectory1
+ /upnp/event/ContentDirectory1
+ ContentDirectory1.xml
+
+
+ urn:schemas-upnp-org:service:ConnectionManager:1
+ urn:upnp-org:serviceId:ConnectionManager
+ /upnp/control/ConnectionManager1
+ /upnp/event/ConnectionManager1
+ ConnectionManager1.xml
+
+
+
+'''
+
+
+def main():
+ config = common.LoadOrCreateConfig()
+
+
+if __name__ == "__main__":
+ main()
\ No newline at end of file
diff --git a/ssdp.py b/ssdp.py
index 1f00f47..bd1574c 100644
--- a/ssdp.py
+++ b/ssdp.py
@@ -1,6 +1,6 @@
#!/usr/bin/python
#
-# Copyright 2013 Jeff Rebeiro (jrebeiro@gmail.com) All rights reserved
+# Copyright 2013 Jeff Rebeiro (jeff@rebeiro.net) All rights reserved
# Simple SSDP implementation for PC Autobackup
__author__ = 'jeff@rebeiro.net (Jeff Rebeiro)'
@@ -11,12 +11,12 @@
import socket
import sys
import uuid
+
from twisted.internet import reactor
from twisted.internet import task
from twisted.internet.protocol import DatagramProtocol
-# TODO(jrebeiro): Move the CONFIG_FILE variable to the main runnable module
-CONFIG_FILE = os.path.expanduser("~/pc-autobackup.cfg")
+import common
pattern = r'^M-SEARCH.*HOST: (.*):(\d+).*urn:schemas-upnp-org:device:(\w+):1.*'
MSEARCH = re.compile(pattern, re.DOTALL)
@@ -40,7 +40,7 @@
listenMultiple=True)
self.server.setLoopbackMode(1)
self.server.joinGroup(self.ssdp_address,
- interface=self.config.get('SSDP',
+ interface=self.config.get('AUTOBACKUP',
'default_interface'))
def datagramReceived(self, datagram, address):
@@ -63,32 +63,15 @@
# TODO(jrebeiro): Make this send a UDP response once the HTTP server is
# ready.
print "Response:"
- print SSDP_RESPONSE % (address[0], self.config.get('SSDP', 'uuid'))
+ print SSDP_RESPONSE % (address[0], self.config.get('AUTOBACKUP', 'uuid'))
def stop(self):
self.server.leaveGroup(self.ssdp_address,
- interface=self.config.get('SSDP',
+ interface=self.config.get('AUTOBACKUP',
'default_interface'))
self.server.stopListening()
-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('SSDP'):
- config.add_section('SSDP')
- config.set('SSDP', 'uuid', uuid.uuid4())
- config.set('SSDP', 'default_interface',
- socket.gethostbyname(socket.gethostname()))
- with open(CONFIG_FILE, 'wb') as config_file:
- config.write(config_file)
-
- return config
-
-
def SSDPReactor():
"""Callback function for twisted.internet.reactor."""
ssdp_server = SSDP()
@@ -96,8 +79,7 @@
def main():
- # TODO(jrebeiro): Move this code to a main runnable module
- config = LoadOrCreateConfig()
+ config = common.LoadOrCreateConfig()
reactor.callWhenRunning(SSDPReactor)
reactor.run()