media_harmony VFS module: Add and build by default.
[Samba/gbeck.git] / examples / scripts / vfs / media_harmony / trigger_avid_update.py
blob938b3d11053152bd0cc289382ab2025c3972806a
1 #!/usr/bin/python
2 import os, socket, sys, stat
4 ######################################################################
5 ##
6 ## trigger_avid_update.py for media_harmony VFS module.
7 ##
8 ## Copyright (C) Andrew Klaassen 2012.
9 ##
10 ## This program is free software; you can redistribute it and/or modify
11 ## it under the terms of the GNU General Public License as published by
12 ## the Free Software Foundation; either version 3 of the License, or
13 ## (at your option) any later version.
15 ## This program is distributed in the hope that it will be useful,
16 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ## GNU General Public License for more details.
20 ## You should have received a copy of the GNU General Public License
21 ## along with this program; if not, see <http://www.gnu.org/licenses/>.
23 ######################################################################
27 # Change avid_shares and ip_prefix as appropriate for your network.
30 avid_shares = (
31 '\\\\mediaharmony01\\project1\\',
32 '\\\\mediaharmony01\\project2\\',
33 '\\\\mediaharmony01\\project3\\',
36 ip_prefix = '192.168.1.'
39 if __name__ == "__main__":
40 my_ips = [ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if ip[:len(ip_prefix)] == ip_prefix]
41 if not my_ips:
42 print 'No IP address found. Aborting.'
43 dummy = raw_input("\nPress Enter to finish: ")
44 sys.exit()
46 my_ip = my_ips[0]
47 my_name = os.environ.get('USERNAME')
49 for avid_share in avid_shares:
50 media_dirs = []
51 omfi_dir = os.path.join(avid_share, 'OMFI MediaFiles')
52 if os.path.exists(omfi_dir):
53 media_dirs.append(omfi_dir)
54 mxf_root = os.path.join(avid_share, 'Avid MediaFiles', 'MXF')
55 if os.path.exists(mxf_root):
56 mxf_children = os.listdir(mxf_root)
57 for child in mxf_children:
58 fullpath = os.path.join(mxf_root, child)
59 if os.path.isdir(fullpath):
60 media_dirs.append(fullpath)
62 for media_dir in media_dirs:
64 print '\nChecking %s...' % media_dir
66 fakepath = '%s_%s_%s' % (media_dir, my_ip, my_name)
67 print '...fakepath: %s' % fakepath
69 db = os.path.join(media_dir, 'msmMMOB.mdb')
70 print '...Checking for %s' % db
71 if os.path.exists(db):
72 print '......found %s.' % db
73 db_mtime = os.stat(db)[stat.ST_MTIME]
74 newer_file = False
75 for child in os.listdir(media_dir):
76 if child == 'msmMMOB.mdb' or child == 'msmFMID.pmr':
77 continue
78 child_mtime = os.stat(os.path.join(media_dir, child))[stat.ST_MTIME]
79 if child_mtime > db_mtime:
80 print '......found newer file %s' % child
81 newer_file = True
82 break
83 else:
84 print '......no %s.' % db
85 newer_file = True
87 if newer_file:
88 utime = None # Sets to current time.
89 print '...Setting fake mtime to NOW. Will trigger re-index.'
90 else:
91 mtime = os.stat(media_dir)[stat.ST_MTIME]
92 utime = (mtime, mtime)
93 print '...Setting fake mtime to media_dir mtime. No re-index.'
95 if not os.path.exists(fakepath):
96 tmp_fakepath = '%s.tmp' % fakepath
97 open(tmp_fakepath, 'a').close()
98 os.utime(tmp_fakepath, utime)
99 os.rename(tmp_fakepath, fakepath)
100 else:
101 os.utime(fakepath, utime)
103 dummy = raw_input("\nPress Enter to finish: ")