diff --git a/lazyscripts/constant.py b/lazyscripts/constant.py new file mode 100644 index 0000000..7f57f02 --- /dev/null +++ b/lazyscripts/constant.py @@ -0,0 +1,45 @@ + +##Python +PYTHON_VERSION = '2.6.0' + +### DISTRIBUTION +# Debian base +DIST_DEBIAN = 'debian' +DIST_UBUNTU = 'ubuntu' +DIST_LINUXMINT = 'linuxmint' + +DIST_DEB_BASE = \ + (DIST_DEBIAN, + DIST_UBUNTU, + DIST_LINUXMINT) + + +# RPM Base +DIST_REDHAT = 'redhat' +DIST_CENTOS = 'centos' +DIST_FEDORA = 'fedora' + +DIST_SUSE = 'suse' +DIST_OPENSUSE = 'opensuse' +DIST_MANDRIVA = 'mandriva' + +DIST_RPM_BASE = \ + (DIST_REDHAT, + DIST_CENTOS, + DIST_FEDORA, + DIST_SUSE, + DIST_OPENSUSE, + DIST_MANDRIVA) + +# BSD Base +DIST_MACOSX = 'macosx' + +### Architecture +ARCH_I386 = 'i386' +ARCH_AMD64 = 'amd64' + +### System +SYSTEM_LINUX = 'Linux' +SYSTEM_MAC = 'Darwin' +# not ready +#SYSTEM_BSD = '' diff --git a/lazyscripts/distro.py b/lazyscripts/distro.py index 9aaef4c..4dd63db 100755 --- a/lazyscripts/distro.py +++ b/lazyscripts/distro.py @@ -21,6 +21,7 @@ import platform from lazyscripts import pkgmgr +from lazyscripts.constant import * class DistrobutionNotFound(Exception): "The distrobution can not be detected." @@ -45,7 +46,7 @@ def __repr__(self): def __init__(self): # linux_distribution is insted of dist # Ref: http://docs.python.org/library/platform.html - if platform.python_version() < '2.6.0': + if platform.python_version() < PYTHON_VERSION: (self.name, self.version, self.codename) = platform.dist() else: (self.name, self.version, self.codename) = platform.linux_distribution() @@ -63,9 +64,9 @@ def pkgsrc_name(self): @return str """ - if self.name in ('ubuntu', 'debian', 'linuxmint'): + if self.name in DIST_DEB_BASE: extend = 'list' - elif self.name in ('fedora', 'redhat', 'centos','opensuse','suse','mandriva'): + elif self.name in DIST_RPM_BASE: extend = 'sh' return "lzs_%s_%s_%s.%s" % (platform.machine(), self.name, @@ -93,32 +94,32 @@ def _reduce_name(self): raise DistrobutionNotFound() elif self.name == 'susE': if commands.getoutput('cat /etc/SuSE-release | grep "openSUSE"'): - self.name = 'opensuse' - elif self.name == 'redhat': + self.name = DIST_OPENSUSE + elif self.name == DIST_REDHAT: if commands.getoutput('cat /etc/redhat-release | grep "Red Hat"'): - self.name = 'redhat' + self.name = DIST_REDHAT if commands.getoutput('cat /etc/redhat-release | grep "CentOS"'): - self.name = 'centos' + self.name = DIST_CENTOS elif self.name in ('mandrake', 'mandriva linux'): if os.path.exists('/etc/mandriva-release') and \ commands.getoutput('cat /etc/mandriva-release | grep "Mandriva"'): - self.name = 'mandriva' + self.name = DIST_MANDRIVA #}}} #{{{def _reduce_version(self): def _reduce_version(self): if self.name == 'opensolaris' and not self.version: self.version = commands.getoutput('cat /etc/release | grep "OpenSolaris" | cut -d " " -f 27') - elif self.name == 'debian': + elif self.name == DIST_DEBIAN: self.version = self.version.split('.')[0] #}}} def _reduce_architecture(self): arch = platform.architecture()[0] if arch == '32bit': - self.architecture = 'i386' + self.architecture = ARCH_I386 elif arch == '64bit': - self.architecture = 'amd64' + self.architecture = ARCH_AMD64 else: self.architecture = None