def _ping(self): """ Ping the Docker Daemon :return: """ try: return self._client.ping() except ConnectionError as e: Log.e(e) Log.i("Docker Daemon became unresponsive") self._change_status(ManagerStatus.DISCONNECTED) return False
def _connect(self): try: Log.i("Attempt to contact Docker Daemon") self._change_status(ManagerStatus.ATTEMPT_CONNECT) self._client = DockerClient.from_env(**self._kwargs) self._last_ping = datetime.now() Log.i("Connected to Docker Daemon") self._change_status(ManagerStatus.CONNECTED) self.refresh_all() except DockerException as e: Log.e(e) self._stop = True self._change_status(ManagerStatus.DISCONNECTED)
def upgrade(self): """ Upgrade script for now :return: """ try: Log.i("Upgrade Started") self._dao_environment.drop() self._dao_environment.init() self.handle_sql_error(self._conn.lastError()) # Insert Local VM environment env = self._dao_environment.create_env( DEnvEnvironment(name='Local VM')) if env is not None: self._dao_environment.create_env_setting( env, ('DOCKER_HOST', 'tcp://10.0.0.17:2375')) self._dao_environment.create_env_setting( env, ('DOCKER_TLS_VERIFY', '')) self._dao_environment.create_env_setting( env, ('DOCKER_CERT_PATH', '')) # Insert Linux environment env = self._dao_environment.create_env( DEnvEnvironment(name='Linux')) if env is not None: self._dao_environment.create_env_setting( env, ('DOCKER_HOST', 'unix:///var/run/docker.sock')) self._dao_environment.create_env_setting( env, ('DOCKER_TLS_VERIFY', '')) self._dao_environment.create_env_setting( env, ('DOCKER_CERT_PATH', '')) self._dao_registry.drop() self._dao_registry.init() # Insert Local Docker Registry entry registry_id = self._dao_registry.insert_registry( 'Local VM', 'localhost:5000') # Commit all changes to database self.handle_sql_error(self._conn.lastError()) except QSqlError as e: self.handle_sql_error(e) # Close database connection self._conn.close()
def init_env(self, timeout=120, version='auto', env=None): kwargs = {'timeout': timeout, 'version': version, 'environment': env} try: self._client = DockerClient.from_env(**kwargs) version = self._client.api.version() DebugConsole.println('Environment loaded for %s' % env['DOCKER_HOST']) Log.i( 'Initialized communication using Docker Engine API version %s' % version['ApiVersion']) self._change_status(ManagerStatus.CONNECTED) self.refresh_all() Log.i('Loaded environment') except DockerException as e: print("DockerManager :: %s" % e) self._change_status(ManagerStatus.DISCONNECTED) DebugConsole.println('Docker Client could not load environment') Log.e('Docker Client could not load environment')
def run(self): Log.i("Manager Started [%s]" % self._env.name) while self._stop is not True: if self._status == ManagerStatus.DISCONNECTED: self._connect() time.sleep(2) if self._status == ManagerStatus.CONNECTED: diff = (datetime.now() - self._last_ping).total_seconds() if diff > 30: try: if self._ping(): self._last_ping = datetime.now() Log.i("Docker Daemon is responsive") except APIError as e: Log.e(e) Log.i("Docker Daemon became unresponsive") self._change_status(ManagerStatus.DISCONNECTED) self._close() Log.i("Manager stopped")
def main(): global app global threads Log.__init__(None) Log.i("Performing DB Init") upgrade = Upgrade() upgrade.upgrade() Log.i('Starting GUI') app = QApplication(sys.argv) Log.i('Process ID %s' % app.applicationPid()) app.setStyle('Fusion') app.focusWidget() window = MainWindow() app.setActiveWindow(window) window.show() threads = [] sys.excepthook = handle_exception sys.exit(app.exec_())
def media_transform(parser, options): #keep track if we do anything other than copying tcodeVideo = False tcodeAudio = False # Start with the video. # We're going to check the parser video_stream and compare it to our target. cstream = parser.video_stream voptions = options["video"] codec = "copy" if cstream["codec"] != voptions["codec"] or voptions["force"] == True: if voptions["allowhevc"] == True and cstream["codec"] == "hevc": Log.i(TAG, "Skipping transcode for HVEC as per override.") else: tcodeVideo = True Log.i(TAG, "Transcoding video track") codec = voptions["codec"] else: Log.i(TAG, "Copying video track") deinterlace = False if (parser.is_interlaced and voptions["deinterlace"] == "yes") or voptions["deinterlace"] == "forced": Log.i(TAG, "Deinterlacing video track (will cause transcode!)") tcodeVideo = True codec = voptions["codec"] deinterlace = True scaleopts = False if voptions["res"] != "keep": dres = 0 if voptions["res"] == "1080p": dres = 1080 elif voptions["res"] == "720p": dres = 720 elif voptions["res"] == "480p": dres = 480 if (cstream["height"] < dres): scaleopts = False elif (abs(cstream["height"] - dres) < 30): scaleopts = False else: Log.i(TAG, "Scaling video (will cause transcode!)") codec = voptions["codec"] scaleopts = dres bit10 = False if "10bit" in voptions: bit10 = voptions["10bit"] video_build = { "type": "video", "index": cstream["index"], "codec": codec, "quality": voptions["quality"], "deinterlacing": deinterlace, "scaleopts": scaleopts, "10bit": bit10 } if options["video"]["ignore"] == True: Log.w(TAG, "Ignoring incorrect video codec") video_build = { "type": "video", "index": cstream["index"], "codec": "copy", "quality": "10", "deinterlacing": False, "scaleopts": False } aoptions = options["audio"] audio_building = [] surround_exists = False stereo_exists = False #Now the hard part. Figuring out the mess of audio streams #Find the master track. This is the highest bitrate, highest number of channels stream, which is also in the right language. audio_master = {"channels": 0, 'language': 'und'} audio_stereo = None ignore_language = False valid_laguages = ["eng"] if "lang" in aoptions: if "ignore" in aoptions["lang"] and aoptions["lang"]["ignore"] == True: ignore_language = True if "allowed" in aoptions["lang"]: valid_languages = aoptions["lang"]["allowed"] #this feels naieve. Take a closer look at this! for track in parser.audio_streams: if ignore_language or (track["language"] in valid_languages or track["language"] == "und" or track["language"] == None): if track["channels"] > audio_master["channels"]: audio_master = track if track["channels"] < 6: audio_stereo = track stereo_exists = True if audio_master["channels"] > 2: surround_exists = True #Add our audio channels. #Use the existing surround track if surround_exists and aoptions["surround"]["keep"] == True: audio_building.append({ "type": "audio", "index": audio_master["index"], "codec": "copy", "ffprocdown": False, "downconvert": False }) Log.i(TAG, "Copying surround audio") #Use our existing stereo track. if stereo_exists and aoptions["stereo"]["keep"] == True: if "aac" == audio_stereo["codec"]: Log.i(TAG, "Copying stereo audio") audio_building.append({ "type": "audio", "index": audio_stereo["index"], "codec": "copy", "ffprocdown": False, "downconvert": False }) else: tcodeAudio = True Log.i(TAG, "Transcoding existing stereo audio") audio_building.append({ "type": "audio", "index": audio_stereo["index"], "codec": "aac", "bitrate": aoptions["stereo"]["bitrate"], "downconvert": False, "forcefdk": aoptions["stereo"]["force_libfdk"], "ffprocdown": False }) #Create from surround. if surround_exists and (not stereo_exists or aoptions["stereo"]["keep"] == False) and aoptions["stereo"]["create"] == True: Log.i(TAG, "Downmixing surround to stereo") tcodeAudio = True audio_building.append({ "type": "audio", "index": audio_master["index"], "codec": "aac", "bitrate": aoptions["stereo"]["bitrate"], "downconvert": True, "forcefdk": aoptions["stereo"]["force_libfdk"], "ffprocdown": aoptions["stereo"]["ffproc_filtering"] }) #Are we doing any transcoding? tcode = tcodeVideo or tcodeAudio remux = False if not tcode and parser.file_format.find( options["format"]["filetype"]) == -1: remux = True audio_building.append(video_build) return { "video": tcodeVideo, "audio": tcodeAudio, "remux": remux, "tcodeData": audio_building }
def finished(self): Log.i("finished() called")
def stop_container(self, model: ContainerClientModel = None, timeout=120): self._general_signals.show_loading_signal.emit(True, 'Stopping %s ...' % model.names) result = self._client.api.stop(model.id, timeout=timeout) Log.i('Container Stop Result %s' % result) self._signals.refresh_containers_signal.emit(self._client.api.containers(all=True)) self._general_signals.show_loading_signal.emit(False, '')
if profile not in allprofiles: Log.e(TAG, "Profile " + profile+" does not exist!") sys.exit() discoveredprofile = allprofiles[profile] #TODO: use argparse here thistask = transformer.ffmpeg_tasks_create(fileparsed,discoveredprofile) if thistask != None: thistask.infile = startfilename thistask.outfile = endfilename thistask.forcefdk = discoveredprofile["audio"]["stereo"]["force_libfdk"] Log.i(TAG, "Enqueing " + os.path.basename(startfilename) + " for " + thistask.tasktype) if arguments.showcommand == True: Log.v(TAG, "ffmpeg command: " + " ".join(thistask.arguments)) if arguments.dryrun == False and useredis == True: redaddr = arguments.redis if isinstance(redaddr, list): redaddr = arguments.redis[0] q = Queue(thistask.tasktype, connection=Redis(redaddr)) q.enqueue_call("worker.ffmpeg", args=(str(thistask),),timeout=360000) else: if arguments.dryrun == True: Log.e(TAG, "Did not enqueue as per command line options") else: Log.e(TAG, "Running ffmpeg locally.") import worker worker.ffmpeg(str(thistask))
discoveredprofile = allprofiles[profile] extension = "mp4" if discoveredprofile["format"]["filetype"] == "matroska": extension = "mkv" endfilename = ".".join(arguments.file.split(".")[:-1] + [extension]) thistask = transformer.ffmpeg_tasks_create(fileparsed,discoveredprofile) if thistask != None: thistask.infile = startfilename thistask.outfile = endfilename thistask.forcefdk = discoveredprofile["audio"]["stereo"]["force_libfdk"] Log.i(TAG, "Enqueing " + os.path.basename(startfilename) + " for " + thistask.tasktype) if arguments.showcommand == True: Log.v(TAG, "ffmpeg command: " + " ".join(thistask.arguments)) if arguments.dryrun == False and useredis == True: redaddr = arguments.redis if isinstance(redaddr, list): redaddr = arguments.redis[0] q = Queue(thistask.tasktype, connection=Redis(redaddr)) q.enqueue_call("worker.ffmpeg", args=(str(thistask),),timeout=360000) else: if arguments.dryrun == True: Log.e(TAG, "Did not enqueue as per command line options") else: Log.e(TAG, "Running ffmpeg locally.") import worker worker.ffmpeg(str(thistask))
def media_transform(parser, options): #keep track if we do anything other than copying tcodeVideo=False tcodeAudio=False # Start with the video. # We're going to check the parser video_stream and compare it to our target. cstream = parser.video_stream voptions = options["video"] codec = "copy" if cstream["codec"] != voptions["codec"] or voptions["force"] == True: if voptions["allowhevc"] == True and cstream["codec"] == "hevc": Log.i(TAG, "Skipping transcode for HVEC as per override.") else: tcodeVideo = True Log.i(TAG, "Transcoding video track") codec = voptions["codec"] else: Log.i(TAG, "Copying video track") deinterlace = False if (parser.is_interlaced and voptions["deinterlace"] == "yes") or voptions["deinterlace"] == "forced": Log.i(TAG, "Deinterlacing video track (will cause transcode!)") tcodeVideo=True codec = voptions["codec"] deinterlace = True scaleopts = False if voptions["res"] != "keep": dres = 0 if voptions["res"] == "1080p": dres = 1080 elif voptions["res"] == "720p": dres = 720 elif voptions["res"] == "480p": dres = 480 if(cstream["height"] < dres): scaleopts = False elif(abs(cstream["height"] - dres) < 30): scaleopts = False else: Log.i(TAG, "Scaling video (will cause transcode!)") codec = voptions["codec"] scaleopts = dres video_build = {"type":"video", "index":cstream["index"], "codec": codec, "quality": voptions["quality"], "deinterlacing": deinterlace, "scaleopts": scaleopts} if options["video"]["ignore"] == True: Log.w(TAG, "Ignoring incorrect video codec") video_build = {"type":"video", "index":cstream["index"], "codec": "copy", "quality": "10", "deinterlacing": False, "scaleopts": False} aoptions = options["audio"] audio_building=[] surround_exists = False stereo_exists = False #Now the hard part. Figuring out the mess of audio streams #Find the master track. This is the highest bitrate, highest number of channels stream, which is also in the right language. audio_master = {"channels": 0, 'language':'und'} audio_stereo = None #this feels naieve. Take a closer look at this! for track in parser.audio_streams: if ( track["language"] == "eng" or track["language"] == "und" or track["language"] == None): if track["channels"] > audio_master["channels"]: audio_master = track if track["channels"] < 6: audio_stereo = track stereo_exists = True if audio_master["channels"] > 2: surround_exists = True #Add our audio channels. #Use the existing surround track if surround_exists and aoptions["surround"]["keep"] == True: audio_building.append({"type":"audio","index":audio_master["index"], "codec": "copy","ffprocdown":False,"downconvert":False}) Log.i(TAG, "Copying surround audio") #Use our existing stereo track. if stereo_exists and aoptions["stereo"]["keep"] == True: if "aac" == audio_stereo["codec"]: Log.i(TAG, "Copying stereo audio") audio_building.append({"type":"audio","index":audio_stereo["index"], "codec": "copy","ffprocdown":False,"downconvert":False}) else: tcodeAudio = True Log.i(TAG, "Transcoding existing stereo audio") audio_building.append({"type":"audio","index":audio_master["index"], "codec": "aac", "bitrate": aoptions["stereo"]["bitrate"],"downconvert":False, "forcefdk":aoptions["stereo"]["force_libfdk"],"ffprocdown":False}) #Create from surround. if surround_exists and (not stereo_exists or aoptions["stereo"]["keep"] == False) and aoptions["stereo"]["create"] == True: Log.i(TAG, "Downmixing surround to stereo") tcodeAudio = True audio_building.append({"type":"audio","index":audio_master["index"], "codec": "aac", "bitrate": aoptions["stereo"]["bitrate"],"downconvert":True, "forcefdk":aoptions["stereo"]["force_libfdk"],"ffprocdown":aoptions["stereo"]["ffproc_filtering"]}) #Are we doing any transcoding? tcode = tcodeVideo or tcodeAudio remux = False if not tcode and parser.file_format.find(options["format"]["filetype"]) == -1: remux = True audio_building.append(video_build) return {"video": tcodeVideo, "audio": tcodeAudio, "remux": remux, "tcodeData":audio_building}