~ubuntu-branches/ubuntu/saucy/pysolfc/saucy-proposed

« back to all changes in this revision

Viewing changes to .pc/pillow/pysollib/mfxutil.py

  • Committer: Package Import Robot
  • Author(s): Bernhard Reiter
  • Date: 2013-04-17 08:10:25 UTC
  • Revision ID: package-import@ubuntu.com-20130417081025-no2panc62u0pe9xm
Tags: 2.0-3
* debian/copyright:
  - Change Format from DEP-5 to copyright-format/1.0 link.
  - Point to GFDL-1.3 instead of just GFDL.
* debian/control:
  - Remove Replaces: and Conflicts: lines as those packages aren't in
    Debian anymore.
  - Remove X-Python-Version line.
  - Switch to canonical Vcs-* fields.
  - Bump Standards-Version to 3.9.4.
  - Bump debhelper Build-Depends to >= 9.
* debian/compat: Bump to 9.
* debian/control, debian/rules:
  - Drop transitional pysol package now that wheezy is out.
* debian/rules:
  - Fix order of arguments for the dh command.
  - Delete COPYRIGHT files in the override_dh_auto_install (instead of the
    override_dh_auto_install) section.
* debian/pysolfc.install: Remove.
* debian/patches/pillow, debian/patches/series: Fix PIL imports for pillow
  compatibility -- see 5117D0B7.801@debian.org (LP: 1160571).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# -*- mode: python; coding: utf-8; -*-
 
3
##---------------------------------------------------------------------------##
 
4
##
 
5
## Copyright (C) 1998-2003 Markus Franz Xaver Johannes Oberhumer
 
6
## Copyright (C) 2003 Mt. Hood Playing Card Co.
 
7
## Copyright (C) 2005-2009 Skomoroh
 
8
##
 
9
## This program is free software: you can redistribute it and/or modify
 
10
## it under the terms of the GNU General Public License as published by
 
11
## the Free Software Foundation, either version 3 of the License, or
 
12
## (at your option) any later version.
 
13
##
 
14
## This program is distributed in the hope that it will be useful,
 
15
## but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
## GNU General Public License for more details.
 
18
##
 
19
## You should have received a copy of the GNU General Public License
 
20
## along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
21
##
 
22
##---------------------------------------------------------------------------##
 
23
 
 
24
 
 
25
# imports
 
26
import sys, os, time, types, locale
 
27
import webbrowser
 
28
 
 
29
try:
 
30
    from cPickle import Pickler, Unpickler, UnpicklingError
 
31
except ImportError:
 
32
    from pickle import Pickler, Unpickler, UnpicklingError
 
33
 
 
34
try:
 
35
    import thread
 
36
except:
 
37
    thread = None
 
38
 
 
39
from settings import PACKAGE, TOOLKIT
 
40
 
 
41
Image = ImageTk = ImageOps = None
 
42
if TOOLKIT == 'tk':
 
43
    try: # PIL
 
44
        import Image
 
45
        import ImageTk
 
46
        import ImageOps
 
47
    except ImportError:
 
48
        Image = None
 
49
    else:
 
50
        # for py2exe
 
51
        import GifImagePlugin
 
52
        import PngImagePlugin
 
53
        import JpegImagePlugin
 
54
        import BmpImagePlugin
 
55
        import PpmImagePlugin
 
56
        Image._initialized = 2
 
57
 
 
58
 
 
59
# ************************************************************************
 
60
# * exceptions
 
61
# ************************************************************************
 
62
 
 
63
class SubclassResponsibility(Exception):
 
64
    pass
 
65
 
 
66
 
 
67
# ************************************************************************
 
68
# * misc. util
 
69
# ************************************************************************
 
70
 
 
71
 
 
72
def latin1_to_ascii(n):
 
73
    #return n
 
74
    n = n.encode('iso8859-1', 'replace')
 
75
    ## FIXME: rewrite this for better speed
 
