~toolpart/+junk/pythoncard

« back to all changes in this revision

Viewing changes to samples/life/util.py

  • Committer: Bazaar Package Importer
  • Author(s): Sandro Tosi
  • Date: 2010-03-04 23:55:10 UTC
  • mfrom: (3.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20100304235510-3v6lbhzwrgm0pcca
Tags: 0.8.2-1
* QA upload.
* New upstream release
* debian/control
  - set maintainer to QA group
  - set Homepage field, removing the URL from packages description
  - bump versioned b-d-i on python-support, to properly support Python module
  - replace b-d on python-all-dev with python-all, since building only
    arch:all packages
  - replace Source-Version substvar with source:Version
  - add ${misc:Depends} to binary packages Depends
* debian/watch
  - updated to use the SourceForge redirector; thanks to Raphael Geissert for
    the report and to Dario Minnucci for the patch; Closes: #449904
* debian/{pythoncard-doc, python-pythoncard}.install
  - use wildcards instead of site-packages to fix build with python 2.6;
    thanks to Ilya Barygin for the report and patch; Closes: #572332
* debian/pythoncard-doc.doc-base
  - set section to Programmin/Python
* debian/pythoncard-tools.menu
  - set menu main section to Applications
* debian/pythoncard-tools.postinst
  - removed, needed only to update the menu, but it's now created by debhelper

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
"""
3
 
__version__ = "$Revision: 1.10 $"
4
 
__date__ = "$Date: 2004/09/28 05:00:26 $"
 
3
__version__ = "$Revision: 1.12 $"
 
4
__date__ = "$Date: 2006/01/24 19:59:35 $"
5
5
"""
6
6
 
7
7
import os
55
55
        fp = open(path)
56
56
        data = fp.readlines()
57
57
        fp.close()
58
 
 
59
 
        if data[0].strip() != '#Life 1.05':
60
 
            return None
61
 
 
62
 
        for line in data[1:]:
63
 
            s = line.strip()
64
 
            if s == '':
65
 
                pass
66
 
            elif s.startswith('#N') or s.startswith('#R'):
67
 
                # assume Conway (Normal) rules for now
68
 
                pass
69
 
            elif s.startswith('#D'):
70
 
                if description == '':
71
 
                    description = s[3:].strip()
72
 
                else:
73
 
                    description += "\n" + s[3:].strip()
74
 
            elif s.startswith('#P'):
75
 
                # beginning of a cell block
76
 
                if pattern != {}:
77
 
                    pattern['size'] = (width, height)
78
 
                    patterns.append(pattern.copy())
79
 
                x, y = s[3:].split(' ')
80
 
                width = 0
81
 
                height = 0
82
 
                pattern = {}
83
 
                pattern['position'] = (int(x), int(y))
84
 
                pattern['rows'] = []
 
58
    except IOError:
 
59
        return None
 
60
    if data[0].strip() != '#Life 1.05':
 
61
        return None
 
62
    for line in data[1:]:
 
63
        s = line.strip()
 
64
        if s == '':
 
65
            pass
 
66
        elif s.startswith('#N') or s.startswith('#R'):
 
67
            # assume Conway (Normal) rules for now
 
68
            pass
 
69
        elif s.startswith('#D'):
 
70
            if description == '':
 
71
                description = s[3:].strip()
85
72
            else:
86
 
                pattern['rows'].append(s)
87
 
                if len(s) > width:
88
 
                    width = len(s)
89
 
                height += 1
90
 
        if pattern != {}:
91
 
            pattern['size'] = (width, height)
92
 
            patterns.append(pattern.copy())
93
 
 
94
 
        left, top, right, bottom = patternDimensions(patterns)
95
 
        #print "bounds", left, top, right, bottom
96
 
        #print "size", abs(right - left), abs(bottom - top)
97
 
        return description, patterns, (left, top), (abs(right - left), abs(bottom - top))
98
 
    except:
99
 
        return None
 
73
                description += "\n" + s[3:].strip()
 
74
        elif s.startswith('#P'):
 
75
            # beginning of a cell block
 
76
            if pattern != {}:
 
77
                pattern['size'] = (width, height)
 
78
                patterns.append(pattern.copy())
 
79
            x, y = s[3:].split(' ')
 
80
            width = 0
 
81
            height = 0
 
82
            pattern = {}
 
83
            pattern['position'] = (int(x), int(y))
 
84
            pattern['rows'] = []
 
85
        else:
 
86
            pattern['rows'].append(s)
 
87
            if len(s) > width:
 
88
                width = len(s)
 
89
            height += 1
 
90
    if pattern != {}:
 
91
        pattern['size'] = (width, height)
 
92
        patterns.append(pattern.copy())
 
93
    left, top, right, bottom = patternDimensions(patterns)
 
94
    #print "bounds", left, top, right, bottom
 
95
    #print "size", abs(right - left), abs(bottom - top)
 
96
    return description, patterns, (left, top), (abs(right - left), abs(bottom - top))
100
97
 
101
98
"""
102
99
test tube baby
146
143
            try:
147
144
                s, desc = s.split(' ')
148
145
                description += "\n" + desc
149
 
            except:
 
146
            except ValueError:
 
147
                # no description
150
148
                pass
151
149
            # beginning of a cell block
152
150
            if pattern == {}: