import smtplib
from glob import glob
from logging import Formatter
-from sqlalchemy import create_engine
-from sqlalchemy.orm import sessionmaker
-from sqlalchemy import Table, Column, Integer, String, MetaData, Sequence
-from sqlalchemy.ext.declarative import declarative_base
-from sqlalchemy.orm.exc import NoResultFound
+import kernel_persistance
CWD = os.environ.get('WORKSPACE')
BUILD_NUMBER = os.environ.get('BUILD_NUMBER')
GIT_COMMITTER_EMAIL = os.environ.get('GIT_COMMITTER_EMAIL')
-PERSISTENCE_FILE = os.path.join(CWD, '..', '.persistence')
SMTP_SERVER = 'roma.profitbricks.localdomain'
SMTP_SUBJECT = 'Kernel build for branch %s, buildnumber %s was %s'
SMTP_TEXT = (
stream_handler.setFormatter(formatter)
logger.addHandler(stream_handler)
-Base = declarative_base()
-
-engine = create_engine('sqlite:///%s' %(PERSISTENCE_FILE))
-Session = sessionmaker(bind=engine)
def send_email(result):
smtp = smtplib.SMTP(SMTP_SERVER)
smtp.sendmail(SMTP_FROM, GIT_COMMITTER_EMAIL, msg)
smtp.quit()
-class KernelVersion(Base):
- __tablename__ = 'branch_kernel_version'
- id = Column(Integer, Sequence('branch_id'), primary_key=True)
- branch_name = Column(String(255), unique=True, nullable=False)
- last_version = Column(Integer, nullable=False)
-
- def __init__(self, branch_name, last_version):
- self.branch_name = branch_name
- self.last_version = last_version
-
- def __repr__(self):
- return '<KernelVersion(branch_name=\'%s\', last_version=\'%s\')>' %(
- self.branch_name, self.last_version
- )
-
-Base.metadata.create_all(engine)
-
-def get_last_kernel_revision_obj():
- session = Session()
- logger.debug('Getting kernel revision from persistence')
- if GIT_BRANCH_NAME == 'master' or GIT_BRANCH_NAME.startswith('hotfix'):
- persistance_identifier = 'master'
- elif GIT_BRANCH_NAME.startswith('release'):
- persistance_identifier = 'release'
- else:
- persistance_identifier = 'develop'
-
- try:
- answ = session.query(KernelVersion).filter(
- KernelVersion.branch_name == persistance_identifier).one()
- except NoResultFound:
- session.add(KernelVersion(persistance_identifier, 0))
- session.commit()
- answ = session.query(KernelVersion).filter(
- KernelVersion.branch_name == persistance_identifier).one()
- finally:
- session.close()
-
- logger.info(
- 'Got this Kernel revision for branch %s and persistance_identifier %s: %s'
- %(GIT_BRANCH_NAME, persistance_identifier, answ)
- )
- return answ
-
-def update_kernel_revision_obj(kernel_version_obj, new_revision):
- session = Session()
- kernel_version_obj.last_version = new_revision
- session.add(kernel_version_obj)
- try:
- session.commit()
- except Exception, error:
- logger.error('Some error happend while commiting new revision')
- logger.exception(error)
- return False
- else:
- return True
- finally:
- session.close()
-
-
def build_kernel_with_pbuilder(revision, pbuilder_script, dist='stable'):
pbuilder_script = os.path.abspath(pbuilder_script)
cmd = [
--- /dev/null
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import os
+from sqlalchemy import create_engine
+from sqlalchemy.orm import sessionmaker
+from sqlalchemy import Table, Column, Integer, String, MetaData, Sequence
+from sqlalchemy.ext.declarative import declarative_base
+from sqlalchemy.orm.exc import NoResultFound
+
+CWD = os.environ.get('WORKSPACE')
+PERSISTENCE_FILE = os.path.join(CWD, '..', '.persistence')
+
+Base = declarative_base()
+
+engine = create_engine('sqlite:///%s' %(PERSISTENCE_FILE))
+Session = sessionmaker(bind=engine)
+
+class KernelVersion(Base):
+ __tablename__ = 'branch_kernel_version'
+ id = Column(Integer, Sequence('branch_id'), primary_key=True)
+ identifier = Column(String(255), unique=True, nullable=False)
+ branch_name = Column(String(255), unique=True, nullable=False)
+ last_version = Column(Integer, nullable=False)
+ pb_modules = Column(String(255), unique=True, nullable=False)
+
+ def __init__(self, branch_name, last_version):
+ self.identifier = identifier
+ self.last_version = last_version
+ self.branch_name = branch_name
+ self.pb_modules = pb_modules
+
+ def __repr__(self):
+ return '<KernelVersion(identifier=\'%s\', last_version=\'%s\')>' %(
+ self.identifier, self.last_version
+ )
+
+Base.metadata.create_all(engine)
+
+def get_last_kernel_revision_obj():
+ session = Session()
+ logger.debug('Getting kernel revision from persistence')
+ if GIT_BRANCH_NAME == 'master' or GIT_BRANCH_NAME.startswith('hotfix'):
+ persistance_identifier = 'master'
+ elif GIT_BRANCH_NAME.startswith('release'):
+ persistance_identifier = 'release'
+ else:
+ # FIXME: feature branch handling
+ persistance_identifier = 'develop'
+
+ try:
+ answ = session.query(KernelVersion).filter(
+ KernelVersion.identifier == persistance_identifier).one()
+ except NoResultFound:
+ session.add(KernelVersion(persistance_identifier, 0))
+ session.commit()
+ answ = session.query(KernelVersion).filter(
+ KernelVersion.identifier == persistance_identifier).one()
+ finally:
+ session.close()
+
+ logger.info(
+ 'Got this Kernel revision for persistance_identifier %s: %s'
+ %(persistance_identifier, answ)
+ )
+ return answ
+
+def update_kernel_revision_obj(kernel_version_obj, new_revision):
+ session = Session()
+ kernel_version_obj.last_version = new_revision
+ session.add(kernel_version_obj)
+ try:
+ session.commit()
+ except Exception, error:
+ logger.error('Some error happend while commiting new revision')
+ logger.exception(error)
+ return False
+ else:
+ return True
+ finally:
+ session.close()
+
+