gmyth-stream/server/lib.py
author rosfran
Thu Apr 12 14:58:13 2007 +0100 (2007-04-12)
branchtrunk
changeset 530 ad51640dd2cd
parent 511 16312d0021cb
child 533 e55310730feb
permissions -rw-r--r--
[svn r535] Fixed to the older GMythFileTransfer revision (no GObject inheritance).
renatofilho@484
     1
import time
morphbr@511
     2
import logging
morphbr@511
     3
import os
morphbr@511
     4
import stat
renatofilho@484
     5
morphbr@516
     6
global ext = ['mpg', 'avi', 'mp4', 'nuv', 'mpeg', 'mov']
morphbr@516
     7
renatofilho@484
     8
def now():
renatofilho@484
     9
    return time.strftime("%Y-%m-%d %H:%M:%S");
renatofilho@484
    10
renatofilho@484
    11
def log(msg):
morphbr@511
    12
    logging.log(logging.DEBUG, msg)
renatofilho@484
    13
    new_msg = "[%s] %s" % (now(), msg)
renatofilho@484
    14
    return new_msg
morphbr@511
    15
morphbr@511
    16
morphbr@511
    17
bin_path_list = os.environ["PATH"].split(os.pathsep)
morphbr@511
    18
def which(prg):
morphbr@511
    19
    for d in bin_path_list:
morphbr@511
    20
        path = os.path.join(d, prg)
morphbr@511
    21
        if os.path.exits(path):
morphbr@511
    22
            st = os.stat(path)
morphbr@511
    23
            if st[stat.ST_MODE] & 0111:
morphbr@511
    24
                return path
morphbr@511
    25
    return ""
morphbr@511
    26
morphbr@516
    27
def list_media_files(directory, file_list):
morphbr@516
    28
    for root, dirs, files in os.walk(directory):
morphbr@516
    29
        for name in files:
morphbr@516
    30
            if os.path.splitext(name)[1].strip(".") in ext:
morphbr@516
    31
                media = os.path.join(root,name)
morphbr@516
    32
                if media not in file_list
morphbr@516
    33
                file_list.append(os.path.join(root,name))
morphbr@511
    34
morphbr@516
    35
    return True
morphbr@516
    36