# Path: lib/env.py
# def setEnvFromFile(batFilePath, verbose = False):
# 
# Path: lib/sitkaAPI.py
# def downloadUnzipTopo(visitID, unzipPath):
#     """
#     Download a topo zip file to a local path using a visitID
#     :param visitID:
#     :param zipFilePath:
#     :return:
#     """
#     tokenator = Tokenator()
#     log = Logger("downloadTopoZip")
# 
#     # First find the appropriate download URL
#     try:
#         topoFieldFolders = APIGet('visits/{}/fieldFolders/Topo'.format(visitID))
# 
#         log.debug("Getting visit file data")
#         file = next(file for file in topoFieldFolders['files'] if file['componentTypeID'] == 181)
#         downloadUrl = file['downloadUrl']
#     except Exception, e:
#         raise MissingException("ERROR: No TopoData.zip file found for visit".format(visitID))
# 
#     # Download the file to a temporary location
#     with NamedTemporaryFile() as f:
#         response = APIGet(downloadUrl, absolute=True)
#         f.write(response.content)
# 
#         log.debug("Downloaded file: {} to: {}".format(downloadUrl, f.name))
# 
#         # Now we have it. Unzip
#         with zipfile.ZipFile(f, 'r') as zip_ref:
#             log.debug("Unzipping file: {} to: {}".format(f.name, unzipPath))
#             zip_ref.extractall(unzipPath)
# 
#         # Return a folder where we can find a project.rs.xml (or not)
#         projpath = None
#         for root, subFolders, files in os.walk(unzipPath):
#             if "project.rs.xml" in files:
#                 projpath = root
# 
#     return file, projpath
# 
# Path: lib/loghelper.py
# class Logger():
#     """
#     Think of this class like a light interface
#     """
# 
#     def __init__(self, method=""):
#         self.instance = _LoggerSingleton()
#         self.method = method
# 
#     def setup(self, **kwargs):
#         self.instance.setup(**kwargs)
# 
#     def print_(self, message, **kwargs):
#         self.instance.logprint(message, **kwargs)
# 
#     def debug(self, *args):
#         """
#         This works a little differently. You can basically throw anything you want into it.
#         :param message:
#         :return:
#         """
#         msgarr =  []
#         for arg in args:
#             if type(arg) is str:
#                 msgarr.append(arg)
#             else:
#                 msgarr.append(pformat(arg))
#         finalmessage = '\n'.join(msgarr).replace('\n', '\n              ')
#         self.instance.logprint(finalmessage, self.method, "debug")
# 
#     def destroy(self):
#         self.instance = None
#         self.method = None
# 
#     def info(self, message):
#         self.instance.logprint(message, self.method, "info")
# 
#     def error(self, message, exception=None):
#         self.instance.logprint(message, self.method, "error", exception)
# 
#     def warning(self, message, exception=None):
#         self.instance.logprint(message, self.method, "warning", exception)
# 
# Path: lib/exception.py
# class DataException(Exception):
# 
#     def __init__(self, message):
#         # Call the base class constructor with the parameters it needs
#         super(DataException, self).__init__(message)
#         self.returncode = 2
#         logg = Logger('DataException')
#         logg.error(message)
# 
# class MissingException(Exception):
# 
#     def __init__(self, message):
#         # Call the base class constructor with the parameters it needs
#         super(MissingException, self).__init__(message)
#         self.returncode = 4
# 
#         logg = Logger('MissingException')
#         logg.error(message)
# 
# class NetworkException(Exception):
# 
#     def __init__(self, message):
#         # Call the base class constructor with the parameters it needs
#         super(NetworkException, self).__init__(message)
#         self.returncode = 3
# 
#         logg = Logger('NetworkException')
#         logg.error(message)


import argparse
import sys, traceback
import os
import xml.etree.ElementTree as ET
import geopandas, rasterio
import numpy as np
    import datetime
from os import path
from shapely.geometry import Point
from lib import env
from lib.sitkaAPI import downloadUnzipTopo
from lib.loghelper import Logger
from lib.exception import DataException, MissingException, NetworkException
        from lib.topoproject import TopoProject
        if not elem.tail or not elem.tail.strip():
            elem.tail = i
            if more_sibs:
                elem.tail += '  '
    else:
        if level and (not elem.tail or not elem.tail.strip()):
            elem.tail = i
            if more_sibs:
                elem.tail += '  '


def main():
    # parse command line options
    parser = argparse.ArgumentParser()
    parser.add_argument('visitID', help='Visit ID', type=int)
    parser.add_argument('outputfolder', help='Path to output folder', type=str)
    parser.add_argument('--datafolder', help='(optional) Top level folder containing TopoMetrics Riverscapes projects', type=str)
    parser.add_argument('--verbose', help='Get more information in your logs.', action='store_true', default=False )
    args = parser.parse_args()

    # Make sure the output folder exists
    resultsFolder = os.path.join(args.outputfolder, "outputs")

    # Initiate the log file
    logg = Logger("Program")
    logfile = os.path.join(resultsFolder, "bankfull_metrics.log")
    xmlfile = os.path.join(resultsFolder, "bankfull_metrics.xml")
    logg.setup(logPath=logfile, verbose=args.verbose)

    # Initiate the log file

