Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu@sugarlabs.org>2009-09-04 15:30:44 (GMT)
committer Tomeu Vizoso <tomeu@sugarlabs.org>2009-09-04 15:30:44 (GMT)
commit6c832e5681e9dbdf26d1260558659db2f5ff2fbc (patch)
tree88c21d0ac4add3a303338d162712789c9d358395 /src
parent930741e22e97901f737484f20aac8f090d9beefa (diff)
Implement server registration for non-XOs (Hamilton Chua) #916
Diffstat (limited to 'src')
-rw-r--r--src/jarabe/desktop/schoolserver.py72
1 files changed, 62 insertions, 10 deletions
diff --git a/src/jarabe/desktop/schoolserver.py b/src/jarabe/desktop/schoolserver.py
index f09469f..62519df 100644
--- a/src/jarabe/desktop/schoolserver.py
+++ b/src/jarabe/desktop/schoolserver.py
@@ -19,33 +19,85 @@ from gettext import gettext as _
from xmlrpclib import ServerProxy, Error
import socket
import os
+import string
+import random
+import time
+import uuid
+
import gconf
+from sugar import env
from sugar.profile import get_profile
REGISTER_URL = 'http://schoolserver:8080/'
+def generate_serial_number():
+ """ Generates a serial number based on 3 random uppercase letters
+ and the last 8 digits of the current unix seconds. """
+
+ serial_part1 = []
+
+ for y in range(3) :
+ serial_part1.append(random.choice(string.ascii_uppercase))
+
+ serial_part1 = ''.join(serial_part1)
+ serial_part2 = str(int(time.time()))[-8:]
+ serial = serial_part1 + serial_part2
+
+ return serial
+
+def store_identifiers(serial_number, uuid, backup_url):
+ """ Stores the serial number, uuid and backup_url
+ in the identifier folder inside the profile directory
+ so that these identifiers can be used for backup. """
+
+ identifier_path = os.path.join(env.get_profile_path(), 'identifiers')
+ if not os.path.exists(identifier_path):
+ os.mkdir(identifier_path)
+
+ if os.path.exists(os.path.join(identifier_path, 'sn')):
+ os.remove(os.path.join(identifier_path, 'sn'))
+ serial_file = open(os.path.join(identifier_path, 'sn'), 'w')
+ serial_file.write(serial_number)
+ serial_file.close()
+
+ if os.path.exists(os.path.join(identifier_path, 'uuid')):
+ os.remove(os.path.join(identifier_path, 'uuid'))
+ uuid_file = open(os.path.join(identifier_path, 'uuid'), 'w')
+ uuid_file.write(uuid)
+ uuid_file.close()
+
+ if os.path.exists(os.path.join(identifier_path, 'backup_url')):
+ os.remove(os.path.join(identifier_path, 'backup_url'))
+ backup_url_file = open(os.path.join(identifier_path, 'backup_url'), 'w')
+ backup_url_file.write(backup_url)
+ backup_url_file.close()
+
class RegisterError(Exception):
pass
def register_laptop(url=REGISTER_URL):
- if not have_ofw_tree():
- logging.error('Registration: Cannot obtain data needed to register.')
- raise RegisterError(_('Cannot obtain data needed for registration.'))
-
- sn = read_ofw('mfg-data/SN')
- uuid = read_ofw('mfg-data/U#')
- sn = sn or 'SHF00000000'
- uuid = uuid or '00000000-0000-0000-0000-000000000000'
profile = get_profile()
-
client = gconf.client_get_default()
+
+ if have_ofw_tree():
+ sn = read_ofw('mfg-data/SN')
+ uuid_ = read_ofw('mfg-data/U#')
+ sn = sn or 'SHF00000000'
+ uuid_ = uuid_ or '00000000-0000-0000-0000-000000000000'
+ else:
+ sn = generate_serial_number()
+ uuid_ = str(uuid.uuid1())
+ jabber_server = client.get_string('/desktop/sugar/collaboration/jabber_server')
+ store_identifiers(sn, uuid_, jabber_server)
+ url = 'http://' + jabber_server + ':8080/'
+
nick = client.get_string('/desktop/sugar/user/nick')
server = ServerProxy(url)
try:
- data = server.register(sn, nick, uuid, profile.pubkey)
+ data = server.register(sn, nick, uuid_, profile.pubkey)
except (Error, socket.error):
logging.exception('Registration: cannot connect to server')
raise RegisterError(_('Cannot connect to the server.'))