Ticket #916: 0002-use-instead-of-hardcoding-the-home-dir-put-files.patch

File 0002-use-instead-of-hardcoding-the-home-dir-put-files.patch, 4.6 KB (added by hamiltonchua, 7 months ago)
  • src/jarabe/desktop/schoolserver.py

    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  
    1818from gettext import gettext as _ 
    1919from xmlrpclib import ServerProxy, Error 
    2020import socket 
    21 import os 
     21import os,os.path 
    2222import gconf 
    2323 
    2424import string, random, time 
     
    3131 
    3232REGISTER_URL = 'http://schoolserver:8080/' 
    3333 
    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 
    3635 
    3736# utilities ******************************************************************** 
    3837 
     
    4746# - we randomly get 3 letters 
    4847# - concat the above with the last 8 numbers from epoch seconds 
    4948 
    50 def gen_soas_serial(): 
     49def gen_identifier_serial(): 
    5150  s1 = ''.join([random.choice(string.ascii_uppercase) for y in range(3)]) 
    5251  s2 = str(int(getEpoch()))[-8:] 
    5352  serial = s1 + s2  
     
    5554 
    5655# to create a unique uuid 
    5756 
    58 def gen_soas_uuid(): 
     57def gen_identifier_uuid(): 
    5958  u1_count = 40  
    6059  uuid = ''.join([random.choice(string.hexdigits + '-') for y in range(int(u1_count))]) 
    6160  return uuid 
    6261 
    6362# write serial and uuid to file ************************************************ 
    6463 
    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/' 
     64def 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' 
    6867  # 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) 
    7170  # check if a serial file exists, it might be from a failed registration 
    7271  # 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')) 
    7574  # 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') 
    7776  serial_file.write(sn) 
    7877  serial_file.close() 
    7978  # check if a uuid file exists, it might be from a failed registration 
    8079  # 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')) 
    8382  # 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') 
    8584  uuid_file.write(uuid) 
    8685  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')) 
    8988  # 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') 
    9190  bu_file.write(backup_url) 
    9291  bu_file.close() 
    9392 
     
    105104        # logging.error('Registration: Cannot obtain data needed to register.') 
    106105        # raise RegisterError(_('Cannot obtain data needed for registration.')) 
    107106 
    108         # SoaS  : 
    109107        # if we did not find an ofw directory 
    110108        # let's generate the serial and uuid from the current time  
    111109        # save the generated serial and uuid into files 
    112110 
    113         sn = gen_soas_serial() 
    114         uuid = gen_soas_uuid() 
     111        sn = gen_identifier_serial() 
     112        uuid = gen_identifier_uuid() 
    115113 
    116114        # we want to use the text in the jabber server as our registration url 
    117115 
     
    119117 
    120118        # we need to save sn and uuid to work with backups 
    121119 
    122         write_soas_info(sn,uuid,JABBER_SERVER) 
     120        write_identifier_info(sn,uuid,JABBER_SERVER) 
    123121 
    124122        # override the registration url to use 
    125123