# Path: lib/env.py
# def setEnvFromFile(batFilePath, verbose = False):
# 
# Path: lib/sitkaAPI.py
# def downloadUnzipTopo(visitID, unzipPath):
#     """
#     Download a topo zip file to a local path using a visitID
#     :param visitID:
#     :param zipFilePath:
#     :return:
#     """
#     tokenator = Tokenator()
#     log = Logger("downloadTopoZip")
# 
#     # First find the appropriate download URL
#     try:
#         topoFieldFolders = APIGet('visits/{}/fieldFolders/Topo'.format(visitID))
# 
#         log.debug("Getting visit file data")
#         file = next(file for file in topoFieldFolders['files'] if file['componentTypeID'] == 181)
#         downloadUrl = file['downloadUrl']
#     except Exception, e:
#         raise MissingException("ERROR: No TopoData.zip file found for visit".format(visitID))
# 
#     # Download the file to a temporary location
#     with NamedTemporaryFile() as f:
#         response = APIGet(downloadUrl, absolute=True)
#         f.write(response.content)
# 
#         log.debug("Downloaded file: {} to: {}".format(downloadUrl, f.name))
# 
#         # Now we have it. Unzip
#         with zipfile.ZipFile(f, 'r') as zip_ref:
#             log.debug("Unzipping file: {} to: {}".format(f.name, unzipPath))
#             zip_ref.extractall(unzipPath)
# 
#         # Return a folder where we can find a project.rs.xml (or not)
#         projpath = None
#         for root, subFolders, files in os.walk(unzipPath):
#             if "project.rs.xml" in files:
#                 projpath = root
# 
#     return file, projpath
# 
# Path: lib/loghelper.py
# class Logger():
#     """
#     Think of this class like a light interface
#     """
# 
#     def __init__(self, method=""):
#         self.instance = _LoggerSingleton()
#         self.method = method
# 
#     def setup(self, **kwargs):
#         self.instance.setup(**kwargs)
# 
#     def print_(self, message, **kwargs):
#         self.instance.logprint(message, **kwargs)
# 
#     def debug(self, *args):
#         """
#         This works a little differently. You can basically throw anything you want into it.
#         :param message:
#         :return:
#         """
#         msgarr =  []
#         for arg in args:
#             if type(arg) is str:
#                 msgarr.append(arg)
#             else:
#                 msgarr.append(pformat(arg))
#         finalmessage = '\n'.join(msgarr).replace('\n', '\n              ')
#         self.instance.logprint(finalmessage, self.method, "debug")
# 
#     def destroy(self):
#         self.instance = None
#         self.method = None
# 
#     def info(self, message):
#         self.instance.logprint(message, self.method, "info")
# 
#     def error(self, message, exception=None):
#         self.instance.logprint(message, self.method, "error", exception)
# 
#     def warning(self, message, exception=None):
#         self.instance.logprint(message, self.method, "warning", exception)
# 
# Path: lib/exception.py
# class DataException(Exception):
# 
#     def __init__(self, message):
#         # Call the base class constructor with the parameters it needs
#         super(DataException, self).__init__(message)
#         self.returncode = 2
#         logg = Logger('DataException')
#         logg.error(message)
# 
# class MissingException(Exception):
# 
#     def __init__(self, message):
#         # Call the base class constructor with the parameters it needs
#         super(MissingException, self).__init__(message)
#         self.returncode = 4
# 
#         logg = Logger('MissingException')
#         logg.error(message)
# 
# class NetworkException(Exception):
# 
#     def __init__(self, message):
#         # Call the base class constructor with the parameters it needs
#         super(NetworkException, self).__init__(message)
#         self.returncode = 3
# 
#         logg = Logger('NetworkException')
#         logg.error(message)


# Path: tools/topometrics/methods/bankfull.py
import argparse
import sys, traceback
import os
import xml.etree.ElementTree as ET
import geopandas, rasterio
import numpy as np
    import datetime
from os import path
from shapely.geometry import Point
from lib import env
from lib.sitkaAPI import downloadUnzipTopo
from lib.loghelper import Logger
from lib.exception import DataException, MissingException, NetworkException
        from lib.topoproject import TopoProject

        if not elem.tail or not elem.tail.strip():
            elem.tail = i
            if more_sibs:
                elem.tail += '  '
    else:
        if level and (not elem.tail or not elem.tail.strip()):
            elem.tail = i
            if more_sibs:
                elem.tail += '  '


def main():
    # parse command line options
    parser = argparse.ArgumentParser()
    parser.add_argument('visitID', help='Visit ID', type=int)
    parser.add_argument('outputfolder', help='Path to output folder', type=str)
    parser.add_argument('--datafolder', help='(optional) Top level folder containing TopoMetrics Riverscapes projects', type=str)
    parser.add_argument('--verbose', help='Get more information in your logs.', action='store_true', default=False )
    args = parser.parse_args()

    # Make sure the output folder exists
    resultsFolder = os.path.join(args.outputfolder, "outputs")

    # Initiate the log file
    logg = Logger("Program")
    logfile = os.path.join(resultsFolder, "bankfull_metrics.log")
    xmlfile = os.path.join(resultsFolder, "bankfull_metrics.xml")
    logg.setup(logPath=logfile, verbose=args.verbose)

    # Initiate the log file

    log = Logger("Program")