Skip to content

Commit

Permalink
Created a special Edition class with handles exceptions, such as BioN…
Browse files Browse the repository at this point in the history
…ode,

without resorting to boolean checking.
  • Loading branch information
pjotrp committed May 8, 2011
1 parent 5ae5ebd commit 1aacbc2
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 23 deletions.
Empty file added contrib/__init__.py
Empty file.
Empty file added contrib/edition/__init__.py
Empty file.
30 changes: 30 additions & 0 deletions contrib/edition/bionode.py
@@ -0,0 +1,30 @@

from fabric.api import *

from edition import *
import logging

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
# create formatter
formatter = logging.Formatter('%(name)s %(levelname)s: %(message)s')
# add formatter to ch
ch.setFormatter(formatter)
logger.addHandler(ch)

class BioNode(Edition):
"""BioNode specialization of BioLinux
"""
def __init__(self, env):
self.name = "BioNode Edition"
self.env = env
self.include_oracle_virtualbox = False
self.include_freenx = False

def check_packages_source(self):
# Bionode removes sources, just to be sure
logger.debug("Clearing %s" % self.env.sources_file)
sudo("cat /dev/null > %s" % self.env.sources_file)

28 changes: 24 additions & 4 deletions edition.py
@@ -1,6 +1,26 @@
import logging

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
# create formatter
formatter = logging.Formatter('%(name)s %(levelname)s: %(message)s')
# add formatter to ch
ch.setFormatter(formatter)
logger.addHandler(ch)


class Edition:
"""Base class. Every edition derives from this
"""
def __init__(self):
self.name = "BioLinux base Edition"
"""Base class. Every edition derives from this
"""
def __init__(self, env):
self.name = "BioLinux base Edition"
self.env = env
self.include_oracle_virtualbox = True
self.include_freenx = True

def check_packages_source(self):
"""Override for check package definition file before updating
"""
logger.debug("check_packages_source not implemented")
48 changes: 29 additions & 19 deletions fabfile.py
Expand Up @@ -41,7 +41,7 @@

from edition import *

edition = Edition()
edition = Edition(env) # default is empty Edition

env.config_dir = os.path.join(os.path.dirname(__file__), "config")
if not env.get('edition'):
Expand All @@ -55,19 +55,24 @@
env.ubuntu = False # is it pure Ubuntu?
env.centos = False # is it pure CentOS?
env.deb_derived = False # is it Debian derived?
env.bionode = False # is it a bionode?

# ### Configuration details for different server types
from contrib.edition.bionode import *

def _setup_distribution_environment():
"""Setup distribution environment
def _setup_edition():
"""Setup one of the BioLinux editions (which are derived from
the Edition base class)
"""
_parse_fabricrc()
logger.info("Edition %s %s" % (env.edition,env.edition_version))
global edition
logger.debug("Edition %s %s" % (env.edition,env.edition_version))
if env.edition == 'bionode':
env.bionode = True
if env.bionode:
logger.info("Note: this is a BioNode specialization!")
edition = BioNode(env)
logger.info("This is a %s" % edition.name)

def _setup_distribution_environment():
"""Setup distribution environment
"""
logger.info("Distribution %s" % env.distribution)
if env.distribution == 'debian':
env.debian = True
Expand Down Expand Up @@ -163,11 +168,12 @@ def _setup_deb_general():
shared_sources = [
"deb http://nebc.nox.ac.uk/bio-linux/ unstable bio-linux", # Bio-Linux
]
if not env.bionode:
# virtualbox (non-free, bionode uses virtualbox-ose instead)
shared_sources += "deb http://download.virtualbox.org/virtualbox/debian %s contrib",
if edition.include_oracle_virtualbox:
# virtualbox (non-free, otherwise use virtualbox-ose instead)
shared_sources.append('deb http://download.virtualbox.org/virtualbox/debian %s contrib')
if edition.include_freenx:
# this arguably belongs in _setup_ubuntu:
shared_sources += "deb http://ppa.launchpad.net/freenx-team/ppa/ubuntu lucid main", # FreeNX PPA
shared_sources.append('deb http://ppa.launchpad.net/freenx-team/ppa/ubuntu lucid main') # FreeNX PPA
return shared_sources

def _setup_centos():
Expand Down Expand Up @@ -249,6 +255,8 @@ def install_biolinux(target=None):
- finalize Setup freenx
"""
_check_fabric_version()
_parse_fabricrc()
_setup_edition()
_setup_distribution_environment() # get parameters for distro, packages etc.
pkg_install, lib_install = _read_main_config() # read main.yaml
_validate_target_distribution()
Expand Down Expand Up @@ -486,6 +494,8 @@ def install_libraries(language):
"""High level target to install libraries for a specific language.
"""
_check_fabric_version()
_parse_fabricrc()
_setup_edition()
_setup_distribution_environment()
_do_library_installs(["%s-libs" % language])

Expand Down Expand Up @@ -527,10 +537,12 @@ def _add_apt_gpg_keys():
"""
logger.info("Update GPG keys for repositories")
standalone = [
"http://archive.cloudera.com/debian/archive.key",
"http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc"]
"http://archive.cloudera.com/debian/archive.key"
]
if edition.include_oracle_virtualbox:
standalone.append('http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc')
keyserver = []
if not env.bionode: # FIXME: should really be: if env.ubuntu:
if env.ubuntu:
keyserver = [
("keyserver.ubuntu.com", "7F0CEB10"),
("keyserver.ubuntu.com", "E084DAB9"),
Expand Down Expand Up @@ -584,11 +596,9 @@ def _setup_apt_sources():
Uses python-software-properties, which provides an abstraction of apt repositories
"""
sudo("apt-get install -y --force-yes python-software-properties")
if env.bionode:
# remove sources, just to be sure
sudo("cat /dev/null > %s" % env.sources_file)
edition.check_packages_source()

comment = "# This file was modified for BioLinux"
comment = "# This file was modified for "+edition.name
if not contains(env.sources_file, comment):
append(env.sources_file, comment, use_sudo=True)
for source in env.std_sources:
Expand Down

0 comments on commit 1aacbc2

Please sign in to comment.