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 plugin_configuregithubrepository(self, variables):
     connection=None
     workspace_path=None
     try:
         connection = LocalConnection.getLocalConnection()
         workspace_path = PluginClient.create_tmp_workspace(connection)
         # Step 1 -- Clone the Repo
         if variables['create_in_github_organization']:
             path = variables['github_organization']
         else:
             path = variables['github_username']
         clone_cmd='#!/bin/sh\n%s clone https://github.com/%s/%s.git\n' \
                 % (variables['git_path'], path, variables['github_repo_name'])
         PluginClient.execute_command(connection, workspace_path, clone_cmd)
         # Step 2 -- Create .travis.yml file
         PluginClient.create_travis_yml_file(connection, workspace_path, variables)
         # Step 3 -- Sync Travis
         sync_cmd='#!/bin/sh\ncd %s\n%s sync\n' % (variables['github_repo_name'], variables['travis_path'])
         PluginClient.execute_command(connection, workspace_path, sync_cmd)
         # Step 4 -- Enable Project
         enable_cmd='#!/bin/sh\ncd %s\n%s enable --no-interactive\n' % (variables['github_repo_name'], variables['travis_path'])
         PluginClient.execute_command(connection, workspace_path, enable_cmd)
         # Step 5 -- Add HipChat Notifications
         if variables['integrate_with_hipchat']:
             hipchat_cmd='#!/bin/sh\ncd %s\n%s encrypt --no-interactive %s@%s --add notifications.hipchat.rooms\n' \
                     % (variables['github_repo_name'], variables['travis_path'], variables['hipchat_token'], variables['hipchat_room_id'])
             PluginClient.execute_command(connection, workspace_path, hipchat_cmd)
         # Step 6 -- Add GitHub Releases
         releases_cmd='#!/bin/sh\ncd %s\n%s encrypt --no-interactive "%s" --add deploy.api_key.secure\n' \
                 % (variables['github_repo_name'], variables['travis_path'], variables['github_api_token'])
         PluginClient.execute_command(connection, workspace_path, releases_cmd)
         # Step 7 -- Add the gradle stuff
         gradle_wrapper_cmd='#!/bin/sh\ncd %s\n%s wrapper --gradle-version %s\n' % (variables['github_repo_name'], variables['gradle_path'], variables['gradle_version'])
         PluginClient.execute_command(connection, workspace_path, gradle_wrapper_cmd)
         # settings.gradle
         PluginClient.create_settings_gradle_file(connection, workspace_path, variables)
         # build.gradle
         PluginClient.create_build_gradle_file(connection, workspace_path, variables)
         # Step 8 -- .gitignore
         PluginClient.create_gitignore_file(connection, workspace_path, variables)
         # Step 9 -- Generate README.md
         PluginClient.create_readme_file(connection, workspace_path, variables)
         # Step 10 -- Create License File
         PluginClient.create_license_file(connection, workspace_path, variables)
         # Step 11 -- Add/Commit/Push
         push_cmd='#!/bin/sh\ncd %s\n%s add -A\n%s commit -m "Initial Plugin Setup"\n%s push "https://%s:%[email protected]/%s/%s.git"' \
                 % (variables['github_repo_name'], variables['git_path'], variables['git_path'], variables['git_path'],
                     variables['github_username'], variables['github_password'], path, variables['github_repo_name'])
         PluginClient.execute_command(connection, workspace_path, push_cmd)
     except Exception:
         traceback.print_exc(file=sys.stdout)
         sys.exit(1)
     finally:
         if connection is not None and workspace_path is not None:
             self.zip_workspace(workspace_path, connection)
         if connection is not None:
             connection.close()
 def execute(self):
     connection = None
     try:
         connection = LocalConnection.getLocalConnection()
         exitCode = connection.execute(self.stdout, self.stderr,
                                       self.cmdLine)
     except Exception, e:
         stacktrace = StringWriter()
         writer = PrintWriter(stacktrace, True)
         e.printStackTrace(writer)
         self.stderr.handleLine(stacktrace.toString())
         return 1
    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 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}
示例#6
0
 def executeFile( self ):
    connection = None
    try:
       connection = LocalConnection.getLocalConnection()
       scriptFile = self.script 
       print "using script %s" % ( scriptFile )
       #scriptFile.setExecutable(True)
       self.cmdLine.addArgument( '-source' )
       self.cmdLine.addArgument( scriptFile )
       if ( len( self.options ) > 1 ):
          self.cmdLine.addArgument( '--' )
          optionsList = self.options.split(' ')
          for opt in optionsList:
              self.cmdLine.addArgument( opt )
          # End for
       # End if
       exitCode = connection.execute( self.stdout, self.stderr, self.cmdLine )
    except Exception, e:
          stacktrace = StringWriter()
          writer = PrintWriter(stacktrace, True)
          e.printStackTrace(writer)
          self.stderr.handleLine(stacktrace.toString())
          return 1
