summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIsis Lovecruft <isis@torproject.org>2013-02-16 22:57:08 +0000
committerIsis Lovecruft <isis@torproject.org>2013-02-16 23:01:49 +0000
commit0ceaf9ac207e4d0716c0aa9c6bb4b5871d8d7292 (patch)
treeeb70f6edc8ed5a1d2927b0704380e661f3980ff5 /src
parent73d33d4caac1cd5e0be63584f72de92742a2c91a (diff)
Cleaned up versioning to have more easily parsable public methods.
* Changed most of version.py to be in class Version, without importing any twisted code (so that runner.CheckRequirements can check for it first) and so that leap/mx/util/__init__.py can do: import version version = version.Version() to expost only the public methods. * Moved client detection platform code to leap/mx/util/config.py.
Diffstat (limited to 'src')
-rw-r--r--src/leap/mx/util/__init__.py13
-rw-r--r--src/leap/mx/util/version.py158
2 files changed, 88 insertions, 83 deletions
diff --git a/src/leap/mx/util/__init__.py b/src/leap/mx/util/__init__.py
index c8448b0..c4a93b8 100644
--- a/src/leap/mx/util/__init__.py
+++ b/src/leap/mx/util/__init__.py
@@ -1 +1,12 @@
-__all__ = ['config', 'exceptions', 'log', 'net', 'version, storage']
+#-*- encoding: utf-8 -*-
+"""
+leap/mx/util/__init__.py
+------------------------
+Module intialization file for leap.mx.util.
+"""
+
+import version
+version = version.Version()
+
+__all__ = ['config', 'log', 'net', 'storage', 'version']
+
diff --git a/src/leap/mx/util/version.py b/src/leap/mx/util/version.py
index 215876c..c32166f 100644
--- a/src/leap/mx/util/version.py
+++ b/src/leap/mx/util/version.py
@@ -10,92 +10,86 @@ Version information for leap_mx.
@copyright: 2013 Isis Agora Lovecruft
'''
-import os
+from os import getcwd
+from os import path as ospath
+
import sys
-from twisted.python import versions
-
-name = 'leap_mx'
-version = versions.Version(name, 0, 0, 1, None)
-authors = [('Isis Agora Lovecruft', '<isis@leap.se>', '0x2cdb8b35'),]
-git_url = 'https://github.com/isislovecruft/leap_mx/'
-website = 'https://leap.se'
-
-PLATFORMS = {'LINUX': sys.platform.startswith("linux"),
- 'OPENBSD': sys.platform.startswith("openbsd"),
- 'FREEBSD': sys.platform.startswith("freebsd"),
- 'NETBSD': sys.platform.startswith("netbsd"),
- 'DARWIN': sys.platform.startswith("darwin"),
- 'SOLARIS': sys.platform.startswith("sunos"),
- 'WINDOWS': sys.platform.startswith("win32")}
-
-def getClientPlatform(platform_name=None):
- """
- Determine the client's operating system platform. Optionally, if
- :param:`platform_name` is given, check that this is indeed the platform
- we're operating on.
-
- @param platform_name: A string, upper-, lower-, or mixed case, of one of
- the keys in the :attr:`leap.util.version.PLATFORMS` dictionary. E.g.
- 'Linux' or 'OPENBSD', etc.
- @returns: A string specifying the platform name, and the boolean test used
- to determine it.
- """
- for name, test in PLATFORMS.items():
- if not platform_name or platform_name.upper() == name:
- if test:
- return name, test
-
-def getVersion():
- """
- Returns a version object, with attributes authors, git_url, and website.
- """
- version.authors = authors
- version.git_url = git_url
- version.website = website
- return version
-
-def getRepoDir():
- """
- Get the top-level repository directory.
- """
- here = os.getcwd()
- base = here.rsplit(name, 1)[0]
- repo = os.path.join(base, name)
- return repo
-
-def __make_text__(extra_text=None):
- splitter = "-" * len(version.__str__())
- header = ["\n%s\n" % version.__str__(), "%s\n" % splitter]
- footer = ["Website: \t%s\n" % website, "Github: \t%s\n" % git_url, "\n"]
- contacts = ["\t%s, %s %s\n" % (a[0], a[1], a[2]) for a in authors]
- contacts.insert(0, "Authors: ")
-
- with_contacts = header + contacts
-
- if extra_text is not None:
- if isinstance(extra_text, iter):
- with_contacts.extend((e for e in extra_text))
- elif isinstance(extra_text, str):
- with_contacts.append(extra_text)
- else:
- print "Couldn't add extra text..."
-
- text = with_contacts + footer
- return text
-
-def __update_version__():
- repo = getRepoDir()
- version_file = os.path.join(repo, 'VERSION')
- version_text = __make_text__()
-
- with open(version_file, 'w+') as fh:
- fh.writelines((line for line in version_text))
- fh.flush()
- fh.truncate()
+
+class Version(object):
+ def __init__(self):
+ self.name = 'leap_mx'
+ self.version = '0.0.2'
+ self.pipfile = ospath.join(self.getRepoDir(),
+ 'pkg/mx-requirements.pip')
+ self.authors = [
+ ('Isis Agora Lovecruft', '<isis@leap.se>', '0x2cdb8b35'),
+ ]
+ self.git_url = 'https://github.com/isislovecruft/leap_mx/'
+ self.website = 'https://leap.se'
+
+ def getPackageName(self):
+ """Returns the application name."""
+ return self.name
+
+ def getPipfile(self):
+ """Returns the full path of the pip requirements.txt file."""
+ return self.pipfile
+
+ def getVersion(self):
+ """Returns a version the application name and version number."""
+ return self.version
+
+ def getAuthors(self):
+ credits = str()
+ for author in self.authors:
+ credits += " ".join(author)
+ return credits
+
+ def getRepoDir(self):
+ """Get the top-level repository directory."""
+ here = getcwd()
+ base = here.rsplit(self.name, 1)[0]
+ repo = ospath.join(base, self.name)
+ return repo
+
+ def __make_text__(self, extra_text=None):
+ splitr = "-" * len(self.version.__str__())
+ header = ["\n%s\n" % self.version.__str__(),
+ "%s\n" % splitr]
+ footer = ["Website: \t%s\n" % self.website,
+ "Github: \t%s\n" % self.git_url,
+ "\n"]
+ contacts = ["\t%s, %s %s\n"
+ % (a[0], a[1], a[2]) for a in self.authors]
+ contacts.insert(0, "Authors: ")
+
+ with_contacts = header + contacts
+
+ if extra_text is not None:
+ if isinstance(extra_text, iter):
+ with_contacts.extend((e for e in extra_text))
+ elif isinstance(extra_text, str):
+ with_contacts.append(extra_text)
+ else:
+ print "Couldn't add extra text..."
+
+ text = with_contacts + footer
+ return text
+
+ def __update_version__(self):
+ repo = self.getRepoDir()
+ self.version_file = ospath.join(repo, 'VERSION')
+ version_text = self.__make_text__()
+
+ with open(self.version_file, 'w+') as fh:
+ fh.writelines((line for line in version_text))
+ fh.flush()
+ fh.truncate()
if __name__ == "__main__":
print "Generating new VERSION file..."
- __update_version__()
+ vrsn = Version()
+ vrsn.__update_version__()
print "Done."