From 99a48c3f35d8b18680a60b8ebacb52343f8d5cf5 Mon Sep 17 00:00:00 2001
From: Hamilton Chua <hchua@enterprise2.localdomain>
Date: Thu, 13 Aug 2009 18:30:51 +0800
Subject: [PATCH 2/2] use ~ instead of hardcoding the home dir, put files into a folder inside /.sugar

---
 src/jarabe/desktop/schoolserver.py |   44 +++++++++++++++++------------------
 1 files changed, 21 insertions(+), 23 deletions(-)

diff --git a/src/jarabe/desktop/schoolserver.py b/src/jarabe/desktop/schoolserver.py
index 2ec5a06..57d381f 100644
--- a/src/jarabe/desktop/schoolserver.py
+++ b/src/jarabe/desktop/schoolserver.py
@@ -18,7 +18,7 @@ import logging
 from gettext import gettext as _
 from xmlrpclib import ServerProxy, Error
 import socket
-import os
+import os,os.path
 import gconf
 
 import string, random, time
@@ -31,8 +31,7 @@ from sugar.profile import get_profile
 
 REGISTER_URL = 'http://schoolserver:8080/'
 
-# SoaS: ham@solutiongrove.com
-# defs to enable registration on SoaS
+# defs to enable registration of sugar to an xs on non-olpc hardware
 
 # utilities ********************************************************************
 
@@ -47,7 +46,7 @@ def getEpoch():
 # - we randomly get 3 letters
 # - concat the above with the last 8 numbers from epoch seconds
 
-def gen_soas_serial():
+def gen_identifier_serial():
   s1 = ''.join([random.choice(string.ascii_uppercase) for y in range(3)])
   s2 = str(int(getEpoch()))[-8:]
   serial = s1 + s2 
@@ -55,39 +54,39 @@ def gen_soas_serial():
 
 # to create a unique uuid
 
-def gen_soas_uuid():
+def gen_identifier_uuid():
   u1_count = 40 
   uuid = ''.join([random.choice(string.hexdigits + '-') for y in range(int(u1_count))])
   return uuid
 
 # write serial and uuid to file ************************************************
 
-def write_soas_info(sn,uuid,backup_url):
-  # we presume that there is a /home/liveuser/.sugar directory
-  soas_dir = '/home/liveuser/.sugar/soas/'
+def write_identifier_info(sn,uuid,backup_url):
+  # get to the user's home where .sugar/default/ is
+  identifier_dir = os.path.expanduser('~') + '/.sugar/default/identifiers'
   # create the directory where we will put the files
-  if not os.path.exists(soas_dir):
-    os.mkdir(soas_dir)
+  if not os.path.exists(identifier_dir):
+    os.mkdir(identifier_dir)
   # check if a serial file exists, it might be from a failed registration
   # let's delete it first
-  if os.path.exists(os.path.join(soas_dir, 'sn')):
-    os.remove(os.path.join(soas_dir, 'sn'))
+  if os.path.exists(os.path.join(identifier_dir, 'sn')):
+    os.remove(os.path.join(identifier_dir, 'sn'))
   # write the serial into a file
-  serial_file = open(os.path.join(soas_dir, 'sn'),'w')
+  serial_file = open(os.path.join(identifier_dir, 'sn'),'w')
   serial_file.write(sn)
   serial_file.close()
   # check if a uuid file exists, it might be from a failed registration
   # let's delete it first
-  if os.path.exists(os.path.join(soas_dir, 'uuid')):
-    os.remove(os.path.join(soas_dir, 'uuid'))
+  if os.path.exists(os.path.join(identifier_dir, 'uuid')):
+    os.remove(os.path.join(identifier_dir, 'uuid'))
   # write the uuid into a file
-  uuid_file = open(os.path.join(soas_dir, 'uuid'),'w')
+  uuid_file = open(os.path.join(identifier_dir, 'uuid'),'w')
   uuid_file.write(uuid)
   uuid_file.close()
-  if os.path.exists(os.path.join(soas_dir, 'backup_url')):
-    os.remove(os.path.join(soas_dir, 'backup_url'))
+  if os.path.exists(os.path.join(identifier_dir, 'backup_url')):
+    os.remove(os.path.join(identifier_dir, 'backup_url'))
   # write the backup_url to a file
-  bu_file = open(os.path.join(soas_dir, 'backup_url'),'w')
+  bu_file = open(os.path.join(identifier_dir, 'backup_url'),'w')
   bu_file.write(backup_url)
   bu_file.close()
 
@@ -105,13 +104,12 @@ def register_laptop(url=REGISTER_URL):
         # logging.error('Registration: Cannot obtain data needed to register.')
         # raise RegisterError(_('Cannot obtain data needed for registration.'))
 
-        # SoaS  :
         # if we did not find an ofw directory
         # let's generate the serial and uuid from the current time 
         # save the generated serial and uuid into files
 
-        sn = gen_soas_serial()
-        uuid = gen_soas_uuid()
+        sn = gen_identifier_serial()
+        uuid = gen_identifier_uuid()
 
         # we want to use the text in the jabber server as our registration url
 
@@ -119,7 +117,7 @@ def register_laptop(url=REGISTER_URL):
 
         # we need to save sn and uuid to work with backups
 
-        write_soas_info(sn,uuid,JABBER_SERVER)
+        write_identifier_info(sn,uuid,JABBER_SERVER)
 
         # override the registration url to use
 
-- 
1.6.2.5

