#! /usr/bin/env python
# -*- coding: utf-8 -*-
# Adds my copyright notice to photos.
#
# Author R.F. Smith <rsmith@xs4all.nl>
# Time-stamp: <2012-04-22 19:35:42 rsmith>
# 
# To the extent possible under law, Roland Smith has waived all copyright and
# related or neighboring rights to backup-local. This work is published from the
# Netherlands. See http://creativecommons.org/publicdomain/zero/1.0/

import sys
import shlex, subprocess
from multiprocessing import Pool, Lock
from os import utime
import os.path
from time import mktime

def processfile(name):
    args = shlex.split("exiftool -CreateDate {}".format(name))
    createdate = subprocess.check_output(args)
    fields = createdate.split(":")
    year = int(fields[1])
    cr = "R.F. Smith <rsmith@xs4all.nl> http://rsmith.home.xs4all.nl/"
    cmt = "Copyright © {} {}".format(year, cr)
    cmd = "exiftool -Copyright='{}' -Comment='{}' -overwrite_original -q {}"
    args = shlex.split(cmd.format(cr, cmt, name))
    rv = subprocess.call(args)
    modtime = int(mktime((year, int(fields[2]), int(fields[3][:2]), 
                      int(fields[3][3:]), int(fields[4]), int(fields[5]), 
                      0,0,-1)))
    utime(name, (modtime, modtime))
    globallock.acquire()
    if rv == 0:
        print "File '{}' processed.".format(name)
    else:
        print "Error when processing file '{}'".format(name)
    globallock.release()

if __name__ == '__main__':
    files = sys.argv[1:]
    if len(files) == 0:
        path, binary = os.path.split(sys.argv[0])
        print "Usage: {} [file ...]".format(binary)
        exit(0)
    try:
        subprocess.check_output(['exiftool', '-ver'], stderr=subprocess.STDOUT)
    except CalledProcessError:
        print "Exiftool not found! exiting."
        exit(1)
    globallock = Lock()
    p = Pool()
    p.map(processfile, files)
    p.close()

@@ -88,16 +88,17 @@
 # Author
+:
  R.F. Sm
@@ -148,18 +148,18 @@
 04-2
-2 19:35:42
+8 11:42:44
  rsm
@@ -283,20 +283,21 @@
  to 
-backup-local
+markphotos.py
 . Th
@@ -325,14 +325,14 @@
 from
+%0A#
  the
-%0A#
  Net
@@ -417,15 +417,8 @@
 port
- shlex,
  sub
@@ -563,29 +563,18 @@
 s = 
-shlex.split(%22
+%5B'
 exiftool
  -Cr
@@ -569,17 +569,20 @@
 exiftool
- 
+', '
 -CreateD
@@ -588,26 +588,16 @@
 Date
- %7B%7D%22.format(
+', 
 name
-))
+%5D
 %0A   
@@ -822,28 +822,31 @@
  cr)
+ 
 %0A    
-cmd = %22
+args = %5B'
 exiftool
  -Co
@@ -841,17 +841,20 @@
 exiftool
- 
+', '
 -Copyrig
@@ -856,21 +856,71 @@
 pyright=
-'%7B%7D' 
+%22Copyright (C) %7B%7D %7B%7D%22'.format(year, cr), %0A            '
 -Comment
@@ -920,21 +920,36 @@
 Comment=
-'
+%22
 %7B%7D
+%22'.format(cmt), 
 '
- 
 -overwri
@@ -963,65 +963,22 @@
 inal
- -q %7B%7D%22%0A    args = shlex.split(cmd.format(cr, cmt
+', '-q'
 , name
-))
+%5D
 %0A   
@@ -1096,16 +1096,20 @@
         
+    
 int(fiel
@@ -1149,24 +1149,28 @@
 ields%5B5%5D), %0A
+    
             
@@ -1413,16 +1413,317 @@
 ease()%0A%0A
+def checkfor(args):%0A    '''Make sure that a program necessary for using this script is available.'''%0A    try:%0A        subprocess.check_output(args, stderr=subprocess.STDOUT)%0A    except CalledProcessError:%0A        print %22Required program '%7B%7D' not found! exiting.%22.format(progname)%0A        sys.exit(1)%0A%0A
 if __nam
@@ -1916,183 +1916,37 @@
     
-try:%0A        subprocess.check_output(%5B'exiftool', '-ver'%5D, stderr=subprocess.STDOUT)%0A    except CalledProcessError:%0A        print %22Exiftool not found! exiting.%22%0A        exit(1
+checkfor(%5B'exiftool', '-ver'%5D
 )%0A  

Add or update public domain dedication for scripts.