示例#1
0
文件: fjj.py 项目: atykhonov/mirantis
import os
import sys
import time

from utils import can_read, is_build_running, parse_config


system_settings = '/etc/fjj/fjjrc'
home_settings_dir = os.path.expanduser(os.path.join('~', '.config', 'fjj'))
home_settings = os.path.join(home_settings_dir, 'fjjrc')
pwd_settings = os.path.join(os.getcwd(), '.fjjrc')

settings = {}

if can_read(system_settings):
    settings.update(parse_config(system_settings))

if can_read(home_settings):
    settings.update(parse_config(home_settings))

if can_read(pwd_settings):
    settings.update(parse_config(pwd_settings))

if os.environ.get('FJJ_USERNAME'):
    settings['username'] = os.environ.get('FJJ_USERNAME')

if os.environ.get('FJJ_PASSWORD'):
    settings['password'] = os.environ.get('FJJ_PASSWORD')

if os.environ.get('FJJ_JENKINS_URL'):
示例#2
0
def TarIt(source, destDir, excludes=[]):
	""" take directory, tar it, put it in destination
		folder, file name generated from directory, replacing
		special characters with underscores; one success,
		return name of archive created """

	now = datetime.datetime.now()
        destFile = os.path.join(
            destDir, 
            socket.gethostname() + '-' + source.replace('/','_').replace(' ','_') + '-' + now.strftime('%Y%m%d-%s') + '.tar.gz'
        )
	out = tarfile.open(destFile, 'w:gz')
        if excludes:
            # exclude if we told it to exclude it or
            out.add(source, recursive=True, exclude = lambda x: True if (utils.is_match(x, excludes) or not utils.can_read(x)) else False)
        else:
            out.add(source, recursive=True)
        
	print('Successfully created archive %s' % destFile)
	return destFile