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
|
b
|
|
| 18 | 18 | from gettext import gettext as _ |
| 19 | 19 | from xmlrpclib import ServerProxy, Error |
| 20 | 20 | import socket |
| 21 | | import os |
| | 21 | import os,os.path |
| 22 | 22 | import gconf |
| 23 | 23 | |
| 24 | 24 | import string, random, time |
| … |
… |
|
| 31 | 31 | |
| 32 | 32 | REGISTER_URL = 'http://schoolserver:8080/' |
| 33 | 33 | |
| 34 | | # SoaS: ham@solutiongrove.com |
| 35 | | # defs to enable registration on SoaS |
| | 34 | # defs to enable registration of sugar to an xs on non-olpc hardware |
| 36 | 35 | |
| 37 | 36 | # utilities ******************************************************************** |
| 38 | 37 | |
| … |
… |
|
| 47 | 46 | # - we randomly get 3 letters |
| 48 | 47 | # - concat the above with the last 8 numbers from epoch seconds |
| 49 | 48 | |
| 50 | | def gen_soas_serial(): |
| | 49 | def gen_identifier_serial(): |
| 51 | 50 | s1 = ''.join([random.choice(string.ascii_uppercase) for y in range(3)]) |
| 52 | 51 | s2 = str(int(getEpoch()))[-8:] |
| 53 | 52 | serial = s1 + s2 |
| … |
… |
|
| 55 | 54 | |
| 56 | 55 | # to create a unique uuid |
| 57 | 56 | |
| 58 | | def gen_soas_uuid(): |
| | 57 | def gen_identifier_uuid(): |
| 59 | 58 | u1_count = 40 |
| 60 | 59 | uuid = ''.join([random.choice(string.hexdigits + '-') for y in range(int(u1_count))]) |
| 61 | 60 | return uuid |
| 62 | 61 | |
| 63 | 62 | # write serial and uuid to file ************************************************ |
| 64 | 63 | |
| 65 | | def write_soas_info(sn,uuid,backup_url): |
| 66 | | # we presume that there is a /home/liveuser/.sugar directory |
| 67 | | soas_dir = '/home/liveuser/.sugar/soas/' |
| | 64 | def write_identifier_info(sn,uuid,backup_url): |
| | 65 | # get to the user's home where .sugar/default/ is |
| | 66 | identifier_dir = os.path.expanduser('~') + '/.sugar/default/identifiers' |
| 68 | 67 | # create the directory where we will put the files |
| 69 | | if not os.path.exists(soas_dir): |
| 70 | | os.mkdir(soas_dir) |
| | 68 | if not os.path.exists(identifier_dir): |
| | 69 | os.mkdir(identifier_dir) |
| 71 | 70 | # check if a serial file exists, it might be from a failed registration |
| 72 | 71 | # let's delete it first |
| 73 | | if os.path.exists(os.path.join(soas_dir, 'sn')): |
| 74 | | os.remove(os.path.join(soas_dir, 'sn')) |
| | 72 | if os.path.exists(os.path.join(identifier_dir, 'sn')): |
| | 73 | os.remove(os.path.join(identifier_dir, 'sn')) |
| 75 | 74 | # write the serial into a file |
| 76 | | serial_file = open(os.path.join(soas_dir, 'sn'),'w') |
| | 75 | serial_file = open(os.path.join(identifier_dir, 'sn'),'w') |
| 77 | 76 | serial_file.write(sn) |
| 78 | 77 | serial_file.close() |
| 79 | 78 | # check if a uuid file exists, it might be from a failed registration |
| 80 | 79 | # let's delete it first |
| 81 | | if os.path.exists(os.path.join(soas_dir, 'uuid')): |
| 82 | | os.remove(os.path.join(soas_dir, 'uuid')) |
| | 80 | if os.path.exists(os.path.join(identifier_dir, 'uuid')): |
| | 81 | os.remove(os.path.join(identifier_dir, 'uuid')) |
| 83 | 82 | # write the uuid into a file |
| 84 | | uuid_file = open(os.path.join(soas_dir, 'uuid'),'w') |
| | 83 | uuid_file = open(os.path.join(identifier_dir, 'uuid'),'w') |
| 85 | 84 | uuid_file.write(uuid) |
| 86 | 85 | uuid_file.close() |
| 87 | | if os.path.exists(os.path.join(soas_dir, 'backup_url')): |
| 88 | | os.remove(os.path.join(soas_dir, 'backup_url')) |
| | 86 | if os.path.exists(os.path.join(identifier_dir, 'backup_url')): |
| | 87 | os.remove(os.path.join(identifier_dir, 'backup_url')) |
| 89 | 88 | # write the backup_url to a file |
| 90 | | bu_file = open(os.path.join(soas_dir, 'backup_url'),'w') |
| | 89 | bu_file = open(os.path.join(identifier_dir, 'backup_url'),'w') |
| 91 | 90 | bu_file.write(backup_url) |
| 92 | 91 | bu_file.close() |
| 93 | 92 | |
| … |
… |
|
| 105 | 104 | # logging.error('Registration: Cannot obtain data needed to register.') |
| 106 | 105 | # raise RegisterError(_('Cannot obtain data needed for registration.')) |
| 107 | 106 | |
| 108 | | # SoaS : |
| 109 | 107 | # if we did not find an ofw directory |
| 110 | 108 | # let's generate the serial and uuid from the current time |
| 111 | 109 | # save the generated serial and uuid into files |
| 112 | 110 | |
| 113 | | sn = gen_soas_serial() |
| 114 | | uuid = gen_soas_uuid() |
| | 111 | sn = gen_identifier_serial() |
| | 112 | uuid = gen_identifier_uuid() |
| 115 | 113 | |
| 116 | 114 | # we want to use the text in the jabber server as our registration url |
| 117 | 115 | |
| … |
… |
|
| 119 | 117 | |
| 120 | 118 | # we need to save sn and uuid to work with backups |
| 121 | 119 | |
| 122 | | write_soas_info(sn,uuid,JABBER_SERVER) |
| | 120 | write_identifier_info(sn,uuid,JABBER_SERVER) |
| 123 | 121 | |
| 124 | 122 | # override the registration url to use |
| 125 | 123 | |