Exemplo n.º 1
0
def load_classpath_resource(resource):
    """
    Uploads the classpath resource to the session's working directory.
    :param resource: to find on the classpath to copy
    :return: string
    """
    url = Thread.currentThread().contextClassLoader.getResource(resource)
    if url is None:
        raise Exception("Resource [%s] not found on classpath." % resource)

    return Resources.toString(url, Charset.defaultCharset())
Exemplo n.º 2
0
def load_session(req,session_dir):
    if req.params.has_key("mvcx.sessionID"):

        session_file=File("%s/%s.json" % (session_dir,req.params["mvcx.sessionID"]))
        print("session_path:"+str(session_file.getAbsolutePath()))
        if session_file.exists():
            session=JsonObject("\n".join(Files.readLines(session_file,Charset.defaultCharset())))

            return session
        else:
            return None
    else:
        return None
Exemplo n.º 3
0
def decode_result(text):
    '''
        The output of ping command is encoded with OS's default encoding, it needs to be decoded
        when the encoding is not utf-8.
    '''
    result = None
    try:
        encoding = get_default_encoding()
        result = text.decode(encoding) if encoding else text
    except LookupError:
        # some encodings (eg cp936 for chinese) are missing in jython, try to decode with java
        # not using java in the first place because encodings like cp850 will fail (encoding windows-1252 is used in java)
        from java.nio.charset import Charset
        from java.lang import String
        result = String(text, Charset.defaultCharset())
    return result
def decode_result(text):
    '''
        The output of ping command is encoded with OS's default encoding, it needs to be decoded
        when the encoding is not utf-8.
    '''
    result = None
    try:
        encoding = get_default_encoding()
        result = text.decode(encoding) if encoding else text
    except LookupError:
        # some encodings (eg cp936 for chinese) are missing in jython, try to decode with java
        # not using java in the first place because encodings like cp850 will fail (encoding windows-1252 is used in java)
        from java.nio.charset import Charset
        from java.lang import String
        result = String(text, Charset.defaultCharset())
    return result
Exemplo n.º 5
0
    os = OperatingSystemFamily.WINDOWS
else:
    os = OperatingSystemFamily.UNIX

local_opts = LocalConnectionOptions(os=os)
local_host = OverthereHost(local_opts)
local_session = OverthereHostSession(local_host, stream_command_output=True)

local_yaml_file = local_session.work_dir_file(remote_yaml_file.getName())
print("local_yaml_file {0}".format(local_yaml_file))

print("copy....")
local_session.copy_to(remote_yaml_file, local_yaml_file)

print("---- YAML ")
print(OverthereUtils.read(local_yaml_file, Charset.defaultCharset().name()))
print("/----")

context = {
    'devopsAsCodePassword': ansible_controler.devopsAsCodePassword,
    'devopsAsCodeUsername': ansible_controler.devopsAsCodeUsername,
    'devopsAsCodeUrl': ansible_controler.devopsAsCodeUrl,
    'yaml_file': local_yaml_file.path,
    'xlPath': ansible_controler.xlPath
}

command_line = "{xlPath} --xl-deploy-password {devopsAsCodePassword} --xl-deploy-username {devopsAsCodeUsername} --xl-deploy-url {devopsAsCodeUrl} apply -f {yaml_file} ".format(
    **context)
print(command_line)

import subprocess