| 34 | def 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 | |
| 49 | def 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 | |
| 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 | |