#!/usr/bin/env python from dataclasses import dataclass, field from collections import Counter import sys, re, os, enum, itertools, inspect from functools import partial, partialmethod from time import sleep from subprocess import Popen, PIPE, DEVNULL from operator import itemgetter from defl import ( log, cl, Dath, Tree, Undefined, Null, Assert, Time, Obj, IterableType, isIterableType, Run, checkType, richReprAuto, quoteSh, ) from defl import CLIError from defl._typing_ import * from defl._typing_ import T, F, N, U from defl._rich_ import * import defl import argparse import json import defl from defl import cl from defl.testing_ import Tester tester = Tester(name=__file__) ########################################### toTree = { 'format': { 'bit_rate': '137650', 'duration': '10.010000', 'filename': './downConvert_S01E05.avi_spd-fast_crf-28_sh-480-qsc-9.mp4[section_90-100].mp4', 'format_long_name': 'QuickTime / MOV', 'format_name': 'mov,mp4,m4a,3gp,3g2,mj2', 'nb_programs': 0, 'nb_streams': 2, 'probe_score': 100, 'size': '172235', 'start_time': '0.000000', 'tags': { 'compatible_brands': 'isomiso2avc1mp41', 'encoder': 'Lavf58.76.100', 'major_brand': 'isom', 'minor_version': '512', }, }, 'streams': [ { 'avg_frame_rate': '24000/1001', 'bit_rate': '59576', 'bits_per_raw_sample': '8', 'chroma_location': 'left', 'closed_captions': 0, 'codec_long_name': 'H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10', 'codec_name': 'h264', 'codec_tag': '0x31637661', 'codec_tag_string': 'avc1', 'codec_type': 'video', 'coded_height': 134, 'coded_width': 240, 'display_aspect_ratio': '9:5', 'disposition': { 'attached_pic': 0, 'clean_effects': 0, 'comment': 0, 'default': 1, 'dub': 0, 'forced': 0, 'hearing_impaired': 0, 'karaoke': 0, 'lyrics': 0, 'original': 0, 'timed_thumbnails': 0, 'visual_impaired': 0, }, 'duration': '10.010000', 'duration_ts': 240240, 'has_b_frames': 2, 'height': 134, 'index': 0, 'is_avc': 'true', 'level': 12, 'nal_length_size': '4', 'nb_frames': '240', 'pix_fmt': 'yuv420p', 'profile': 'High', 'r_frame_rate': '24000/1001', 'refs': 1, 'sample_aspect_ratio': '201:200', 'start_pts': 0, 'start_time': '0.000000', 'tags': {'handler_name': 'VideoHandler', 'language': 'und', 'vendor_id': '[0][0][0][0]'}, 'time_base': '1/24000', 'width': 240, }, { 'avg_frame_rate': '0/0', 'bit_rate': '70940', 'bits_per_sample': 0, 'channel_layout': 'mono', 'channels': 1, 'codec_long_name': 'AAC (Advanced Audio Coding)', 'codec_name': 'aac', 'codec_tag': '0x6134706d', 'codec_tag_string': 'mp4a', 'codec_type': 'audio', 'disposition': { 'attached_pic': 0, 'clean_effects': 0, 'comment': 0, 'default': 1, 'dub': 0, 'forced': 0, 'hearing_impaired': 0, 'karaoke': 0, 'lyrics': 0, 'original': 0, 'timed_thumbnails': 0, 'visual_impaired': 0, }, 'duration': '10.000000', 'duration_ts': 441000, 'index': 1, 'nb_frames': '432', 'profile': 'LC', 'r_frame_rate': '0/0', 'sample_fmt': 'fltp', 'sample_rate': '44100', 'start_pts': 0, 'start_time': '0.000000', 'tags': {'handler_name': 'SoundHandler', 'language': 'und', 'vendor_id': '[0][0][0][0]'}, 'time_base': '1/44100', }, ], } @tester.add() def test(): tree = defl.Tree(toTree) assert defl.jdumps(tree) == defl.jdumps(toTree) t = defl.Tree() # t[[1]] = "4" # t[[1, 1]] = "4" t[[1, 1, 1]] = '4' # t[2] = "5" # t[2, 2] = "5" t[2, 2, 2] = '5' # t[3][3][3] = "6" t[10, 11, 12, 13] = '21' t[10, 11, 12, 14] = '22' t[10, 11, 12, 14] = '22' # assert defl.jdumps(t) == defl.jdumps({ # "1": { # "1": { # "1": "4" # } # }, # "2": { # "2": { # "2": "5" # } # }, # "10": { # "11": { # "12": { # "13": "21", # "14": "22" # } # } # } # }) # t.inc(1, 1, 1, 1, 1, 1) obj = [-1] * 5 for i in range(5): t.inc(*obj) assert t[obj] == 5 ta = Tree({'8a': '9a', '1a': {'2a': {'3a': '4a'}, '5a': {'6a': '7a'}}}) tb = Tree({'8b': '9b', '1b': {'2b': {'3b': '4b'}, '5b': {'6b': '7b'}}}) @tester.add() def iterKeys(): x = [x for x in ta.iterKeys()] Assert(x) == [('8a',), ('1a', '2a', '3a'), ('1a', '5a', '6a')] @tester.add() def iter(): x = [x for x in ta] Assert(x) == [(('8a',), '9a'), (('1a', '2a', '3a'), '4a'), (('1a', '5a', '6a'), '7a')] @tester.add() def merge(): m = ta | tb Assert(m) == Tree( data={ '1a': {'2a': {'3a': ('4a', U)}, '5a': {'6a': ('7a', U)}}, '1b': {'5b': {'6b': (U, '7b')}, '2b': {'3b': (U, '4b')}}, '8b': (U, '9b'), '8a': ('9a', U), } ) log.info(tester.run()) tester.exitWithStatus()