# Path: modules/fflock_globals.py
# DATABASE_HOST = "192.168.206.133"
# DATABASE_PORT = 3306
# DATABASE_USER = "fflock"
# DATABASE_PASSWD = "fflock"
# DATABASE_NAME = "fflock"
# ENCODER = "ffmpeg"
# NFS_PATH = ""
# SLAVE_MOUNT_PREFIX_PATH = ""
# S3ID = ""
# S3KEY = ""
# S3BUCKET = ""
# CONFIG_FILE = ""
# FETCH_RETRIES = 3
# 
# Path: modules/fflock_utility.py
# def dbconnect():
# def local_ip_address():
# def public_ip_address():
# def ping(address):
# def clear():
# def get_uuid():
# def getFps(file):
# def getTotalFrames(file, fps):
# def ensure_dir(path, storageuuid):
# def get_storage_nfs_folder_path(storageuuid):
# def check_dependencies(jobuuid):
# def remove_dependency_jobs(jobuuid):
# def job_cleanup(jobuuid, storageuuid, masteruuid, jobinput, joboutput):
# def number_of_registered_slaves():
# def number_of_connected_slaves(storageuuid):
# def find_server_storage_UUIDs(serveruuid):
# def find_master_UUID_for_job(uuid):
# def find_job_options_for_job(uuid):
# def find_storage_UUID_for_job():
# def find_server_for_storage_job():
# def find_server_for_slave_job():
# def download_file_http(url, filename):
# def download_file_ftp(url, filename):
# def upload_file_ftp(source, destination):
# def download_file_s3(url, filename):
# def upload_file_s3(source, destination):
# def parse_config_file(configfile, type):
# def submit_job(jobuuid, jobtype, jobsubtype, command, commandpreoptions, commandoptions, input, output, dependencies,
#                masteruuid, joboptions):


import sys
import os
import time
import signal
import getopt
import glob
from datetime import datetime, timedelta
from modules import fflock_globals
from modules import fflock_utility
    @param argv:
    """

    try:
        opts, args = getopt.getopt(argv, "hd:c:", ["help", "database=", "config="])
    except getopt.GetoptError:
        usage()
        sys.exit(2)
    for opt, arg in opts:
        if opt in ("-h", "--help"):
            usage()
            sys.exit()
        if opt in ("-d", "--database"):
            fflock_globals.DATABASE_HOST = arg.split(':', 1)[0]
            fflock_globals.DATABASE_PORT = arg.split(':', 1)[-1]
            if fflock_globals.DATABASE_PORT == fflock_globals.DATABASE_HOST:
                fflock_globals.DATABASE_PORT = 3306
        if opt in ("-c", "--config"):
            fflock_globals.CONFIG_FILE = arg
    return True


if __name__ == "__main__":
    signal.signal(signal.SIGINT, signal_handler)
    _uuid = fflock_utility.get_uuid()
    _localip = fflock_utility.local_ip_address()
    _publicip = fflock_utility.public_ip_address()

    parse_cmd(sys.argv[1:])
    if fflock_globals.CONFIG_FILE != "":

# Path: modules/fflock_globals.py
# DATABASE_HOST = "192.168.206.133"
# DATABASE_PORT = 3306
# DATABASE_USER = "fflock"
# DATABASE_PASSWD = "fflock"
# DATABASE_NAME = "fflock"
# ENCODER = "ffmpeg"
# NFS_PATH = ""
# SLAVE_MOUNT_PREFIX_PATH = ""
# S3ID = ""
# S3KEY = ""
# S3BUCKET = ""
# CONFIG_FILE = ""
# FETCH_RETRIES = 3
# 
# Path: modules/fflock_utility.py
# def dbconnect():
# def local_ip_address():
# def public_ip_address():
# def ping(address):
# def clear():
# def get_uuid():
# def getFps(file):
# def getTotalFrames(file, fps):
# def ensure_dir(path, storageuuid):
# def get_storage_nfs_folder_path(storageuuid):
# def check_dependencies(jobuuid):
# def remove_dependency_jobs(jobuuid):
# def job_cleanup(jobuuid, storageuuid, masteruuid, jobinput, joboutput):
# def number_of_registered_slaves():
# def number_of_connected_slaves(storageuuid):
# def find_server_storage_UUIDs(serveruuid):
# def find_master_UUID_for_job(uuid):
# def find_job_options_for_job(uuid):
# def find_storage_UUID_for_job():
# def find_server_for_storage_job():
# def find_server_for_slave_job():
# def download_file_http(url, filename):
# def download_file_ftp(url, filename):
# def upload_file_ftp(source, destination):
# def download_file_s3(url, filename):
# def upload_file_s3(source, destination):
# def parse_config_file(configfile, type):
# def submit_job(jobuuid, jobtype, jobsubtype, command, commandpreoptions, commandoptions, input, output, dependencies,
#                masteruuid, joboptions):


# Path: fflock-master.py
import sys
import os
import time
import signal
import getopt
import glob
from datetime import datetime, timedelta
from modules import fflock_globals
from modules import fflock_utility

    @param argv:
    """

    try:
        opts, args = getopt.getopt(argv, "hd:c:", ["help", "database=", "config="])
    except getopt.GetoptError:
        usage()
        sys.exit(2)
    for opt, arg in opts:
        if opt in ("-h", "--help"):
            usage()
            sys.exit()
        if opt in ("-d", "--database"):
            fflock_globals.DATABASE_HOST = arg.split(':', 1)[0]
            fflock_globals.DATABASE_PORT = arg.split(':', 1)[-1]
            if fflock_globals.DATABASE_PORT == fflock_globals.DATABASE_HOST:
                fflock_globals.DATABASE_PORT = 3306
        if opt in ("-c", "--config"):
            fflock_globals.CONFIG_FILE = arg
    return True


if __name__ == "__main__":
    signal.signal(signal.SIGINT, signal_handler)
    _uuid = fflock_utility.get_uuid()
    _localip = fflock_utility.local_ip_address()
    _publicip = fflock_utility.public_ip_address()

    parse_cmd(sys.argv[1:])
    if fflock_globals.CONFIG_FILE != "":

        fflock_utility.parse_config_file(fflock_globals.CONFIG_FILE, "master")