# Path: elbepack/soapclient.py
# class ClientAction:
#     actiondict = {}
# 
#     @classmethod
#     def register(cls, action):
#         cls.actiondict[action.tag] = action
# 
#     @classmethod
#     def print_actions(cls):
#         print("available subcommands are:", file=sys.stderr)
#         for a in cls.actiondict:
#             print("   %s" % a, file=sys.stderr)
# 
#     def __new__(cls, node):
#         action = cls.actiondict[node]
#         return object.__new__(action)
# 
#     def __init__(self, node):
#         self.node = node
# 
#     @staticmethod
#     def upload_file(append, build_dir, filename):
# 
#         size = 1024 * 1024
# 
#         with open(filename, "rb") as f:
# 
#             while True:
# 
#                 bin_data = f.read(size)
#                 data = binascii.b2a_base64(bin_data)
# 
#                 if not isinstance(data, str):
#                     data = data.decode("ascii")
# 
#                 append(build_dir, data)
# 
#                 if len(bin_data) != size:
#                     break
# 
#     def execute(self, _client, _opt, _args):
#         raise NotImplementedError('execute() not implemented')
# 
# class ElbeSoapClient:
#     def __init__(self, host, port, user, passwd, retries=10, debug=False):
# 
#         # pylint: disable=too-many-arguments
# 
#         # Mess with suds logging, for debug, or squelch warnings
#         set_suds_debug(debug)
# 
#         # Attributes
#         self.wsdl = "http://" + host + ":" + str(port) + "/soap/?wsdl"
#         self.control = None
#         self.retries = 0
# 
#         # Loop and try to connect
#         while self.control is None:
#             self.retries += 1
#             try:
#                 self.control = Client(self.wsdl, timeout=cfg['soaptimeout'])
#             except URLError as e:
#                 if self.retries > retries:
#                     raise e
#                 time.sleep(1)
#             except socket.error as e:
#                 if self.retries > retries:
#                     raise e
#                 time.sleep(1)
#             except BadStatusLine as e:
#                 if self.retries > retries:
#                     raise e
#                 time.sleep(1)
# 
#         # Make sure, that client.service still maps
#         # to the service object.
#         self.service = self.control.service
# 
#         # We have a Connection, now login
#         self.service.login(user, passwd)
# 
#     def download_file(self, builddir, filename, dst_fname):
#         fp = open(dst_fname, "wb")
#         part = 0
# 
#         # XXX the retry logic might get removed in the future, if the error
#         # doesn't occur in real world. If it occurs, we should think about
#         # the root cause instead of stupid retrying.
#         retry = 5
# 
#         while True:
#             try:
#                 ret = self.service.get_file(builddir, filename, part)
#             except BadStatusLine as e:
#                 retry = retry - 1
# 
#                 print("get_file part %d failed, retry %d times" % (part, retry),
#                       file=sys.stderr)
#                 print(str(e), file=sys.stderr)
#                 print(repr(e.line), file=sys.stderr)
# 
#                 if not retry:
#                     fp.close()
#                     print("file transfer failed", file=sys.stderr)
#                     sys.exit(20)
# 
#             if ret == "FileNotFound":
#                 print(ret, file=sys.stderr)
#                 sys.exit(20)
#             if ret == "EndOfFile":
#                 fp.close()
#                 return
# 
#             fp.write(binascii.a2b_base64(ret))
#             part = part + 1
# 
# Path: elbepack/version.py

# 
# Path: elbepack/config.py
# class Config(dict):
#     def __init__(self):
# 
# Path: elbepack/elbexml.py
# class ValidationMode:
#     NO_CHECK = 1
#     CHECK_BINARIES = 2
#     CHECK_ALL = 0


import socket
import sys
from http.client import BadStatusLine
from optparse import (OptionParser, OptionGroup)
from urllib.error import URLError
from suds import WebFault
from elbepack.soapclient import ClientAction, ElbeSoapClient
from elbepack.version import elbe_version
from elbepack.config import cfg
from elbepack.elbexml import ValidationMode
# ELBE - Debian Based Embedded Rootfilesystem Builder
# Copyright (c) 2014, 2016-2017 Manuel Traut <manut@linutronix.de>
# Copyright (c) 2015-2016 Torben Hohn <torben.hohn@linutronix.de>
# Copyright (c) 2017 Philipp Arras <philipp.arras@linutronix.de>
#
# SPDX-License-Identifier: GPL-3.0-or-later






def run_command(argv):

    # pylint: disable=too-many-statements

    oparser = OptionParser(usage="usage: elbe control [options] <command>")

    oparser.add_option("--host", dest="host", default=cfg['soaphost'],
                       help="Ip or hostname of elbe-daemon.")

    oparser.add_option("--port", dest="port", default=cfg['soapport'],
                       help="Port of soap itf on elbe-daemon.")


