0
|
1 |
#!/usr/bin/env python
|
|
2 |
# -*- coding: iso8859-1 -*-
|
|
3 |
|
|
4 |
##############################################################################
|
|
5 |
# cmd_genuid.py - Ensymble command line tool, genuid command
|
|
6 |
# Copyright 2006, 2007, 2008, 2009 Jussi Ylänen
|
|
7 |
#
|
|
8 |
# This file is part of Ensymble developer utilities for Symbian OS(TM).
|
|
9 |
#
|
|
10 |
# Ensymble is free software; you can redistribute it and/or modify
|
|
11 |
# it under the terms of the GNU General Public License as published by
|
|
12 |
# the Free Software Foundation; either version 2 of the License, or
|
|
13 |
# (at your option) any later version.
|
|
14 |
#
|
|
15 |
# Ensymble is distributed in the hope that it will be useful,
|
|
16 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18 |
# GNU General Public License for more details.
|
|
19 |
#
|
|
20 |
# You should have received a copy of the GNU General Public License
|
|
21 |
# along with Ensymble; if not, write to the Free Software
|
|
22 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
23 |
##############################################################################
|
|
24 |
|
|
25 |
import sys
|
|
26 |
import os
|
|
27 |
import getopt
|
|
28 |
import locale
|
|
29 |
import struct
|
|
30 |
|
|
31 |
import symbianutil
|
|
32 |
|
|
33 |
|
|
34 |
##############################################################################
|
|
35 |
# Help texts
|
|
36 |
##############################################################################
|
|
37 |
|
|
38 |
shorthelp = 'Generate a new test-range UID from a name'
|
|
39 |
longhelp = '''genuid
|
|
40 |
[--encoding=terminal,filesystem] [--verbose]
|
|
41 |
<name>...
|
|
42 |
|
|
43 |
Generate a new test-range UID from a name.
|
|
44 |
|
|
45 |
Options:
|
|
46 |
name - Name used for UID generation
|
|
47 |
encoding - Local character encodings for terminal and filesystem
|
|
48 |
verbose - Not used
|
|
49 |
|
|
50 |
Generated UID is compatible with the automatic UID generation of py2sis
|
|
51 |
and simplesis commands. The name must not contain version information or
|
|
52 |
any file prefixes, just the name itself, e.g. "mymodule" instead of
|
|
53 |
"mymodule_v1.2.3.sis".
|
|
54 |
'''
|
|
55 |
|
|
56 |
|
|
57 |
##############################################################################
|
|
58 |
# Public module-level functions
|
|
59 |
##############################################################################
|
|
60 |
|
|
61 |
def run(pgmname, argv):
|
|
62 |
global debug
|
|
63 |
|
|
64 |
# Determine system character encodings.
|
|
65 |
try:
|
|
66 |
# getdefaultlocale() may sometimes return None.
|
|
67 |
# Fall back to ASCII encoding in that case.
|
|
68 |
terminalenc = locale.getdefaultlocale()[1] + ""
|
|
69 |
except TypeError:
|
|
70 |
# Invalid locale, fall back to ASCII terminal encoding.
|
|
71 |
terminalenc = "ascii"
|
|
72 |
|
|
73 |
try:
|
|
74 |
# sys.getfilesystemencoding() was introduced in Python v2.3 and
|
|
75 |
# it can sometimes return None. Fall back to ASCII if something
|
|
76 |
# goes wrong.
|
|
77 |
filesystemenc = sys.getfilesystemencoding() + ""
|
|
78 |
except (AttributeError, TypeError):
|
|
79 |
filesystemenc = "ascii"
|
|
80 |
|
|
81 |
try:
|
|
82 |
gopt = getopt.gnu_getopt
|
|
83 |
except:
|
|
84 |
# Python <v2.3, GNU-style parameter ordering not supported.
|
|
85 |
gopt = getopt.getopt
|
|
86 |
|
|
87 |
short_opts = "e:vh"
|
|
88 |
long_opts = [
|
|
89 |
"encoding=", "verbose", "debug", "help"
|
|
90 |
]
|
|
91 |
args = gopt(argv, short_opts, long_opts)
|
|
92 |
|
|
93 |
opts = dict(args[0])
|
|
94 |
pargs = args[1]
|
|
95 |
|
|
96 |
if len(pargs) == 0:
|
|
97 |
raise ValueError("no name given")
|
|
98 |
|
|
99 |
# Override character encoding of command line and filesystem.
|
|
100 |
encs = opts.get("--encoding", opts.get("-e", "%s,%s" % (terminalenc,
|
|
101 |
filesystemenc)))
|
|
102 |
try:
|
|
103 |
terminalenc, filesystemenc = encs.split(",")
|
|
104 |
except (ValueError, TypeError):
|
|
105 |
raise ValueError("invalid encoding string '%s'" % encs)
|
|
106 |
|
|
107 |
# Convert name(s) to Unicode.
|
|
108 |
names = [name.decode(terminalenc) for name in pargs]
|
|
109 |
|
|
110 |
# Determine verbosity.
|
|
111 |
verbose = False
|
|
112 |
if "--verbose" in opts.keys() or "-v" in opts.keys():
|
|
113 |
verbose = True
|
|
114 |
|
|
115 |
# Determine if debug output is requested.
|
|
116 |
if "--debug" in opts.keys():
|
|
117 |
debug = True
|
|
118 |
|
|
119 |
# Ingredients for successful UID generation:
|
|
120 |
#
|
|
121 |
# terminalenc Terminal character encoding (autodetected)
|
|
122 |
# filesystemenc File system name encoding (autodetected)
|
|
123 |
# names Names to generate the UID from, filesystemenc encoded
|
|
124 |
# verbose Boolean indicating verbose terminal output (no-op)
|
|
125 |
|
|
126 |
for name in names:
|
|
127 |
# Auto-generate a test-range UID from name.
|
|
128 |
autouid = symbianutil.uidfromname(name)
|
|
129 |
|
|
130 |
print "%s: 0x%08x" % (name.decode(filesystemenc).encode(terminalenc),
|
|
131 |
autouid)
|