-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCopyMedia.py
47 lines (39 loc) · 1.23 KB
/
CopyMedia.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
import os
import sys
import shutil
def NeedsUpdating( srcFName, destFName ):
try:
srcStat = os.stat( srcFName )
destStat = os.stat( destFName )
except:
return True
return srcStat.st_mtime > destStat.st_mtime or srcStat.st_size != destStat.st_size
def CopyMedia( src='.', dest=None ):
extensions = set( ['.py', '.html', '.gif', '.png', '.iss', '.txt'] )
if dest is None:
try:
media = os.listdir( '/media' )
assert len(media) == 1, 'Missing, or more than one media'
dest = os.path.join( '/media', media[0], os.path.basename(os.path.abspath(src)) )
except Exception as e:
print ( e )
sys.exit( -1 )
for path, dirs, files in os.walk(src):
for d in dirs:
srcDName = os.path.join(path, d)
destDName = os.path.join( dest, srcDName[len(src)+1:] )
if not os.path.isdir(destDName):
os.makedirs( destDName )
for f in files:
if os.path.splitext(f)[1].lower() in extensions:
srcFName = os.path.join(path, f)
destFName = os.path.join( dest, srcFName[len(src)+1:] )
if NeedsUpdating( srcFName, destFName ):
print ( srcFName, destFName )
try:
shutil.copy( srcFName, destFName )
except Exception as e:
print ( e )
if __name__ == '__main__':
CopyMedia()