Attachments you submit will be routed for moderation. If you have an account, please log in first.

Ticket #916: register-non-xo-with-xs.patch

File register-non-xo-with-xs.patch, 3.4 KB (added by hamiltonchua, 4 years ago)
  • src/jarabe/desktop/schoolserver.py

    diff --git a/src/jarabe/desktop/schoolserver.py b/src/jarabe/desktop/schoolserver.py
    index f09469f..672375f 100644
    a b  
    1919from xmlrpclib import ServerProxy, Error 
    2020import socket 
    2121import os 
     22import string 
     23import random 
     24import time 
     25import uuid 
     26 
    2227import gconf 
    2328 
     29from sugar import env 
    2430from sugar.profile import get_profile 
    2531 
    2632REGISTER_URL = 'http://schoolserver:8080/' 
    2733 
     34def generate_serial_number(): 
     35    """  Generates a serial number based on 3 random uppercase letters  
     36    and the last 8 digits of the current unix seconds. """ 
     37 
     38    serial_part1 = [] 
     39 
     40    for y in range(3) : 
     41        serial_part1.append(random.choice(string.ascii_uppercase)) 
     42 
     43    serial_part1 = ''.join(serial_part1) 
     44    serial_part2 = str(int(time.time()))[-8:] 
     45    serial = serial_part1 + serial_part2 
     46 
     47    return serial 
     48 
     49def store_identifiers(serial_number, uuid, backup_url): 
     50    """  Stores the serial number, uuid and backup_url 
     51    in the identifier folder inside the profile directory 
     52    so that these identifiers can be used for backup. """ 
     53 
     54    identifier_path = os.path.join(env.get_profile_path(), 'identifiers') 
     55    if not os.path.exists(identifier_path): 
     56        os.mkdir(identifier_path) 
     57 
     58    if os.path.exists(os.path.join(identifier_path, 'sn')): 
     59        os.remove(os.path.join(identifier_path, 'sn')) 
     60    serial_file = open(os.path.join(identifier_path, 'sn'), 'w') 
     61    serial_file.write(serial_number) 
     62    serial_file.close() 
     63 
     64    if os.path.exists(os.path.join(identifier_path, 'uuid')): 
     65        os.remove(os.path.join(identifier_path, 'uuid')) 
     66    uuid_file = open(os.path.join(identifier_path, 'uuid'), 'w') 
     67    uuid_file.write(uuid) 
     68    uuid_file.close() 
     69 
     70    if os.path.exists(os.path.join(identifier_path, 'backup_url')): 
     71        os.remove(os.path.join(identifier_path, 'backup_url')) 
     72    backup_url_file = open(os.path.join(identifier_path, 'backup_url'), 'w') 
     73    backup_url_file.write(backup_url) 
     74    backup_url_file.close() 
     75 
    2876class RegisterError(Exception): 
    2977    pass 
    3078 
    3179def register_laptop(url=REGISTER_URL): 
    32     if not have_ofw_tree(): 
    33         logging.error('Registration: Cannot obtain data needed to register.') 
    34         raise RegisterError(_('Cannot obtain data needed for registration.')) 
    35  
    36     sn = read_ofw('mfg-data/SN') 
    37     uuid = read_ofw('mfg-data/U#') 
    38     sn = sn or 'SHF00000000' 
    39     uuid = uuid or '00000000-0000-0000-0000-000000000000' 
    4080 
    4181    profile = get_profile() 
    42  
    4382    client = gconf.client_get_default() 
     83 
     84    if have_ofw_tree(): 
     85        sn = read_ofw('mfg-data/SN') 
     86        uuid_ = read_ofw('mfg-data/U#') 
     87        sn = sn or 'SHF00000000' 
     88        uuid_ = uuid_ or '00000000-0000-0000-0000-000000000000' 
     89    else: 
     90        sn = generate_serial_number() 
     91        uuid_ = str(uuid.uuid1()) 
     92        jabber_server = client.get_string('/desktop/sugar/collaboration/jabber_server') 
     93        store_identifiers(sn, uuid_, jabber_server) 
     94        url = 'http://' + jabber_server + ':8080/' 
     95 
    4496    nick = client.get_string('/desktop/sugar/user/nick') 
    4597 
    4698    server = ServerProxy(url) 
    4799    try: 
    48         data = server.register(sn, nick, uuid, profile.pubkey) 
     100        data = server.register(sn, nick, uuid_, profile.pubkey) 
    49101    except (Error, socket.error): 
    50102        logging.exception('Registration: cannot connect to server') 
    51103        raise RegisterError(_('Cannot connect to the server.'))