'production-proposed-updates'
)
-#unused: (except in in-active code)
-GIT_TARGET_WORKSPACE = os.path.join(
- ENV['WORKSPACE'],
- ('%s-build%s' %(ENV['BUILD_ID'], ENV['BUILD_NUMBER'])),
- )
-#unused: (except in in-active code)
-GIT_TARGET_DIR = os.path.join(
- GIT_TARGET_WORKSPACE,
- os.path.basename(GIT_REPO_PATH)
- )
-
-DPUT_OPTIONS_DEFAULT = {
- # FIXME: i went to lib/dput.py
-DPUT_OPTIONS_DEV = {
- 'fqdn': 'alexandria.pb.local',
- 'method': 'scp',
- 'login': 'reprepro',
- 'incoming': '/srv/dev-repository/incoming/',
- 'allow_unsigned_uploads': 1,
- 'post_upload_command': 'ssh reprepro@alexandria.pb.local /srv/dev-repository/bin/pb_processincoming',
- }
-DPUT_CF = os.path.join(ENV['WORKSPACE'], '..', 'dput.cf')
-
-
-def dput_package_upload(changes_path):
- # FIXME: i went to lib/dput.py
-
-def create_dput_cfg():
- # FIXME: i went to lib/dput.py
+dput_obj = dput.Dput()
+dput_obj.config = os.path.join(ENV['WORKSPACE'], '..', 'dput.cf')
+dput_obj.section = 'profitbricks'
+if GIT_BRANCH_NAME.startswith('feature/') or GIT_BRANCH_NAME.startswith('poc/') or GIT_BRANCH_NAME.startswith('bugfix/'):
+ dput_obj.contents = {
+ 'fqdn': 'alexandria.pb.local',
+ 'method': 'scp',
+ 'login': 'reprepro',
+ 'incoming': '/srv/dev-repository/incoming/',
+ 'allow_unsigned_uploads': 1,
+ 'post_upload_command': 'ssh reprepro@alexandria.pb.local /srv/dev-repository/bin/pb_processincoming',
+ }
+else:
+ dput_obj.contents = {
+ fqdn: 'alexandria.pb.local',
+ method: 'scp',
+ login: 'reprepro',
+ incoming: '/srv/profitbricks-repository/incoming/profitbricks',
+ allow_unsigned_uploads: 1,
+ post_upload_command: 'ssh reprepro@alexandria.pb.local /srv/profitbricks-repository/bin/pb_processincoming',
+ },
def getopts():
usage = '%prog [options]'
# now upload (at least, try to...)
try:
- create_dput_cfg()
+ dput_obj.configure()
# strip epoch
if ":" in version:
version = version.split(":", 1)[1]
fh.close()
# upload (if NO_UPLOAD is not set)
if NO_UPLOAD not in ('true', 'True'):
- dput_package_upload(changes_file)
+ dput_obj.upload(changes_file)
else:
logger.debug('value of NO_UPLOAD: %s' % NO_UPLOAD)
logger.info('dist: %s' %(pb_suite))
--- /dev/null
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+class Dput(object):
+ '''
+ TODO
+ '''
+ def __init__(
+ config = '', #FIXME: whats the correct default?
+ section = 'profitbricks',
+ contents = {
+ fqdn: 'alexandria.pb.local',
+ method: 'scp',
+ login: 'reprepro',
+ incoming: '/srv/profitbricks-repository/incoming/profitbricks',
+ allow_unsigned_uploads: 1,
+ post_upload_command: 'ssh reprepro@alexandria.pb.local /srv/profitbricks-repository/bin/pb_processincoming',
+ },
+ ):
+ self.config = config
+ self.section = section
+ self.contents = contents
+
+ @property
+ def config():
+ return self._config
+
+ @config.setter
+ def config(value):
+ self._config = value
+
+ @property
+ def section():
+ return self._section
+
+ @section.setter
+ def section(value):
+ self._section = value
+
+ @property
+ def contents():
+ return self._contents
+
+ @contents.setter
+ def contents(value):
+ self._contents = value
+
+ def configure(
+ config = self.config,
+ section = self.section,
+ contents = self.contents,
+ ):
+ try:
+ parser = SafeConfigParser()
+ parser.add_section(section)
+ for key, value in contents.iteritems():
+ parser.set(section, str(key), str(value))
+
+ filehandler = open(config, 'w')
+ config.write(filehandler)
+ filehandler.close()
+
+ logger.info('Dput configuration successfully created.')
+ return True
+
+ except Exception as error:
+ logger.error('Failed to configure dput: %s',exc_info=error)
+
+ return False
+
+ def upload(
+ config = self.config,
+ files = [],
+ ):
+
+ if len(files) == 0:
+ logger.debug('Please specify at least one file to upload.')
+ return False
+
+ if type(files) == type(str):
+ files = files.spit()
+
+ try:
+ cmd = [BIN_DPUT,
+ '-c',
+ '%s' %(config),
+ '--no-upload-log',
+ 'profitbricks',
+ '%s' %(' '.join(files)),
+ ]
+
+ logger.debug('Executing "%s" ...' %(cmd))
+ result = subprocess.Popen(
+ cmd,
+ shell=False,
+ stdout=sys.stdout,
+ stderr=subprocess.STDOUT,
+ close_fds=True,
+ cwd=os.path.dirname(config)
+ ).wait()
+ logger.debug('Returned with status %d' %(result))
+
+ if result != 0:
+ raise Exception('{cmd} failed with status code {code}'.format(
+ cmd = ' '.join(cmd),
+ code = result,
+ ))
+
+ logger.info('Dput upload successfully completed.')
+ return True
+
+ except Exception as error:
+ logger.error('Failed to upload files: %s',exc_info=error))
+
+ return False
+