# Path: elbepack/soapclient.py
# class ClientAction:
#     actiondict = {}
# 
#     @classmethod
#     def register(cls, action):
#         cls.actiondict[action.tag] = action
# 
#     @classmethod
#     def print_actions(cls):
#         print("available subcommands are:", file=sys.stderr)
#         for a in cls.actiondict:
#             print("   %s" % a, file=sys.stderr)
# 
#     def __new__(cls, node):
#         action = cls.actiondict[node]
#         return object.__new__(action)
# 
#     def __init__(self, node):
#         self.node = node
# 
#     @staticmethod
#     def upload_file(append, build_dir, filename):
# 
#         size = 1024 * 1024
# 
#         with open(filename, "rb") as f:
# 
#             while True:
# 
#                 bin_data = f.read(size)
#                 data = binascii.b2a_base64(bin_data)
# 
#                 if not isinstance(data, str):
#                     data = data.decode("ascii")
# 
#                 append(build_dir, data)
# 
#                 if len(bin_data) != size:
#                     break
# 
#     def execute(self, _client, _opt, _args):
#         raise NotImplementedError('execute() not implemented')
# 
# class ElbeSoapClient:
#     def __init__(self, host, port, user, passwd, retries=10, debug=False):
# 
#         # pylint: disable=too-many-arguments
# 
#         # Mess with suds logging, for debug, or squelch warnings
#         set_suds_debug(debug)
# 
#         # Attributes
#         self.wsdl = "http://" + host + ":" + str(port) + "/soap/?wsdl"
#         self.control = None
#         self.retries = 0
# 
#         # Loop and try to connect
#         while self.control is None:
#             self.retries += 1
#             try:
#                 self.control = Client(self.wsdl, timeout=cfg['soaptimeout'])
#             except URLError as e:
#                 if self.retries > retries:
#                     raise e
#                 time.sleep(1)
#             except socket.error as e:
#                 if self.retries > retries:
#                     raise e
#                 time.sleep(1)
#             except BadStatusLine as e:
#                 if self.retries > retries:
#                     raise e
#                 time.sleep(1)
# 
#         # Make sure, that client.service still maps
#         # to the service object.
#         self.service = self.control.service
# 
#         # We have a Connection, now login
#         self.service.login(user, passwd)
# 
#     def download_file(self, builddir, filename, dst_fname):
#         fp = open(dst_fname, "wb")
#         part = 0
# 
#         # XXX the retry logic might get removed in the future, if the error
#         # doesn't occur in real world. If it occurs, we should think about
#         # the root cause instead of stupid retrying.
#         retry = 5
# 
#         while True:
#             try:
#                 ret = self.service.get_file(builddir, filename, part)
#             except BadStatusLine as e:
#                 retry = retry - 1
# 
#                 print("get_file part %d failed, retry %d times" % (part, retry),
#                       file=sys.stderr)
#                 print(str(e), file=sys.stderr)
#                 print(repr(e.line), file=sys.stderr)
# 
#                 if not retry:
#                     fp.close()
#                     print("file transfer failed", file=sys.stderr)
#                     sys.exit(20)
# 
#             if ret == "FileNotFound":
#                 print(ret, file=sys.stderr)
#                 sys.exit(20)
#             if ret == "EndOfFile":
#                 fp.close()
#                 return
# 
#             fp.write(binascii.a2b_base64(ret))
#             part = part + 1
# 
# Path: elbepack/version.py

# 
# Path: elbepack/config.py
# class Config(dict):
#     def __init__(self):
# 
# Path: elbepack/elbexml.py
# class ValidationMode:
#     NO_CHECK = 1
#     CHECK_BINARIES = 2
#     CHECK_ALL = 0


# Path: elbepack/commands/control.py
import socket
import sys
from http.client import BadStatusLine
from optparse import (OptionParser, OptionGroup)
from urllib.error import URLError
from suds import WebFault
from elbepack.soapclient import ClientAction, ElbeSoapClient
from elbepack.version import elbe_version
from elbepack.config import cfg
from elbepack.elbexml import ValidationMode

# ELBE - Debian Based Embedded Rootfilesystem Builder
# Copyright (c) 2014, 2016-2017 Manuel Traut <manut@linutronix.de>
# Copyright (c) 2015-2016 Torben Hohn <torben.hohn@linutronix.de>
# Copyright (c) 2017 Philipp Arras <philipp.arras@linutronix.de>
#
# SPDX-License-Identifier: GPL-3.0-or-later






def run_command(argv):

    # pylint: disable=too-many-statements

    oparser = OptionParser(usage="usage: elbe control [options] <command>")

    oparser.add_option("--host", dest="host", default=cfg['soaphost'],
                       help="Ip or hostname of elbe-daemon.")

    oparser.add_option("--port", dest="port", default=cfg['soapport'],
                       help="Port of soap itf on elbe-daemon.")


    oparser.add_option("--pass", dest="passwd", default=cfg['elbepass'],