76
    n = (n.replace("\xc4", "Ae")
 
77
         .replace("\xd6", "Oe")
 
78
         .replace("\xdc", "Ue")
 
79
         .replace("\xe4", "ae")
 
80
         .replace("\xf6", "oe")
 
81
         .replace("\xfc", "ue"))
 
82
    return n
 
83
 
 
84
 
 
85
def format_time(t):
 
86
    ##print 'format_time:', t
 
87
    if t <= 0: return "0:00"
 
88
    if t < 3600: return "%d:%02d" % (t / 60, t % 60)
 
89
    return "%d:%02d:%02d" % (t / 3600, (t % 3600) / 60, t % 60)
 
90
 
 
91
 
 
92
def print_err(s, level=1):
 
93
    if level == 0:
 
94
        ss = PACKAGE+': ERROR:'
 
95
    elif level == 1:
 
96
        ss = PACKAGE+': WARNING:'
 
97
    elif level == 2:
 
98
        ss = PACKAGE+': DEBUG WARNING:'
 
99
    print >> sys.stderr, ss, s.encode(locale.getpreferredencoding())
 
100
    sys.stderr.flush()
 
101
 
 
102
 
 
103
# ************************************************************************
 
104
# * misc. portab stuff
 
105
# ************************************************************************
 
106
 
 
107
def getusername():
 
108
    if os.name == "nt":
 
109
        return win32_getusername()
 
110
    user = os.environ.get("USER","").strip()
 
111
    if not user:
 
112
        user = os.environ.get("LOGNAME","").strip()
 
113
    return user
 
114
 
 
115
 
 
116
def getprefdir(package):
 
117
    if os.name == "nt":
 
118
        return win32_getprefdir(package)
 
119
    home = os.environ.get("HOME", "").strip()
 
120
    if not home or not os.path.isdir(home):
 
121
        home = os.curdir
 
122
    return os.path.join(home, ".pysolfc")
 
123
 
 
124
 
 
125
# high resolution clock() and sleep()
 
126
uclock = time.clock
 
127
usleep = time.sleep
 
128
if os.name == "posix":
 
129
    uclock = time.time
 
130
 
 
131
# ************************************************************************
 
132
# * MSWin util
 
133
# ************************************************************************
 
134
 
 
135
def win32_getusername():
 
136
    user = os.environ.get('USERNAME','').strip()
 
137
    try:
 
138
        user = unicode(user, locale.getpreferredencoding())
 
139
    except:
 
140
        user = ''
 
141
    return user
 
142
 
 
143
def win32_getprefdir(package):
 
144
    portprefdir = 'config'      # portable varsion
 
145
    if os.path.isdir(portprefdir):
 
146
        return portprefdir
 
147
    # %USERPROFILE%, %APPDATA%
 
148
    hd = os.environ.get('APPDATA')
 
149
    if not hd:
 
150
        hd = os.path.expanduser('~')
 
151
        if hd == '~': # win9x
 
152
            hd = os.path.abspath('/windows/Application Data')
 
153
            if not os.path.exists(hd):
 
154
                hd = os.path.abspath('/')
 
155
    return os.path.join(hd, 'PySolFC')
 
156
 
 
157
 
 
158
# ************************************************************************
 
159
# * memory util
 
160
# ************************************************************************
 
161
 
 
162
def destruct(obj):
 
163
    # assist in breaking circular references
 
164
    if obj is not None:
 
165
        assert isinstance(obj, types.InstanceType)
 
166
        for k in obj.__dict__.keys():
 
167
            obj.__dict__[k] = None
 
168
            ##del obj.__dict__[k]
 
169
 
 
170
 
 
171
# ************************************************************************
 
172
# *
 
173
# ************************************************************************
 
174
 
 
175
class Struct:
 
176
    def __init__(self, **kw):
 
177
        self.__dict__.update(kw)
 
178
 
 
179
    def __str__(self):
 
