commit
a600bfd7d3
@ -0,0 +1,32 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# shut down computer after checking running applications
|
||||||
|
|
||||||
|
read -p "Press enter to shutdown computer '$(hostname)'"
|
||||||
|
|
||||||
|
PROGRAMS=("spotify" "firefox" "thunderbird" "ssh" "scp" "rsync" "pacman" "nemo" "vim" "gvim")
|
||||||
|
|
||||||
|
READY=0
|
||||||
|
|
||||||
|
while [ $READY -eq 0 ] ; do
|
||||||
|
READY=1
|
||||||
|
for PROGRAM in "${PROGRAMS[@]}"; do
|
||||||
|
PID=$(pidof "$PROGRAM" 2> /dev/null)
|
||||||
|
while [ -n "$PID" ]; do
|
||||||
|
echo "$PROGRAM still running! (pid: $PID)"
|
||||||
|
sleep 1
|
||||||
|
PID=$(pidof "$PROGRAM" 2> /dev/null)
|
||||||
|
READY=0
|
||||||
|
done
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
poweroff
|
||||||
|
|
||||||
|
if [ $? -ne 0 ] ; then
|
||||||
|
echo "Higher privileges are required!"
|
||||||
|
if type sudo > /dev/null ; then
|
||||||
|
sudo poweroff
|
||||||
|
else
|
||||||
|
su -c poweroff
|
||||||
|
fi
|
||||||
|
fi
|
@ -0,0 +1,46 @@
|
|||||||
|
#!/bin/env python3
|
||||||
|
# vim: noexpandtab ts=4 ft=python :
|
||||||
|
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import operator
|
||||||
|
import PIL.Image
|
||||||
|
import PIL.ExifTags
|
||||||
|
|
||||||
|
def get_date(filename):
|
||||||
|
img = PIL.Image.open(filename)
|
||||||
|
d = re.match(r'(?P<year>\d{4}):(?P<month>\d{2}):(?P<day>\d{2}) (?P<hour>\d{2}):(?P<minute>\d{2}):(?P<second>\d{2})', img._getexif()[306])
|
||||||
|
if d is None:
|
||||||
|
return None
|
||||||
|
img.close()
|
||||||
|
return "%04d%02d%02d_%02d%02d%02d" % (int(d["year"]), int(d["month"]), int(d["day"]), int(d["hour"]), int(d["minute"]), int(d["second"]))
|
||||||
|
|
||||||
|
def print_new_filename(number, date, name, original_filename):
|
||||||
|
ext = original_filename.split('.')[-1]
|
||||||
|
return "%s_%s_%03d.%s" % (date, name, number, ext.lower())
|
||||||
|
|
||||||
|
def rename_file_and_nef(number, date, name, original_filename):
|
||||||
|
ext = original_filename.split('.')[-1].lower()
|
||||||
|
plain = ".".join(original_filename.split('.')[:-1])
|
||||||
|
name = "%s_%s_%03d" % (date, name, number)
|
||||||
|
print("Handling file %s..." % (original_filename, ))
|
||||||
|
print(" Renaming from '%s' to '%s'" % (original_filename, name + "." + ext))
|
||||||
|
os.rename(os.path.join(os.getcwd(), original_filename), os.path.join(os.getcwd(), name + "." + ext))
|
||||||
|
if os.path.isfile(os.path.join(os.getcwd(), plain + ".NEF")):
|
||||||
|
print(" Renaming from '%s' to '%s'" % (plain + ".NEF", name + ".nef"))
|
||||||
|
os.rename(os.path.join(os.getcwd(), plain + ".NEF"), os.path.join(os.getcwd(), name + ".nef"))
|
||||||
|
elif os.path.isfile(os.path.join(os.getcwd(), plain + ".nef")):
|
||||||
|
print(" Renaming from '%s' to '%s'" % (plain + ".nef", name + ".nef"))
|
||||||
|
os.rename(os.path.join(os.getcwd(), plain + ".nef"), os.path.join(os.getcwd(), name + ".nef"))
|
||||||
|
|
||||||
|
if PIL.ExifTags.TAGS[306] != "DateTime":
|
||||||
|
print("Warning: EXIF index for DateTime changed!")
|
||||||
|
exit(2)
|
||||||
|
|
||||||
|
images = [[get_date(os.path.join(os.getcwd(), f)), f] for f in os.listdir(os.getcwd()) if os.path.isfile(os.path.join(os.getcwd(), f)) and re.search(r'\.jpg$', f, flags=re.IGNORECASE)]
|
||||||
|
images = sorted(images, key=operator.itemgetter(0, 1))
|
||||||
|
|
||||||
|
i = 1
|
||||||
|
for img in images:
|
||||||
|
rename_file_and_nef(i, img[0], "thomas", img[1])
|
||||||
|
i += 1
|
@ -0,0 +1,81 @@
|
|||||||
|
#!/bin/env python3
|
||||||
|
# vim: set noexpandtab tabstop=4 ft=python :
|
||||||
|
"""
|
||||||
|
A script moving pictures from one folder to subfolders (depending on the date they are taken)
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import argparse
|
||||||
|
import re
|
||||||
|
import shutil
|
||||||
|
import PIL.Image
|
||||||
|
import PIL.ExifTags
|
||||||
|
|
||||||
|
def get_date(filename):
|
||||||
|
"""
|
||||||
|
Read EXIF data from a file and return a string containing "yyyymmdd"
|
||||||
|
|
||||||
|
:param filename: The files name
|
||||||
|
"""
|
||||||
|
image = PIL.Image.open(filename)
|
||||||
|
image_exif = image._getexif()
|
||||||
|
if not image_exif:
|
||||||
|
return None
|
||||||
|
matches = re.match(r'(?P<year>\d{4}):(?P<month>\d{2}):(?P<day>\d{2})', image_exif[306])
|
||||||
|
image.close()
|
||||||
|
if matches is None:
|
||||||
|
return None
|
||||||
|
return "%04d%02d%02d" % (int(matches["year"]), int(matches["month"]), int(matches["day"]))
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""
|
||||||
|
Move files to a directory by date
|
||||||
|
|
||||||
|
:param args: CLI arguments
|
||||||
|
"""
|
||||||
|
# verify we're getting the correct data :)
|
||||||
|
if PIL.ExifTags.TAGS[306] != "DateTime":
|
||||||
|
print("ERROR: EXIF index for DateTime changed!")
|
||||||
|
exit(2)
|
||||||
|
# parse arguments
|
||||||
|
parser = argparse.ArgumentParser(description="Move/copy pictures to subfolders")
|
||||||
|
parser.add_argument("--source", "-s", action="store", default=os.getcwd(), metavar="<path>", \
|
||||||
|
help="The source directory (default = current)", dest="source")
|
||||||
|
parser.add_argument("--destination", "-d", action="store", default=os.getcwd(), metavar="<path>", \
|
||||||
|
help="The destination directory (default = current)", dest="destination")
|
||||||
|
parser.add_argument("--copy", "-c", action="store_true", dest="copy_files", \
|
||||||
|
help="Copy the files insted of moving them")
|
||||||
|
args = parser.parse_args()
|
||||||
|
# settings
|
||||||
|
source_directory = args.source
|
||||||
|
destination_directory = args.destination
|
||||||
|
copy_files = args.copy_files
|
||||||
|
# iterate through directory
|
||||||
|
for filename in os.listdir(source_directory):
|
||||||
|
if os.path.isfile(os.path.join(source_directory, filename)) and \
|
||||||
|
re.search(r'\.jpg$', filename, flags=re.IGNORECASE):
|
||||||
|
date = get_date(os.path.join(source_directory, filename))
|
||||||
|
if date is None:
|
||||||
|
print("WARNING: No EXIF data for file '%s'" % (filename))
|
||||||
|
continue
|
||||||
|
directory = os.path.join(destination_directory, date)
|
||||||
|
# create directory if it not exists
|
||||||
|
if os.path.exists(directory):
|
||||||
|
if not os.path.isdir(directory):
|
||||||
|
print("'%s' exists but is no directory!" % (date))
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
print("Creating directory '%s'" % (directory))
|
||||||
|
os.mkdir(directory)
|
||||||
|
# copy or move file
|
||||||
|
if copy_files:
|
||||||
|
print("Copy file '%s' to '%s'" % (filename, date))
|
||||||
|
shutil.copy2(os.path.join(source_directory, filename), \
|
||||||
|
os.path.join(destination_directory, date, filename))
|
||||||
|
else:
|
||||||
|
print("Moving file '%s' to '%s'" % (filename, date))
|
||||||
|
os.rename(os.path.join(source_directory, filename), \
|
||||||
|
os.path.join(destination_directory, date, filename))
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
Loading…
Reference in new issue