# 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
    jobfileinput = jobinput
    if jobinput.startswith("http://") or jobinput.startswith("https://"):
        download_uuid = fflock_utility.get_uuid()
        jobfileinput = jobinput.split('/')[-1]
        fflock_utility.submit_job(download_uuid, "Storage", "http download", " ", " ", " ", jobinput, jobfileinput, " ",
                                  masteruuid, "")
    if jobinput.startswith("ftp://"):
        download_uuid = fflock_utility.get_uuid()
        jobfileinput = jobinput.split('/')[-1]
        fflock_utility.submit_job(download_uuid, "Storage", "ftp download", " ", " ", " ", jobinput, jobfileinput, " ",
                                  masteruuid, "")
    if jobinput.startswith("s3://"):
        download_uuid = fflock_utility.get_uuid()
        jobfileinput = jobinput.split('/')[-1]
        fflock_utility.submit_job(download_uuid, "Storage", "s3 download", " ", " ", " ", jobinput, jobfileinput, " ",
                                  masteruuid, "")

    return download_uuid, jobfileinput


def upload_external_destination(source, joboutput, dependencies, masteruuid):
    """



    @rtype : boolean
    """
    upload_uuid = " "
    if joboutput.startswith("ftp://"):
        upload_uuid = fflock_utility.get_uuid()

# 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

    jobfileinput = jobinput
    if jobinput.startswith("http://") or jobinput.startswith("https://"):
        download_uuid = fflock_utility.get_uuid()
        jobfileinput = jobinput.split('/')[-1]
        fflock_utility.submit_job(download_uuid, "Storage", "http download", " ", " ", " ", jobinput, jobfileinput, " ",
                                  masteruuid, "")
    if jobinput.startswith("ftp://"):
        download_uuid = fflock_utility.get_uuid()
        jobfileinput = jobinput.split('/')[-1]
        fflock_utility.submit_job(download_uuid, "Storage", "ftp download", " ", " ", " ", jobinput, jobfileinput, " ",
                                  masteruuid, "")
    if jobinput.startswith("s3://"):
        download_uuid = fflock_utility.get_uuid()
        jobfileinput = jobinput.split('/')[-1]
        fflock_utility.submit_job(download_uuid, "Storage", "s3 download", " ", " ", " ", jobinput, jobfileinput, " ",
                                  masteruuid, "")

    return download_uuid, jobfileinput


def upload_external_destination(source, joboutput, dependencies, masteruuid):
    """



    @rtype : boolean
    """
    upload_uuid = " "
    if joboutput.startswith("ftp://"):
        upload_uuid = fflock_utility.get_uuid()

        fflock_utility.submit_job(upload_uuid, "Storage", "ftp upload", " ", " ", " ", source, joboutput, dependencies,