def create_readme_file(connection, workspace_path, variables):
        if variables['create_in_github_organization']:
            path = variables['github_organization']
        else:
            path = variables['github_username']
        contents='''# %s

[![Build Status](https://travis-ci.org/%s/%s.svg?branch=master)](https://travis-ci.org/%s/%s)
[REPLACE ME WITH CODACY BADGE](https://www.codacy.com)
[![Code Climate](https://codeclimate.com/github/%s/%s/badges/gpa.svg)](https://codeclimate.com/github/%s/%s)
[![License: MIT][%s-license-image] ][%s-license-url]
[![Github All Releases][%s-downloads-image]]()

[%s-license-image]: https://img.shields.io/badge/License-MIT-yellow.svg
[%s-license-url]: https://opensource.org/licenses/MIT
[%s-downloads-image]: https://img.shields.io/github/downloads/xebialabs-community/%s/total.svg

## Preface

## Overview

## Installation

## References
''' % (variables['github_repo_name'], path, variables['github_repo_name'], path,
       variables['github_repo_name'], path, variables['github_repo_name'], path,
       variables['github_repo_name'], variables['github_repo_name'], variables['github_repo_name'], variables['github_repo_name'],
       variables['github_repo_name'], variables['github_repo_name'], variables['github_repo_name'], variables['github_repo_name'],)
        repo_directory=OverthereUtils.constructPath(connection.getFile(workspace_path), '%s' % variables['github_repo_name'])
        readme_file=connection.getFile(OverthereUtils.constructPath(connection.getFile(repo_directory), 'README.md'))
        OverthereUtils.write(String(contents).getBytes(), readme_file)
 def create_chef_tmp_workspace(self, connection):
     try:
         tmp_workspace_file = connection.getTempFile('tmp_workspace')
         workspace_path = re.sub('tmp_workspace', '',
                                 tmp_workspace_file.getPath())
         workspace_directory = connection.getFile(workspace_path)
         connection.setWorkingDirectory(workspace_directory)
         new_path = "%s.chef" % workspace_path
         if not os.path.exists(new_path):
             os.makedirs(new_path)
         self.generate_knife_rb(new_path, connection)
         chef_key_file = connection.getFile(
             OverthereUtils.constructPath(connection.getFile(new_path),
                                          'chefkey.pem'))
         OverthereUtils.write(
             String(self.client_key).getBytes(), chef_key_file)
         ssl_script = self.get_os_specific_ssl_script(workspace_path)
         script_file = connection.getFile(
             OverthereUtils.constructPath(
                 connection.getFile(workspace_path), 'ssl.cmd'))
         OverthereUtils.write(String(ssl_script).getBytes(), script_file)
         script_file.setExecutable(True)
         self.cmd_line.addArgument(script_file.getPath())
         connection.execute(self.stdout, self.stderr, self.cmd_line)
         return workspace_path
     except Exception:
         traceback.print_exc(file=sys.stdout)
         sys.exit(1)
예제 #3
0
파일: Plugin.py 프로젝트: Varma4u/Xebia
    def create_build_gradle_file(connection, workspace_path, variables):
        contents = '''plugins {
    id "com.github.hierynomus.license" version "0.13.0"
}

defaultTasks 'build'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'maven'
version='%s'

license {
    header rootProject.file('License.md')
    strictCheck false
    excludes(["**/*.json"])
    ext.year = Calendar.getInstance().get(Calendar.YEAR)
    ext.name = 'XEBIALABS'
}
''' % variables['initial_version']
        repo_directory = OverthereUtils.constructPath(
            connection.getFile(workspace_path),
            '%s' % variables['github_repo_name'])
        build_gradle_file = connection.getFile(
            OverthereUtils.constructPath(connection.getFile(repo_directory),
                                         'build.gradle'))
        OverthereUtils.write(String(contents).getBytes(), build_gradle_file)
