2
# -*- coding: iso8859-1 -*-
4
##############################################################################
5
# cmd_genuid.py - Ensymble command line tool, genuid command
6
# Copyright 2006, 2007, 2008, 2009 Jussi Ylänen
8
# This file is part of Ensymble developer utilities for Symbian OS(TM).
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.
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.
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
##############################################################################
34
##############################################################################
36
##############################################################################
38
shorthelp = 'Generate a new test-range UID from a name'
40
[--encoding=terminal,filesystem] [--verbose]
43
Generate a new test-range UID from a name.
46
name - Name used for UID generation
47
encoding - Local character encodings for terminal and filesystem
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".
57
##############################################################################
58
# Public module-level functions
59
##############################################################################
61
def run(pgmname, argv):
64
# Determine system character encodings.
66
# getdefaultlocale() may sometimes return None.
67
# Fall back to ASCII encoding in that case.
68
terminalenc = locale.getdefaultlocale()[1] + ""
70
# Invalid locale, fall back to ASCII terminal encoding.
74
# sys.getfilesystemencoding() was introduced in Python v2.3 and
75
# it can sometimes return None. Fall back to ASCII if something
77
filesystemenc = sys.getfilesystemencoding() + ""
78
except (AttributeError, TypeError):
79
filesystemenc = "ascii"
82
gopt = getopt.gnu_getopt
84
# Python <v2.3, GNU-style parameter ordering not supported.
89
"encoding=", "verbose", "debug", "help"
91
args = gopt(argv, short_opts, long_opts)
97
raise ValueError("no name given")
99
# Override character encoding of command line and filesystem.
100
encs = opts.get("--encoding", opts.get("-e", "%s,%s" % (terminalenc,
103
terminalenc, filesystemenc = encs.split(",")
104
except (ValueError, TypeError):
105
raise ValueError("invalid encoding string '%s'" % encs)
107
# Convert name(s) to Unicode.
108
names = [name.decode(terminalenc) for name in pargs]
110
# Determine verbosity.
112
if "--verbose" in opts.keys() or "-v" in opts.keys():
115
# Determine if debug output is requested.
116
if "--debug" in opts.keys():
119
# Ingredients for successful UID generation:
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)
127
# Auto-generate a test-range UID from name.
128
autouid = symbianutil.uidfromname(name)
130
print "%s: 0x%08x" % (name.decode(filesystemenc).encode(terminalenc),