diff --git a/prepare_dist_package.sh b/prepare_dist_package.sh new file mode 100755 index 0000000..c7d2afd --- /dev/null +++ b/prepare_dist_package.sh @@ -0,0 +1,32 @@ +#!/bin/sh +# remove ~, pyc, pyo files from current directory + +mkdir t 2>/dev/null +if [ $? != 0 ]; then + echo "cannot create directory 't': File exist." + echo "Rename it, move or rename, bcoz it's on the way." + exit +fi +cd t +alias ls=ls + +PREV=`ls -1 ..|grep bz2|tail -n 1|cut -f '2' -d '_'|cut -f 1 -d '.'` +REV=`svn export svn://10.0.0.10/repos/Python/pyGTKtalog pyGTKtalog |tail -n 1|cut -f 3 -d " "|cut -f 1 -d '.'` + +cd pyGTKtalog +find . -name \*~ -exec rm '{}' ';' +find . -name \*pyc -exec rm '{}' ';' +find . -name \*pyo -exec rm '{}' ';' +find . -type d -name .svn -exec rm -fr '{}' ';' +rm -fr db img +rm -fr prepare_dist_package.sh + +svn log -r ${PREV}:HEAD -v svn://10.0.0.10/repos/Python/pyGTKtalog > CHANGELOG + +cd .. + +tar jcf ../pygtktalog_${REV}.tar.bz2 pyGTKtalog + +cd .. +rm -fr t + diff --git a/src/lib/midentify.py b/src/lib/midentify.py new file mode 100644 index 0000000..8fdb488 --- /dev/null +++ b/src/lib/midentify.py @@ -0,0 +1,63 @@ +# This Python file uses the following encoding: utf-8 + +from os import popen +from sys import argv, exit + +class Midentify(object): + """Class for retrive midentify script output and put it in dict. + Usually there is no need for such a detailed movie/clip information. + Midentify script belongs to mplayer package. + """ + + def __init__(self, filename): + """Init class instance. Filename of a video file is required.""" + self.filename = filename + self.tags = {} + + def get_data(self): + """return dict with clip information""" + output = popen("midentify \"%s\"" % self.filename).readlines() + for line in output: + line = line.strip() + if "ID_VIDEO_WIDTH" in line: + self.tags['width'] = line.replace("ID_VIDEO_WIDTH=", "") + elif "ID_VIDEO_HEIGHT" in line: + self.tags['height'] = line.replace("ID_VIDEO_HEIGHT=", "") + elif "ID_LENGTH" in line: + length = line.replace("ID_LENGTH=", "") + if "." in length: + length = length.split(".")[0] + seconds = int(length) + if seconds > 0: + hours = seconds / 3600 + seconds -= hours * 3600 + minutes = seconds / 60 + seconds -= minutes * 60 + self.tags['length'] = length + length_str = "%02d:%02d:%02d" % (hours, minutes, seconds) + self.tags['duration'] = length_str + elif "ID_DEMUXER" in line: + self.tags['container'] = line.replace("ID_DEMUXER=", "") + elif "ID_VIDEO_FORMAT" in line: + self.tags['video_format'] = line.replace("ID_VIDEO_FORMAT=", "") + elif "ID_VIDEO_CODEC" in line: + self.tags['video_codec'] = line.replace("ID_VIDEO_CODEC=", "") + elif "ID_AUDIO_CODEC" in line: + self.tags['audio_codec'] = line.replace("ID_AUDIO_CODEC=", "") + elif "ID_AUDIO_FORMAT" in line: + self.tags['audio_format'] = line.replace("ID_AUDIO_FORMAT=", "") + elif "ID_AUDIO_NCH" in line: + self.tags['audio_no_channels'] = line.replace("ID_AUDIO_NCH=", + "") + return self.tags + + +if __name__ == "__main__": + """run as standalone script""" + if len(argv) < 2: + print "usage: %s filename" % argv[0] + exit() + + for arg in argv[1:]: + mid = Midentify(arg) + print mid.get_data() diff --git a/src/test/__init__.py b/src/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/test/mocks/m.avi b/src/test/mocks/m.avi new file mode 100644 index 0000000..b19f4b6 Binary files /dev/null and b/src/test/mocks/m.avi differ diff --git a/src/test/mocks/m.mkv b/src/test/mocks/m.mkv new file mode 100644 index 0000000..0ffe561 Binary files /dev/null and b/src/test/mocks/m.mkv differ diff --git a/src/test/mocks/m.mpg b/src/test/mocks/m.mpg new file mode 100644 index 0000000..31530cc Binary files /dev/null and b/src/test/mocks/m.mpg differ diff --git a/src/test/mocks/m.ogm b/src/test/mocks/m.ogm new file mode 100644 index 0000000..b01b094 Binary files /dev/null and b/src/test/mocks/m.ogm differ diff --git a/src/test/mocks/m1.avi b/src/test/mocks/m1.avi new file mode 100644 index 0000000..64e6279 Binary files /dev/null and b/src/test/mocks/m1.avi differ diff --git a/src/test/run_tests.py b/src/test/run_tests.py new file mode 100755 index 0000000..90e6d6b --- /dev/null +++ b/src/test/run_tests.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python +# This Python file uses the following encoding: utf-8 +# +# Author: Roman 'gryf' Dobosz gryf@elysium.pl +# +# Copyright (C) 2007 by Roman 'gryf' Dobosz +# +# This file is part of pyGTKtalog. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +# ------------------------------------------------------------------------- +import sys +import unittest +from os import path, chdir +import glob + + +def my_import(module, name): + """import replacement""" + mod = __import__(module, {}, {}, [name]) + components = name.split('.') + for comp in components[1:]: + mod = getattr(mod, comp) + return mod + +def setup_path(): + """Sets up the python include paths to include needed directories""" + this_path = path.abspath(path.dirname(__file__)) + sys.path = [path.join(this_path, "../../src")] + sys.path + sys.path = [path.join(this_path, "../../src/test")] + sys.path + sys.path = [path.join(this_path, "../../src/test/unit")] + sys.path + return + +def build_suite(): + """build suite test from files in unit directory""" + modules = [] + classes = [] + for fname in glob.glob1('unit', '*_test.py'): + class_name = fname[:-8] + if "_" in class_name: + splited = class_name.split("_") + class_name = 'Test' + for word in splited: + class_name += word.capitalize() + else: + class_name = "Test" + class_name.capitalize() + + modules.append(fname[:-3]) + classes.append(class_name) + + modules = map(__import__, modules) + #my_import(fname[:-3], class_name) + load = unittest.defaultTestLoader.loadTestsFromModule + return unittest.TestSuite(map(load, modules)) + + #exec('suite.addTest(TL().loadTestsFromTestCase('+class_name+'))') + #return suite + +if __name__ == "__main__": + chdir(path.abspath(path.curdir)) + setup_path() + unittest.main(defaultTest="build_suite") + #unittest.TextTestRunner().run(build_suite()) diff --git a/src/test/unit/__init__.py b/src/test/unit/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/test/unit/dummy_test.py b/src/test/unit/dummy_test.py new file mode 100644 index 0000000..c42e90a --- /dev/null +++ b/src/test/unit/dummy_test.py @@ -0,0 +1,11 @@ +# This Python file uses the following encoding: utf-8 +import unittest + +class TestDummy(unittest.TestCase): + """Fake test class""" + def test_dummyMethod(self): + """Test simple assertion""" + self.assertTrue(True) + +if __name__ == "__main__": + unittest.main() diff --git a/src/test/unit/foo_bar_test.py b/src/test/unit/foo_bar_test.py new file mode 100644 index 0000000..7c1a8c9 --- /dev/null +++ b/src/test/unit/foo_bar_test.py @@ -0,0 +1,11 @@ +# This Python file uses the following encoding: utf-8 +import unittest + +class TestFooBar(unittest.TestCase): + """Fake test class""" + def test_dummyMethod(self): + """Test simple assertion""" + self.assertTrue(True) + +if __name__ == "__main__": + unittest.main() diff --git a/src/test/unit/midentify_test.py b/src/test/unit/midentify_test.py new file mode 100644 index 0000000..3526fbf --- /dev/null +++ b/src/test/unit/midentify_test.py @@ -0,0 +1,93 @@ +# This Python file uses the following encoding: utf-8 +import unittest +from lib.midentify import Midentify + +class TestMidentify(unittest.TestCase): + """Class for retrive midentify script output and put it in dict. + Usually there is no need for such a detailed movie/clip information. + Midentify script belongs to mplayer package. + """ + + def test_testAvi(self): + """test mock avi file, should return dict with expected values""" + avi = Midentify("mocks/m.avi") + result_dict = avi.get_data() + self.assertTrue(len(result_dict) != 0, "result should have lenght > 0") + self.assertEqual(result_dict['audio_format'], '85') + self.assertEqual(result_dict['width'], '128') + self.assertEqual(result_dict['audio_no_channels'], '2') + self.assertEqual(result_dict['height'], '96') + self.assertEqual(result_dict['video_format'], 'XVID') + self.assertEqual(result_dict['length'], '4') + self.assertEqual(result_dict['audio_codec'], 'mp3') + self.assertEqual(result_dict['video_codec'], 'ffodivx') + self.assertEqual(result_dict['duration'], '00:00:04') + self.assertEqual(result_dict['container'], 'avi') + + def test_testAvi2(self): + """test another mock avi file, should return dict with expected + values""" + avi = Midentify("mocks/m1.avi") + result_dict = avi.get_data() + self.assertTrue(len(result_dict) != 0, "result should have lenght > 0") + self.assertEqual(result_dict['audio_format'], '85') + self.assertEqual(result_dict['width'], '128') + self.assertEqual(result_dict['audio_no_channels'], '2') + self.assertEqual(result_dict['height'], '96') + self.assertEqual(result_dict['video_format'], 'H264') + self.assertEqual(result_dict['length'], '4') + self.assertEqual(result_dict['audio_codec'], 'mp3') + self.assertEqual(result_dict['video_codec'], 'ffh264') + self.assertEqual(result_dict['duration'], '00:00:04') + self.assertEqual(result_dict['container'], 'avi') + + def test_testMkv(self): + """test mock mkv file, should return dict with expected values""" + avi = Midentify("mocks/m.mkv") + result_dict = avi.get_data() + self.assertTrue(len(result_dict) != 0, "result should have lenght > 0") + self.assertEqual(result_dict['audio_format'], '8192') + self.assertEqual(result_dict['width'], '128') + self.assertEqual(result_dict['audio_no_channels'], '2') + self.assertEqual(result_dict['height'], '96') + self.assertEqual(result_dict['video_format'], 'mp4v') + self.assertEqual(result_dict['length'], '4') + self.assertEqual(result_dict['audio_codec'], 'a52') + self.assertEqual(result_dict['video_codec'], 'ffodivx') + self.assertEqual(result_dict['duration'], '00:00:04') + self.assertEqual(result_dict['container'], 'mkv') + + def test_testMpg(self): + """test mock mpg file, should return dict with expected values""" + avi = Midentify("mocks/m.mpg") + result_dict = avi.get_data() + self.assertTrue(len(result_dict) != 0, "result should have lenght > 0") + self.assertFalse(result_dict.has_key('audio_format')) + self.assertEqual(result_dict['width'], '128') + self.assertFalse(result_dict.has_key('audio_no_channels')) + self.assertEqual(result_dict['height'], '96') + self.assertEqual(result_dict['video_format'], '0x10000001') + self.assertFalse(result_dict.has_key('lenght')) + self.assertFalse(result_dict.has_key('audio_codec')) + self.assertEqual(result_dict['video_codec'], 'mpegpes') + self.assertFalse(result_dict.has_key('duration')) + self.assertEqual(result_dict['container'], 'mpeges') + + def test_testOgm(self): + """test mock ogm file, should return dict with expected values""" + avi = Midentify("mocks/m.ogm") + result_dict = avi.get_data() + self.assertTrue(len(result_dict) != 0, "result should have lenght > 0") + self.assertEqual(result_dict['audio_format'], '8192') + self.assertEqual(result_dict['width'], '160') + self.assertEqual(result_dict['audio_no_channels'], '2') + self.assertEqual(result_dict['height'], '120') + self.assertEqual(result_dict['video_format'], 'H264') + self.assertEqual(result_dict['length'], '4') + self.assertEqual(result_dict['audio_codec'], 'a52') + self.assertEqual(result_dict['video_codec'], 'ffh264') + self.assertEqual(result_dict['duration'], '00:00:04') + self.assertEqual(result_dict['container'], 'ogg') + +if __name__ == "__main__": + unittest.main()