import smtplib
from glob import glob
from logging import Formatter
-import kernel_persistance
+import kernel_persistence
CWD = os.environ.get('WORKSPACE')
BUILD_NUMBER = os.environ.get('BUILD_NUMBER')
atexit.register(remove_git_target_workspace)
kernel_revision_obj = kernel_persistence.get_last_kernel_revision_obj()
new_version = kernel_revision_obj.last_version + 1
- if not kernel_persistance.update_kernel_revision_obj(kernel_revision_obj, new_version):
+ if not kernel_persistence.update_kernel_revision_obj(kernel_revision_obj, new_version):
logger.info(
'Could not update persistence version to %s for %s'
%(new_version, GIT_BRANCH_NAME)
+++ /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)
-Base.metadata.create_all(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
- )
-
-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()
--- /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)
+Base.metadata.create_all(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
+ )
+
+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'):
+ persistence_identifier = 'master'
+ elif GIT_BRANCH_NAME.startswith('release'):
+ persistence_identifier = 'release'
+ else:
+ # FIXME: feature branch handling
+ persistence_identifier = 'develop'
+
+ try:
+ answ = session.query(KernelVersion).filter(
+ KernelVersion.identifier == persistence_identifier).one()
+ except NoResultFound:
+ session.add(KernelVersion(persistence_identifier, 0))
+ session.commit()
+ answ = session.query(KernelVersion).filter(
+ KernelVersion.identifier == persistence_identifier).one()
+ finally:
+ session.close()
+
+ logger.info(
+ 'Got this Kernel revision for persistence_identifier %s: %s'
+ %(persistence_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()