示例#7
0
 def execute( self ):
    connection = None
    try:
       connection = LocalConnection.getLocalConnection()
       scriptFile = connection.getTempFile('xlrScript', '.py')
       OverthereUtils.write( String( self.script ).getBytes(), scriptFile )
       scriptFile.setExecutable(True)
       self.cmdLine.addArgument( '-source' )
       self.cmdLine.addArgument( scriptFile.getPath() )
       if ( len( self.options ) > 1 ):
          self.cmdLine.addArgument( '--' )
          optionsList = self.options.split(' ')
          for opt in optionsList:
              self.cmdLine.addArgument( opt )
          # End for
       # End if
       exitCode = connection.execute( self.stdout, self.stderr, self.cmdLine )
    except Exception, e:
          stacktrace = StringWriter()
          writer = PrintWriter(stacktrace, True)
          e.printStackTrace(writer)
          self.stderr.handleLine(stacktrace.toString())
          return 1
 def execute(self):
     connection = None
     try:
         connection = LocalConnection.getLocalConnection()
         scriptFile = connection.getTempFile('xlrScript', '.py')
         OverthereUtils.write(String(self.script).getBytes(), scriptFile)
         scriptFile.setExecutable(True)
         self.cmdLine.addArgument('-source')
         self.cmdLine.addArgument(scriptFile.getPath())
         if len(self.options) > 1:
             self.cmdLine.addArgument('--')
             optionsList = self.options.split(' ')
             for opt in optionsList:
                 self.cmdLine.addArgument(opt)
             # End for
         # End if
         exitCode = connection.execute(self.stdout, self.stderr,
                                       self.cmdLine)
     except Exception, e:
         stacktrace = StringWriter()
         writer = PrintWriter(stacktrace, True)
         e.printStackTrace(writer)
         self.stderr.handleLine(stacktrace.toString())
         return 1
 def executeFile(self):
     connection = None
     try:
         connection = LocalConnection.getLocalConnection()
         scriptFile = self.script
         print "using script %s" % (scriptFile)
         #scriptFile.setExecutable(True)
         self.cmdLine.addArgument('-source')
         self.cmdLine.addArgument(scriptFile)
         if (len(self.options) > 1):
             self.cmdLine.addArgument('--')
             optionsList = self.options.split(' ')
             for opt in optionsList:
                 self.cmdLine.addArgument(opt)
             # End for
         # End if
         exitCode = connection.execute(self.stdout, self.stderr,
                                       self.cmdLine)
     except Exception, e:
         stacktrace = StringWriter()
         writer = PrintWriter(stacktrace, True)
         e.printStackTrace(writer)
         self.stderr.handleLine(stacktrace.toString())
         return 1
 def getConnection(self):
     if (self.connectionType):
         return Overthere.getConnection("ssh", self.options)
     else:
         return LocalConnection.getLocalConnection()
cmdLogon  = "%s login --server=%s -u %s -p %s --insecure-skip-tls-verify" % (ocCmd, ocUrl, ocUsername, ocPassword)
cmdProject ="%s delete project %s" % (ocCmd, ocProject)
script = """

%s
%s

""" % (cmdLogon, cmdProject)
#print script
print "-------------------------"

stdout = CapturingOverthereExecutionOutputHandler.capturingHandler()
stderr = CapturingOverthereExecutionOutputHandler.capturingHandler()

try:
    connection = LocalConnection.getLocalConnection()
    targetScript = connection.getTempFile('oc-script', '.bat')
    OverthereUtils.write( String(script).getBytes(), targetScript)
    targetScript.setExecutable(True)
    cmd = CmdLine.build( targetScript.getPath() )
    connection.execute( stdout, stderr, cmd )
except Exception, e:
    stacktrace = StringWriter()
    writer = PrintWriter( stacktrace, True )
    e.printStackTrace(writer)
    stderr.hadleLine(stacktrace.toString())

# set variables
output = stdout.getOutput()
error = stderr.getOutput()
示例#12
0
    if created_tmp_dir is not None:
        if created_tmp_dir.isFile():
            created_tmp_dir.delete();
        elif created_tmp_dir.isDirectory():
            files = created_tmp_dir.listFiles()
            if files is not None:
                for file in files:
                    remove_tmp_dir(file)
            created_tmp_dir.delete()

bundle_id = deployed.getDeployable().getId()
package_id = get_parent_id(bundle_id)

# Export the package dar
context.logOutput("Exporting: %s\n" % package_id)
local_connection = LocalConnection.getLocalConnection()
repository_service = RepositoryServiceHolder.getRepositoryService()
export_service = ExporterService(repository_service)

try:
    working_directory = local_connection.getWorkingDirectory()
    if working_directory is None:
        created_tmp_dir = create_tmp_dir(local_connection)
        working_directory = LocalFile(local_connection, created_tmp_dir)
        local_connection.setWorkingDirectory(working_directory)

    work_dir = WorkDir(working_directory)
    exported_dar = export_service.exportDar(package_id, work_dir)
    context.logOutput("Completed export to file: %s" % exported_dar.getFile().getName())

    # Connect to XL Deploy instance