7 ######################################################################
9 ## trigger_avid_update.py for media_harmony VFS module.
11 ## Copyright (C) Andrew Klaassen 2012.
13 ## This program is free software; you can redistribute it and/or modify
14 ## it under the terms of the GNU General Public License as published by
15 ## the Free Software Foundation; either version 3 of the License, or
16 ## (at your option) any later version.
18 ## This program is distributed in the hope that it will be useful,
19 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ## GNU General Public License for more details.
23 ## You should have received a copy of the GNU General Public License
24 ## along with this program; if not, see <http://www.gnu.org/licenses/>.
26 ######################################################################
30 # Change avid_shares and ip_prefix as appropriate for your network.
34 '\\\\mediaharmony01\\project1\\',
35 '\\\\mediaharmony01\\project2\\',
36 '\\\\mediaharmony01\\project3\\',
39 ip_prefix = '192.168.1.'
42 if __name__ == "__main__":
43 my_ips = [ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if ip[:len(ip_prefix)] == ip_prefix]
45 print 'No IP address found. Aborting.'
46 dummy = raw_input("\nPress Enter to finish: ")
50 my_name = os.environ.get('USERNAME')
52 for avid_share in avid_shares:
54 omfi_dir = os.path.join(avid_share, 'OMFI MediaFiles')
55 if os.path.exists(omfi_dir):
56 media_dirs.append(omfi_dir)
57 mxf_root = os.path.join(avid_share, 'Avid MediaFiles', 'MXF')
58 if os.path.exists(mxf_root):
59 mxf_children = os.listdir(mxf_root)
60 for child in mxf_children:
61 fullpath = os.path.join(mxf_root, child)
62 if os.path.isdir(fullpath):
63 media_dirs.append(fullpath)
65 for media_dir in media_dirs:
67 print '\nChecking %s...' % media_dir
69 fakepath = '%s_%s_%s' % (media_dir, my_ip, my_name)
70 print '...fakepath: %s' % fakepath
72 db = os.path.join(media_dir, 'msmMMOB.mdb')
73 print '...Checking for %s' % db
74 if os.path.exists(db):
75 print '......found %s.' % db
76 db_mtime = os.stat(db)[stat.ST_MTIME]
78 for child in os.listdir(media_dir):
79 if child == 'msmMMOB.mdb' or child == 'msmFMID.pmr':
81 child_mtime = os.stat(os.path.join(media_dir, child))[stat.ST_MTIME]
82 if child_mtime > db_mtime:
83 print '......found newer file %s' % child
87 print '......no %s.' % db
91 utime = None # Sets to current time.
92 print '...Setting fake mtime to NOW. Will trigger re-index.'
94 mtime = os.stat(media_dir)[stat.ST_MTIME]
95 utime = (mtime, mtime)
96 print '...Setting fake mtime to media_dir mtime. No re-index.'
98 if not os.path.exists(fakepath):
99 tmp_fakepath = '%s.tmp' % fakepath
100 open(tmp_fakepath, 'a').close()
101 os.utime(tmp_fakepath, utime)
102 os.rename(tmp_fakepath, fakepath)
104 os.utime(fakepath, utime)
106 dummy = raw_input("\nPress Enter to finish: ")