From: Guillaume Pellerin Date: Sun, 29 Jul 2012 18:07:39 +0000 (+0200) Subject: fix bad fixes, add self process detection : no dual process X-Git-Tag: 0.8.4^2~8^2~1 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=c69fbf34d580bdc8646355c9f45ebd4cfbc77095;p=teleforma.git fix bad fixes, add self process detection : no dual process --- diff --git a/tools/trans/fix_chk_media.py b/tools/trans/fix_chk_media.py index 1c6d2468..991a644d 100644 --- a/tools/trans/fix_chk_media.py +++ b/tools/trans/fix_chk_media.py @@ -1,6 +1,7 @@ #!/usr/bin/python -import os, sys +import os, sys, psutil +import datetime class FixCheckMedia(object): @@ -18,20 +19,20 @@ class FixCheckMedia(object): ext = os.path.splitext(filename)[1][1:] dir_files = os.listdir(root) - fixed_log = 'mp3_fixed' + fixed_log = 'mp3.fixed' tofix_log = 'mp3.tofix' if ext == 'mp3' and tofix_log in dir_files and not fixed_log in dir_files: print path for file in dir_files: - ext = os.path.splitext(file)[1][1:] - if ext == 'webm': + source_ext = os.path.splitext(file)[1][1:] + if source_ext == 'webm': + source = root + os.sep + file + os.system('touch ' + root + os.sep + fixed_log) + os.system('rm ' + root + os.sep + tofix_log) + if os.path.getsize(source): + self.fix_mp3(source, path) break - source = root + os.sep + file - os.system('touch ' + root + os.sep + fixed_log) - os.system('rm ' + root + os.sep + tofix_log) - if os.path.getsize(source): - self.fix_mp3(source, path) - #pass + #pass fixed_log = 'webm.fixed' tofix_log = 'webm.tofix' @@ -48,7 +49,7 @@ class FixCheckMedia(object): os.system('touch ' + root + os.sep + fixed_log) os.system('rm ' + root + os.sep + tofix_log) if os.path.getsize(path): - self.hard_fix_webm(path): + self.hard_fix_webm(path) #pass @@ -67,7 +68,7 @@ class FixCheckMedia(object): def fix_webm(self, path): try: tmp_file = self.tmp_dir + 'out.webm ' - command = 'ffmpeg -loglevel quiet -i '+ path + ' -vcodec copy -acodec copy -f webm -y ' + tmp_file + ' > /dev/null' + command = 'ffmpeg -loglevel 0 -i '+ path + ' -vcodec copy -acodec copy -f webm -y ' + tmp_file + ' > /dev/null' print command os.system(command) command = 'mv ' + tmp_file + path @@ -77,15 +78,37 @@ class FixCheckMedia(object): def fix_mp3(self, source, path): try: - command = 'ffmpeg -loglevel quiet -i '+ source + ' -ab 96k -y ' + path + ' > /dev/null' + command = 'ffmpeg -loglevel 0 -i '+ source + ' -ab 96k -y ' + path + ' > /dev/null' print command os.system(command) except: pass +def get_pids(name, args=None): + """Get a process pid filtered by arguments and uid""" + pids = [] + for proc in psutil.process_iter(): + if proc.cmdline: + if name == proc.name: + if args: + if args in proc.cmdline[-1]: + pids.append(proc.pid) + else: + pids.append(proc.pid) + return pids + + +print datetime.datetime.now() +dir = sys.argv[-1] +path = os.path.abspath(__file__) +pids = get_pids('python2.6',args=path) +if len(pids) <= 1: + print 'starting process...' + f = FixCheckMedia(dir) + f.process() + print 'process finished.\n' +else: + print 'already started !\n' -dir = sys.argv[-1] -f = FixCheckMedia(dir) -f.process()