Skip to content

Commit 27b1356

Browse files
committed
Capturing a script used to copy and rename images from www6/wg/images into www6/photos
- Legacy-Id: 11248
1 parent 02fcef7 commit 27b1356

1 file changed

Lines changed: 107 additions & 0 deletions

File tree

2016-05-25-collect-photos.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/usr/bin/env python
2+
3+
import os, sys, shutil
4+
5+
# boilerplate
6+
basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../web/"))
7+
sys.path = [ basedir ] + sys.path
8+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ietf.settings")
9+
10+
import django
11+
django.setup()
12+
13+
from ietf.group.models import Role
14+
15+
old_images_dir = os.path.join(django.conf.settings.PHOTOS_DIR,'wg/images/')
16+
new_images_dir = os.path.join(django.conf.settings.PHOTOS_DIR,django.conf.settings.PHOTO_URL_PREFIX)
17+
18+
old_image_files = []
19+
for (dirpath, dirnames, filenames) in os.walk(old_images_dir):
20+
old_image_files.extend(filenames)
21+
break # Only interested in the files in the top directory
22+
23+
old_image_files_lc = map(lambda x:x.lower(),old_image_files)
24+
25+
interesting_persons = set()
26+
27+
interesting_persons.update([r.person for r in Role.objects.filter(group__type='wg',group__state='active',name='chair')])
28+
interesting_persons.update([r.person for r in Role.objects.filter(group__type='rg',group__state='active',name='chair')])
29+
interesting_persons.update([r.person for r in Role.objects.filter(group__type='area',group__state='active',name_id='ad')])
30+
interesting_persons.update([r.person for r in Role.objects.filter(group__acronym='iab',name_id='member')])
31+
interesting_persons.update([r.person for r in Role.objects.filter(group__acronym='irtf',name_id='chair')])
32+
33+
#from ietf.person.models import Person
34+
#interesting_persons = Person.objects.filter(name__contains="Burman")
35+
36+
exceptions = {
37+
'Aboba' : 'aboba-bernard',
38+
'Bernardos' : 'cano-carlos',
39+
'Bormann' : 'bormann-carsten',
40+
'Wesley George' : 'george-wes',
41+
'Hinden' : 'hinden-bob',
42+
'Hutton' : 'hutton-andy',
43+
'Narten' : 'narten-thomas', # but there's no picture of him
44+
'O\'Donoghue' : 'odonoghue-karen',
45+
'Przygienda' : 'przygienda-antoni',
46+
'Salowey' : 'salowey-joe',
47+
'Patricia Thaler' : 'thaler-pat',
48+
'Gunter Van de Velde' : 'vandevelde-gunter',
49+
'Eric Vyncke' : 'vynke-eric',
50+
'Zuniga' : 'zuniga-carlos-juan',
51+
'Zhen Cao' : 'zhen-cao',
52+
53+
}
54+
55+
# Manually copied Bo Burman and Thubert Pascal from wg/photos/
56+
# Manually copied Victor Pascual (main image, not thumb) from wg/
57+
# Manually copied Eric Vync?ke (main image, not thumb) from wg/photos/
58+
# Manually copied Danial King (main image, not thumb) from wg/photos/
59+
# Manually copied the thumb (not labelled as such) for Tianran Zhou as both the main and thumb image from wg/photos/
60+
61+
62+
for person in sorted(list(interesting_persons),key=lambda x:x.last_name()+x.ascii):
63+
substr_pattern = None
64+
for exception in exceptions:
65+
if exception in person.ascii:
66+
substr_pattern = exceptions[exception]
67+
break
68+
if not substr_pattern:
69+
name_parts = person.ascii.lower().split()
70+
substr_pattern = '-'.join(name_parts[-1:]+name_parts[0:1])
71+
72+
candidates = [x for x in old_image_files_lc if x.startswith(substr_pattern)]
73+
74+
# Fixup for other exceptional cases
75+
if person.ascii=="Lee Howard":
76+
candidates = candidates[:2] # strip howard-lee1.jpg
77+
78+
if person.ascii=="David Oran":
79+
candidates = ['oran-dave-th.jpg','oran-david.jpg']
80+
81+
if person.ascii=="Susan Hares":
82+
candidates = ['hares-sue-th.jpg','hares-susan.jpg']
83+
84+
if person.ascii=="Mahesh Jethanandani":
85+
candidates = ['mahesh-jethanandani-th.jpg','jethanandani-mahesh.jpg']
86+
87+
if len(candidates) not in [0,2]:
88+
candidates = [x for x in candidates if not '00' in x]
89+
90+
# At this point we either have no candidates or two. If two, the first will be the thumb
91+
92+
def original_case(name):
93+
return old_image_files[old_image_files_lc.index(name)]
94+
95+
if len(candidates)==2:
96+
old_name = original_case(candidates[1])
97+
old_thumb_name = original_case(candidates[0])
98+
old_name_ext = os.path.splitext(old_name)[1]
99+
old_thumb_name_ext = os.path.splitext(old_thumb_name)[1]
100+
101+
new_name = person.photo_name(thumb=False)+old_name_ext
102+
new_thumb_name = person.photo_name(thumb=True)+old_thumb_name_ext
103+
104+
print "Copying",os.path.join(old_images_dir,old_name),"to",os.path.join(new_images_dir,new_name)
105+
shutil.copy(os.path.join(old_images_dir,old_name),os.path.join(new_images_dir,new_name))
106+
print "Copying",os.path.join(old_images_dir,old_thumb_name),"to",os.path.join(new_images_dir,new_thumb_name)
107+
shutil.copy(os.path.join(old_images_dir,old_thumb_name),os.path.join(new_images_dir,new_thumb_name))

0 commit comments

Comments
 (0)