Skip to content

Commit

Permalink
Merge pull request #1 from aminzai/master
Browse files Browse the repository at this point in the history
add constant support
  • Loading branch information
billy3321 committed May 27, 2011
2 parents 2bbe0c6 + 6bc0801 commit 4ae0770
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 11 deletions.
45 changes: 45 additions & 0 deletions lazyscripts/constant.py
Original file line number Diff line number Diff line change
@@ -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 = ''
23 changes: 12 additions & 11 deletions lazyscripts/distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import platform

from lazyscripts import pkgmgr
from lazyscripts.constant import *

class DistrobutionNotFound(Exception):
"The distrobution can not be detected."
Expand All @@ -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()
Expand All @@ -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,
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 4ae0770

Please sign in to comment.