|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +import os, sys, shutil, pathlib |
| 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.OLD_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 | +processed_files = [] |
| 63 | + |
| 64 | +for person in sorted(list(interesting_persons),key=lambda x:x.last_name()+x.ascii): |
| 65 | + substr_pattern = None |
| 66 | + for exception in exceptions: |
| 67 | + if exception in person.ascii: |
| 68 | + substr_pattern = exceptions[exception] |
| 69 | + break |
| 70 | + if not substr_pattern: |
| 71 | + name_parts = person.ascii.lower().split() |
| 72 | + substr_pattern = '-'.join(name_parts[-1:]+name_parts[0:1]) |
| 73 | + |
| 74 | + candidates = [x for x in old_image_files_lc if x.startswith(substr_pattern)] |
| 75 | + |
| 76 | + # Fixup for other exceptional cases |
| 77 | + if person.ascii=="Lee Howard": |
| 78 | + candidates = candidates[:2] # strip howard-lee1.jpg |
| 79 | + |
| 80 | + if person.ascii=="David Oran": |
| 81 | + candidates = ['oran-dave-th.jpg','oran-david.jpg'] |
| 82 | + |
| 83 | + if person.ascii=="Susan Hares": |
| 84 | + candidates = ['hares-sue-th.jpg','hares-susan.jpg'] |
| 85 | + |
| 86 | + if person.ascii=="Mahesh Jethanandani": |
| 87 | + candidates = ['mahesh-jethanandani-th.jpg','jethanandani-mahesh.jpg'] |
| 88 | + |
| 89 | + if len(candidates) not in [0,2]: |
| 90 | + candidates = [x for x in candidates if not '00' in x] |
| 91 | + |
| 92 | + # At this point we either have no candidates or two. If two, the first will be the thumb |
| 93 | + |
| 94 | + def original_case(name): |
| 95 | + return old_image_files[old_image_files_lc.index(name)] |
| 96 | + |
| 97 | + def copy(old, new): |
| 98 | + global processed_files |
| 99 | + print("Copying", old, "to", new) |
| 100 | + shutil.copy(old, new) |
| 101 | + processed_files.append(old) |
| 102 | + |
| 103 | + if len(candidates)==2: |
| 104 | + old_name = original_case(candidates[1]) |
| 105 | + old_thumb_name = original_case(candidates[0]) |
| 106 | + old_name_ext = os.path.splitext(old_name)[1] |
| 107 | + old_thumb_name_ext = os.path.splitext(old_thumb_name)[1] |
| 108 | + |
| 109 | + new_name = person.photo_name(thumb=False)+old_name_ext.lower() |
| 110 | + new_thumb_name = person.photo_name(thumb=True)+old_thumb_name_ext.lower() |
| 111 | + |
| 112 | + copy( os.path.join(old_images_dir,old_name), os.path.join(new_images_dir,new_name) ) |
| 113 | + |
| 114 | + # |
| 115 | + copy( os.path.join(old_images_dir,old_thumb_name), os.path.join(new_images_dir,new_thumb_name) ) |
| 116 | + |
| 117 | + |
| 118 | +for file in pathlib.Path(old_images_dir).iterdir(): |
| 119 | + if file.is_file(): |
| 120 | + if not str(file) in processed_files: |
| 121 | + print("Not processed:", file.name) |
0 commit comments