2007-10-12 19:07:02 +02:00
|
|
|
from sugar.profile import get_profile
|
2007-10-12 17:38:29 +02:00
|
|
|
from xmlrpclib import ServerProxy, Error
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
|
|
|
|
REGISTER_URL = 'http://schoolserver:8080/'
|
|
|
|
|
|
|
|
def register_laptop(url=REGISTER_URL):
|
|
|
|
if not have_ofw_tree():
|
|
|
|
return False
|
|
|
|
|
|
|
|
sn = read_ofw('mfg-data/SN')
|
|
|
|
uuid = read_ofw('mfg-data/U#')
|
|
|
|
sn = sn or 'SHF00000000'
|
|
|
|
uuid = uuid or '00000000-0000-0000-0000-000000000000'
|
|
|
|
|
2007-10-12 19:07:02 +02:00
|
|
|
profile = get_profile()
|
2007-10-12 17:38:29 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
server = ServerProxy(url)
|
2007-10-12 19:07:02 +02:00
|
|
|
data = server.register(sn, profile.nick_name, uuid, profile.pubkey)
|
2007-10-12 17:38:29 +02:00
|
|
|
if data['success'] != 'OK':
|
|
|
|
print >> sys.stderr, "Error registering laptop: " + data['error']
|
|
|
|
return False
|
2007-10-12 19:07:02 +02:00
|
|
|
|
|
|
|
profile.jabber_server = data['jabberserver']
|
|
|
|
profile.backup1 = data['backupurl']
|
|
|
|
profile.save()
|
2007-10-12 17:38:29 +02:00
|
|
|
except Error, e:
|
|
|
|
print >> sys.stderr, "Error registering laptop: " + str(e)
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
def have_ofw_tree():
|
|
|
|
return os.path.exists('/ofw')
|
|
|
|
|
|
|
|
def read_ofw(path):
|
|
|
|
path = os.path.join('/ofw', path)
|
|
|
|
if not os.path.exists(path):
|
|
|
|
return None
|
|
|
|
fh = open(path, 'r')
|
|
|
|
data = fh.read().rstrip('\0\n')
|
|
|
|
fh.close()
|
|
|
|
return data
|