summaryrefslogtreecommitdiff
path: root/cad/src/utilities/version.py
blob: 73d7e543e70f8a831c79d39239a10d5909c9e99e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# Copyright 2005-2008 Nanorex, Inc.  See LICENSE file for details.
"""
version.py -- provide version information for NanoEngineer-1,
including author list, program name, release info, etc.

@author: Will, Mark
@version: $Id$
@copyright: 2005-2008 Nanorex, Inc.  See LICENSE file for details.

NOTE: this is copied and imported by autoBuild.py in a directory
which contains no other files, so it needs to be completely self-contained.
(I.e. it should not import anything else in its source directory,
only builtin Python modules.)

Module classification, and refactoring needed:

This should be given a less generic name, and also split into a
high-level module (since it would differ for different applications
built from the same code base) and low-level global access to the
"currently running app's name and version info"
(perhaps implemented similarly to EndUser)
for uses like printing version info into output files
(as in our caller in files_pdb).

In the meantime, to avoid package import cycles, we pretend this is
entirely low-level and classify it as either utilities or constants.
[bruce 071215]
"""

import NE1_Build_Constants

# Note: __copyright__ and __author__ below are about NE1 as a whole,
# not about this specific file. (In some source files, __author__
# is defined and is about that specific file. That usage of
# __author__ is deprecated, superceded by an @author line in the
# module docstring. [bruce 071215 comment])

__copyright__ = "Copyright 2004-2008, Nanorex, Inc."

# Alphabetical by last name
__author__ = """
Damian Allis
K. Eric Drexler
Russ Fish
Josh Hall
Brian Helfrich
Eric Messick
Huaicai Mo
Tom Moore
Piotr Rotkiewicz
Ninad Sathaye
Mark Sims
Bruce Smith
Will Ware
"""

class Version:
    """
    Example usage:
    from utilities.version import Version
    v = Version()
    print v, v.product, v.authors
    """
    # Every instance of Version will share the same state
    tmpary = NE1_Build_Constants.NE1_RELEASE_VERSION.split(".")
    __shared_state = {
        "major": int(tmpary[0]),
        "minor": int(tmpary[1]),
        "releaseType": "",
        "releaseCandidate": NE1_Build_Constants.NE1_OFFICIAL_RELEASE_CANDIDATE,
        "releaseDate": NE1_Build_Constants.NE1_RELEASE_DATE,
        "product": "NanoEngineer-1",
        "copyright": __copyright__,
        "authors": __author__
        }
    if len(tmpary) >= 3:  #tiny and teensy are both not required in version
        __shared_state["tiny"] = int(tmpary[2])
        if len(tmpary) == 4:
            __shared_state["teensy"] = int(tmpary[3])
    def __init__(self):
        # Use Alex Martelli's singleton recipe
        # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531
        self.__dict__ = self.__shared_state
    def __setattr__(self, attr, value):  # attributes write-protected
        raise AttributeError, attr
    def __repr__(self):
        major = self.__shared_state["major"]
        minor = self.__shared_state["minor"]
        str = "%d.%d" % (major, minor)
        if self.__shared_state.has_key("tiny"):
            teensy = self.__shared_state["tiny"]
            str += ".%d" % teensy
            if self.__shared_state.has_key("teensy"):
                teensy = self.__shared_state["teensy"]
                str += ".%d" % teensy
        return str

###############################

if __name__ == "__main__":
    v = Version()
    print v
    for x in dir(v):
        print x + ":", getattr(v, x)
        print
    # test write protection
    try:
        v.foo = "bar"
        print "WRITE PROTECTION IS BROKEN"
    except AttributeError:
        pass