180
        return str(self.__dict__)
 
181
 
 
182
    def __setattr__(self, key, value):
 
183
        if key not in self.__dict__:
 
184
            raise AttributeError(key)
 
185
        self.__dict__[key] = value
 
186
 
 
187
    def addattr(self, **kw):
 
188
        for key in kw.keys():
 
189
            if hasattr(self, key):
 
190
                raise AttributeError(key)
 
191
        self.__dict__.update(kw)
 
192
 
 
193
    def update(self, dict):
 
194
        for key in dict.keys():
 
195
            if key not in self.__dict__:
 
196
                raise AttributeError(key)
 
197
        self.__dict__.update(dict)
 
198
 
 
199
    def clear(self):
 
200
        for key in self.__dict__.keys():
 
201
            if isinstance(key, list):
 
202
                self.__dict__[key] = []
 
203
            elif isinstance(key, tuple):
 
204
                self.__dict__[key] = ()
 
205
            elif isinstance(key, dict):
 
206
                self.__dict__[key] = {}
 
207
            else:
 
208
                self.__dict__[key] = None
 
209
 
 
210
    def copy(self):
 
211
        c = self.__class__()
 
212
        c.__dict__.update(self.__dict__)
 
213
        return c
 
214
 
 
215
 
 
216
# ************************************************************************
 
217
# * keyword argument util
 
218
# ************************************************************************
 
219
 
 
220
# update keyword arguments with default arguments
 
221
def kwdefault(kw, **defaults):
 
222
    for k, v in defaults.items():
 
223
        if k not in kw:
 
224
            kw[k] = v
 
225
 
 
226
 
 
227
class KwStruct:
 
228
    def __init__(self, kw={}, **defaults):
 
229
        if isinstance(kw, KwStruct):
 
230
            kw = kw.__dict__
 
231
        if isinstance(defaults, KwStruct):
 
232
            defaults = defaults.__dict__
 
233
        if defaults:
 
234
            kw = kw.copy()
 
235
            for k, v in defaults.items():
 
236
                if k not in kw:
 
237
                    kw[k] = v
 
238
        self.__dict__.update(kw)
 
239
 
 
240
    def __setattr__(self, key, value):
 
241
        if key not in self.__dict__:
 
242
            raise AttributeError(key)
 
243
        self.__dict__[key] = value
 
244
 
 
245
    def __getitem__(self, key):
 
246
        return getattr(self, key)
 
247
 
 
248
    def get(self, key, default=None):
 
249
        return self.__dict__.get(key, default)
 
250
 
 
251
    def getKw(self):
 
252
        return self.__dict__
 
253
 
 
254
 
 
255
# ************************************************************************
 
256
# * pickling support
 
257
# ************************************************************************
 
258
 
 
259
def pickle(obj, filename, protocol=0):
 
260
    f = None
 
261
    try:
 
262
        f = open(filename, "wb")
 
263
        p = Pickler(f, protocol)
 
264
        p.dump(obj)
 
265
        f.close(); f = None
 
266
        ##print "Pickled", filename
 
267
    finally:
 
268
        if f: f.close()
 
269
 
 
270
 
 
271
def unpickle(filename):
 
272
    f, obj = None, None
 
273
    try:
 
274
        f = open(filename, "rb")
 
275
        p = Unpickler(f)
 
276
        x = p.load()
 
277
        f.close(); f = None
 
278
        obj = x
 
279
        ##print "Unpickled", filename
 
280
    finally:
 
281
        if f: f.close()
 
282
    return obj
 
283
 
 
284
 
 
285
# ************************************************************************
 
286
# *
 
287
# ************************************************************************
 
288
 
 
289
def openURL(url):
 
290
    try:
 
291
        webbrowser.open(url)
 
292
    except OSError:                  # raised on windows if link is unreadable
 
293
        pass
 
294
    except:
 
295
        return 0
 
296
    return 1
 
297