예제 #4
0
파일: Plugin.py 프로젝트: Varma4u/Xebia
 def create_settings_gradle_file(connection, workspace_path, variables):
     contents = 'rootProject.name=\'%s\'\n' % variables['github_repo_name']
     repo_directory = OverthereUtils.constructPath(
         connection.getFile(workspace_path),
         '%s' % variables['github_repo_name'])
     settings_gradle_file = connection.getFile(
         OverthereUtils.constructPath(connection.getFile(repo_directory),
                                      'settings.gradle'))
     OverthereUtils.write(String(contents).getBytes(), settings_gradle_file)
    def create_gitignore_file(connection, workspace_path, variables):
        contents='''.gradle
.idea
build
supervisord.log
supervisord.pid
'''
        repo_directory=OverthereUtils.constructPath(connection.getFile(workspace_path), '%s' % variables['github_repo_name'])
        gitignore_file=connection.getFile(OverthereUtils.constructPath(connection.getFile(repo_directory), '.gitignore'))
        OverthereUtils.write(String(contents).getBytes(), gitignore_file)
    def create_license_file(connection, workspace_path, variables):
        contents='''
Copyright ${year} ${name}

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.'''
        repo_directory=OverthereUtils.constructPath(connection.getFile(workspace_path), '%s' % variables['github_repo_name'])
        readme_file=connection.getFile(OverthereUtils.constructPath(connection.getFile(repo_directory), 'License.md'))
        OverthereUtils.write(String(contents).getBytes(), readme_file)
    def create_travis_yml_file(connection, workspace_path, variables):
        contents='''language: java
sudo: false
deploy:
    provider: releases
    file: build/libs/%s-%s.jar
    skip_cleanup: true
    on:
        all_branches: true
        tags: true
        repo: %s/%s
''' % (variables['github_repo_name'], variables['initial_version'], variables['github_organization'], variables['github_repo_name'])
        repo_directory=OverthereUtils.constructPath(connection.getFile(workspace_path), '%s' % variables['github_repo_name'])
        travis_yml_file=connection.getFile(OverthereUtils.constructPath(connection.getFile(repo_directory), '.travis.yml'))
        OverthereUtils.write(String(contents).getBytes(), travis_yml_file)
 def execute_knife_command(self,
                           command,
                           script_name,
                           options=None,
                           zip_workspace=False):
     connection = None
     try:
         options = Workstation.process_additional_options(options)
         connection = LocalConnection.getLocalConnection()
         workspace_path = self.create_chef_tmp_workspace(connection)
         knife_command = self.get_os_specific_knife_command(
             workspace_path, command, options)
         script_file = connection.getFile(
             OverthereUtils.constructPath(
                 connection.getFile(workspace_path), script_name))
         OverthereUtils.write(String(knife_command).getBytes(), script_file)
         script_file.setExecutable(True)
         if zip_workspace:
             self.zip_workspace(workspace_path, connection)
         command = CmdLine()
         command.addArgument(script_file.getPath())
         output_handler = CapturingOverthereExecutionOutputHandler.capturingHandler(
         )
         error_handler = CapturingOverthereExecutionOutputHandler.capturingHandler(
         )
         exit_code = connection.execute(output_handler, error_handler,
                                        command)
         return [exit_code, output_handler, error_handler]
     except Exception:
         traceback.print_exc(file=sys.stdout)
         sys.exit(1)
     finally:
         if connection is not None:
             connection.close()
 def zip_workspace(self, workspace_path, connection):
     zip_script = self.get_os_specific_zip_command(workspace_path)
     zip_script_file = connection.getFile(OverthereUtils.constructPath(connection.getFile(workspace_path), 'zip.cmd'))
     OverthereUtils.write(String(zip_script).getBytes(), zip_script_file)
     zip_script_file.setExecutable(True)
     command = CmdLine()
     command.addArgument(zip_script_file.getPath())
     return connection.execute(command)
   def generate_knife_rb(self, path, connection):
       knife_contents = '''current_dir = File.dirname(__FILE__)
 log_level %s
 log_location %s
 node_name "%s"
 client_key "#{current_dir}/chefkey.pem"
 chef_server_url "%s"
 cookbook_path ["%s"]''' % (self.log_level, self.log_location, self.node_name,
                            self.chef_server_url, self.cookbook_path)
       knife_rb_file = connection.getFile(
           OverthereUtils.constructPath(connection.getFile(path), 'knife.rb'))
       OverthereUtils.write(knife_contents, knife_rb_file)
    def bitbucket_downloadcode(self, variables):
        downloadURL = "%s/%s/get/%s.zip" % (variables['server']['url'].replace("api.","www."), variables['repo_full_name'], variables['branch'] )
        connection = LocalConnection.getLocalConnection()

        capturedOutput = ""

        print "Cleaning up download folder : %s" % variables['downloadPath']
        command = CmdLine()
        command.addArgument("rm")
        command.addArgument("-rf")
        command.addArgument(variables['downloadPath'] + "/*")
        output_handler = CapturingOverthereExecutionOutputHandler.capturingHandler()
        error_handler = CapturingOverthereExecutionOutputHandler.capturingHandler()
        exit_code = connection.execute(output_handler, error_handler, command)
        capturedOutput = self.parse_output(output_handler.getOutputLines()) + self.parse_output(error_handler.getOutputLines())

        print " Now downloading code in download folder : %s" % variables['downloadPath']
        command = CmdLine()
        script = '''
            cd %s
            wget --user %s --password %s  -O code.zip %s
            unzip code.zip
            rm -rf *.zip
            foldername=`ls -d */`
            mv -f $foldername* `pwd`
            rm -rf $foldername
        ''' % (variables['downloadPath'], self.http_request.username, self.http_request.password,  downloadURL )
        script_file = connection.getFile(OverthereUtils.constructPath(connection.getFile(variables['downloadPath']), 'extract.sh'))
        OverthereUtils.write(String(script).getBytes(), script_file)
        script_file.setExecutable(True)
        command.addArgument(script_file.getPath())
        output_handler = CapturingOverthereExecutionOutputHandler.capturingHandler()
        error_handler = CapturingOverthereExecutionOutputHandler.capturingHandler()
        exit_code = connection.execute(output_handler, error_handler, command)
        capturedOutput += self.parse_output(output_handler.getOutputLines()) + self.parse_output(error_handler.getOutputLines())

        command = CmdLine()
        command.addArgument("rm")
        command.addArgument("-f")
        command.addArgument(variables['downloadPath'] + "/extract.sh")
        output_handler = CapturingOverthereExecutionOutputHandler.capturingHandler()
        error_handler = CapturingOverthereExecutionOutputHandler.capturingHandler()
        exit_code = connection.execute(output_handler, error_handler, command)
        capturedOutput += self.parse_output(output_handler.getOutputLines()) + self.parse_output(error_handler.getOutputLines())

        return {'output': capturedOutput}
 def execute_command(connection, workspace_path, command):
     try:
         print "executing command: %s" % command
         script_file = connection.getFile(OverthereUtils.constructPath(connection.getFile(workspace_path), 'command.cmd'))
         OverthereUtils.write(String(command).getBytes(), script_file)
         script_file.setExecutable(True)
         command = CmdLine()
         command.addArgument(script_file.getPath())
         output_handler = CapturingOverthereExecutionOutputHandler.capturingHandler()
         error_handler = CapturingOverthereExecutionOutputHandler.capturingHandler()
         exit_code = connection.execute(output_handler, error_handler, command)
         print "exit_code : %s" % exit_code
         print "output: %s" % output_handler.getOutput()
         print "errors: %s" % error_handler.getOutput()
         return [exit_code, output_handler, error_handler]
     except Exception:
         traceback.print_exc(file=sys.stdout)
         sys.exit(1)
    def stash_downloadcode(self, variables):
        downloadURL = "%s/rest/archive/latest/projects/%s/repos/%s/archive?at=refs/heads/%s&format=zip" % (variables['server']['url'], variables['project'], variables['repository'], variables['branch'])
        connection = LocalConnection.getLocalConnection()

        capturedOutput = ""

        print "Cleaning up download folder : %s" % variables['downloadPath']
        command = CmdLine()
        command.addArgument("mkdir")
        command.addArgument("-p")
        command.addArgument(variables['downloadPath'])
        output_handler = CapturingOverthereExecutionOutputHandler.capturingHandler()
        error_handler = CapturingOverthereExecutionOutputHandler.capturingHandler()
        exit_code = connection.execute(output_handler, error_handler, command)
        capturedOutput = self.parse_output(output_handler.getOutputLines()) + self.parse_output(error_handler.getOutputLines())

        print " Now downloading code in download folder : %s" % variables['downloadPath']
        command = CmdLine()
        script = '''
            cd %s
            ls | grep -v extract.sh | xargs rm -rf
            wget --user %s --password %s  -O code.zip '%s'
            unzip -o code.zip
            rm code.zip
        ''' % (variables['downloadPath'], self.http_request.username, self.http_request.password,  downloadURL)
        script_file = connection.getFile(OverthereUtils.constructPath(connection.getFile(variables['downloadPath']), 'extract.sh'))
        OverthereUtils.write(String(script).getBytes(), script_file)
        script_file.setExecutable(True)
        command.addArgument(script_file.getPath())
        output_handler = CapturingOverthereExecutionOutputHandler.capturingHandler()
        error_handler = CapturingOverthereExecutionOutputHandler.capturingHandler()
        exit_code = connection.execute(output_handler, error_handler, command)
        capturedOutput += self.parse_output(output_handler.getOutputLines()) + self.parse_output(error_handler.getOutputLines())

        command = CmdLine()
        command.addArgument("rm")
        command.addArgument("-f")
        command.addArgument(variables['downloadPath'] + "/extract.sh")
        output_handler = CapturingOverthereExecutionOutputHandler.capturingHandler()
        error_handler = CapturingOverthereExecutionOutputHandler.capturingHandler()
        exit_code = connection.execute(output_handler, error_handler, command)
        capturedOutput += self.parse_output(output_handler.getOutputLines()) + self.parse_output(error_handler.getOutputLines())

        return {'output': capturedOutput}