author | Pascal Volk <neverseen@users.sourceforge.net> |
Wed, 28 Apr 2010 02:24:23 +0000 | |
branch | v0.6.x |
changeset 267 | 084300a00ee1 |
parent 266 | e14c345b44a1 |
child 273 | 77fc7138ef6a |
permissions | -rw-r--r-- |
262
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
1 |
# -*- coding: UTF-8 -*- |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
2 |
# Copyright (c) 2010, Pascal Volk |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
3 |
# See COPYING for distribution information. |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
4 |
|
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
5 |
""" |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
6 |
VirtualMailManager.common |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
7 |
|
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
8 |
Some common functions |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
9 |
""" |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
10 |
|
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
11 |
import os |
263
07fdc93dde9f
VMM/common: improved version_hex() in order to convert also
Pascal Volk <neverseen@users.sourceforge.net>
parents:
262
diff
changeset
|
12 |
import re |
262
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
13 |
|
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
14 |
from VirtualMailManager import ENCODING |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
15 |
from VirtualMailManager.constants.ERROR import \ |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
16 |
NOT_EXECUTABLE, NO_SUCH_BINARY, NO_SUCH_DIRECTORY |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
17 |
from VirtualMailManager.errors import VMMError |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
18 |
|
265
3c0173418d5d
VMM/{Account,common,maillocation}: Dovecot version (check) fixes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
263
diff
changeset
|
19 |
|
3c0173418d5d
VMM/{Account,common,maillocation}: Dovecot version (check) fixes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
263
diff
changeset
|
20 |
_version_re = re.compile(r'^(\d+)\.(\d+)\.(?:(\d+)|(alpha|beta|rc)(\d+))$') |
266
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
21 |
_version_level = dict(alpha=0xA, beta=0xB, rc=0xC) |
262
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
22 |
_ = lambda msg: msg |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
23 |
|
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
24 |
|
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
25 |
def expand_path(path): |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
26 |
"""Expands paths, starting with ``.`` or ``~``, to an absolute path.""" |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
27 |
if path.startswith('.'): |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
28 |
return os.path.abspath(path) |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
29 |
if path.startswith('~'): |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
30 |
return os.path.expanduser(path) |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
31 |
return path |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
32 |
|
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
33 |
|
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
34 |
def get_unicode(string): |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
35 |
"""Converts `string` to `unicode`, if necessary.""" |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
36 |
if isinstance(string, unicode): |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
37 |
return string |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
38 |
return unicode(string, ENCODING, 'replace') |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
39 |
|
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
40 |
|
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
41 |
def is_dir(path): |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
42 |
"""Checks if `path` is a directory. |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
43 |
|
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
44 |
Throws a `VMMError` if `path` is not a directory. |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
45 |
""" |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
46 |
path = expand_path(path) |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
47 |
if not os.path.isdir(path): |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
48 |
raise VMMError(_(u"'%s' is not a directory") % get_unicode(path), |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
49 |
NO_SUCH_DIRECTORY) |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
50 |
return path |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
51 |
|
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
52 |
|
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
53 |
def exec_ok(binary): |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
54 |
"""Checks if the `binary` exists and if it is executable. |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
55 |
|
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
56 |
Throws a `VMMError` if the `binary` isn't a file or is not |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
57 |
executable. |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
58 |
""" |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
59 |
binary = expand_path(binary) |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
60 |
if not os.path.isfile(binary): |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
61 |
raise VMMError(_(u"'%s' is not a file") % get_unicode(binary), |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
62 |
NO_SUCH_BINARY) |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
63 |
if not os.access(binary, os.X_OK): |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
64 |
raise VMMError(_(u"File is not executable: '%s'") % |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
65 |
get_unicode(binary), NOT_EXECUTABLE) |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
66 |
return binary |
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
67 |
|
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
68 |
|
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
69 |
def version_hex(version_string): |
266
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
70 |
"""Converts a Dovecot version, e.g.: '1.2.3' or '2.0.beta4', to an int. |
265
3c0173418d5d
VMM/{Account,common,maillocation}: Dovecot version (check) fixes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
263
diff
changeset
|
71 |
Raises a `ValueError` if the *version_string* has the wrong™ format. |
263
07fdc93dde9f
VMM/common: improved version_hex() in order to convert also
Pascal Volk <neverseen@users.sourceforge.net>
parents:
262
diff
changeset
|
72 |
|
266
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
73 |
version_hex('1.2.3') -> 270548736 |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
74 |
hex(version_hex('1.2.3')) -> '0x10203f00' |
262
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
75 |
""" |
263
07fdc93dde9f
VMM/common: improved version_hex() in order to convert also
Pascal Volk <neverseen@users.sourceforge.net>
parents:
262
diff
changeset
|
76 |
version = 0 |
265
3c0173418d5d
VMM/{Account,common,maillocation}: Dovecot version (check) fixes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
263
diff
changeset
|
77 |
version_mo = _version_re.match(version_string) |
3c0173418d5d
VMM/{Account,common,maillocation}: Dovecot version (check) fixes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
263
diff
changeset
|
78 |
if not version_mo: |
3c0173418d5d
VMM/{Account,common,maillocation}: Dovecot version (check) fixes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
263
diff
changeset
|
79 |
raise ValueError('Invalid version string: %r' % version_string) |
3c0173418d5d
VMM/{Account,common,maillocation}: Dovecot version (check) fixes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
263
diff
changeset
|
80 |
major, minor, patch, level, serial = version_mo.groups() |
266
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
81 |
major = int(major) |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
82 |
minor = int(minor) |
265
3c0173418d5d
VMM/{Account,common,maillocation}: Dovecot version (check) fixes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
263
diff
changeset
|
83 |
if patch: |
266
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
84 |
patch = int(patch) |
265
3c0173418d5d
VMM/{Account,common,maillocation}: Dovecot version (check) fixes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
263
diff
changeset
|
85 |
if serial: |
266
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
86 |
serial = int(serial) |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
87 |
|
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
88 |
if major > 0xFF or minor > 0xFF or \ |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
89 |
patch and patch > 0xFF or serial and serial > 0xFF: |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
90 |
raise ValueError('Invalid version string: %r' % version_string) |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
91 |
|
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
92 |
version += major << 28 |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
93 |
version += minor << 20 |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
94 |
if patch: |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
95 |
version += patch << 12 |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
96 |
version += _version_level.get(level, 0xF) << 8 |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
97 |
if serial: |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
98 |
version += serial |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
99 |
|
263
07fdc93dde9f
VMM/common: improved version_hex() in order to convert also
Pascal Volk <neverseen@users.sourceforge.net>
parents:
262
diff
changeset
|
100 |
return version |
262
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
101 |
|
266
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
102 |
|
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
103 |
def version_str(version): |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
104 |
"""Converts a Dovecot version previously converted with version_hex back to |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
105 |
a string. |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
106 |
Raises a `TypeError` if *version* is not an int/long. |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
107 |
Raises a `ValueError` if *version* is an incorrect int version. |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
108 |
""" |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
109 |
if not isinstance(version, (int, long)): |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
110 |
raise TypeError('Argument is not a int/long: %r', version) |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
111 |
major = (version >> 28) & 0xFF |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
112 |
minor = (version >> 20) & 0xFF |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
113 |
patch = (version >> 12) & 0xFF |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
114 |
level = (version >> 8) & 0x0F |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
115 |
serial = version & 0xFF |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
116 |
|
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
117 |
levels = dict(zip(_version_level.values(), _version_level.keys())) |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
118 |
if level == 0xF and not serial: |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
119 |
version_string = '%u.%u.%u' % (major, minor, patch) |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
120 |
elif level in levels and not patch: |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
121 |
version_string = '%u.%u.%s%u' % (major, minor, levels[level], serial) |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
122 |
else: |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
123 |
raise ValueError('Invalid version: %r' % hex(version)) |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
124 |
|
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
125 |
return version_string |
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
265
diff
changeset
|
126 |
|
262
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
127 |
del _ |