Ignore:
Timestamp:
11 Jun 2013, 08:18:02 (12 years ago)
Author:
Henrik Bettermann
Message:

Create folders if they do not exist. This is dangerous and should only be applied to old student ids.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/tools/reload_portraits.py

    r9020 r10288  
    1919## The folder where all source docs can be found (can be any folder)
    2020#SRC_DIR = "/kofa/uniben/var/datacenter/media/students/reload"
    21 SRC_DIR = "/zope/instances/unibenpg-import/pictures_admitted_latest"
     21SRC_DIR = "/kofa/uniben_passport_reload"
    2222
    2323## The students folder in Kofa where files should go to
     
    7070
    7171def final_subfolder(stud_id):
    72     # compute new folder name from stud_id (old stud_ids or new stud_ids
    73     # but not new old stud_ids)
    74     num = int(stud_id[1:])
     72    # compute new folder name from stud_id (old stud_ids or new stud_ids)
     73    try:
     74        num = int(stud_id[1:])
     75    except ValueError:
     76        # new old stud_ids
     77        num = int(stud_id[2:])
    7578    num = num / 10000 * 10
    7679    return '%05d' % num
     
    8083    shutil.copyfile(file_src, file_dst)
    8184    set_perms(file_dst)
     85    return
     86
     87def create_path(path):
     88    # create path with subdirs, if it does not exist (completely)
     89    if os.path.exists(path):
     90        return
     91    parent = os.path.dirname(path)
     92    if not os.path.exists(parent):
     93        # create parent first
     94        create_path(parent)
     95    print "CREATE PATH ", path
     96    os.mkdir(path)
     97    set_perms(path)
    8298    return
    8399
     
    96112    dst_folder = os.path.join(DST_DIR, subfolder, new_stud_id)
    97113    if not os.path.exists(dst_folder):
    98         print "Destination folder does not exist: %s. Skipping" % (dst_folder)
    99         continue
     114        #print "Destination folder does not exist: %s. Skipping" % (dst_folder)
     115        #continue
     116        create_path(dst_folder)
    100117    dst_file = os.path.join(DST_DIR, subfolder, new_stud_id,
    101118        'passport_%s.jpg' % new_stud_id)
Note: See TracChangeset for help on using the changeset viewer.