Adjustements to po.sh

main
Thomas Ba. 5 years ago
parent d0bfe41cea
commit 64214420e6

@ -1,9 +1,9 @@
#!/bin/bash #!/bin/bash
# shut down computer after checking running applications # shut down computer after checking running applications
read -p "Press enter to shutdown computer '$(hostname)'" read -r -p "Press enter to shutdown computer '$(hostname)'"
PROGRAMS=("spotify" "firefox" "thunderbird" "ssh" "scp" "rsync" "pacman" "nemo" "vim" "gvim") PROGRAMS=("firefox" "thunderbird" "ssh" "scp" "rsync" "pacman" "nemo" "vim" "gvim" "pacman" "vivaldi-bin")
READY=0 READY=0
@ -18,11 +18,19 @@ while [ $READY -eq 0 ] ; do
READY=0 READY=0
done done
done done
STATUS="$(dropbox-cli status)"
while [ "$STATUS" != "Up to date" -a "$STATUS" != "Connecting..." -a "$STATUS" != "Dropbox isn't running!" ] ; do
echo "Dropbox is still syncing!"
sleep 5
READY=0
STATUS="$(dropbox-cli status)"
done
done done
poweroff
if [ $? -ne 0 ] ; then if poweroff; then
echo "Goodbye :)"
else
echo "Higher privileges are required!" echo "Higher privileges are required!"
if type sudo > /dev/null ; then if type sudo > /dev/null ; then
sudo poweroff sudo poweroff

@ -1,19 +1,38 @@
#!/bin/env python3 #!/bin/env python3
# vim: noexpandtab ts=4 ft=python : # vim: noexpandtab ts=4 ft=python :
"""
Rename all jpg images in the current folder. If there is a NEF image with the same same,
rename it as well.
"""
import os import os
import re import re
import datetime
import operator import operator
import PIL.Image import PIL.Image
import PIL.ExifTags import PIL.ExifTags
def get_date(filename): def get_date(filename):
"""
Get date and time from image exif tag and return string with format %Y%m%d_%H%M%S
"""
try:
img = PIL.Image.open(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]) e = img._getexif()
if d is None: if 306 in e:
return None index = 306
elif 36867 in e:
index = 36867
elif 36838 in e:
index = 36868
d = datetime.datetime.strptime(e[index], "%Y:%m:%d %H:%M:%S")
img.close() 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"])) return d.strftime("%Y%m%d_%H%M%S")
except Exception as e:
print(e)
exit(2)
return None
def print_new_filename(number, date, name, original_filename): def print_new_filename(number, date, name, original_filename):
ext = original_filename.split('.')[-1] ext = original_filename.split('.')[-1]
@ -37,10 +56,10 @@ if PIL.ExifTags.TAGS[306] != "DateTime":
print("Warning: EXIF index for DateTime changed!") print("Warning: EXIF index for DateTime changed!")
exit(2) 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 = [[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'\.jpe?g$', f, flags=re.IGNORECASE)]
images = sorted(images, key=operator.itemgetter(0, 1)) images = sorted(images, key=operator.itemgetter(0, 1))
i = 1 i = 1
for img in images: for img in images:
rename_file_and_nef(i, img[0], "thomas", img[1]) rename_file_and_nef(i, img[0], "mfg-who-am-i", img[1])
i += 1 i += 1

@ -27,6 +27,20 @@ def get_date(filename):
return None return None
return "%04d%02d%02d" % (int(matches["year"]), int(matches["month"]), int(matches["day"])) return "%04d%02d%02d" % (int(matches["year"]), int(matches["month"]), int(matches["day"]))
def create_directory(directory):
"""
Try to create the directory return False when theres already something there thats not a
directory
"""
if os.path.exists(directory):
if not os.path.isdir(directory):
print("'%s' exists but is no directory!" % (directory))
return False
else:
print("Creating directory '%s'" % (directory))
os.mkdir(directory)
return True
def main(): def main():
""" """
Move files to a directory by date Move files to a directory by date
@ -45,11 +59,15 @@ def main():
help="The destination directory (default = current)", dest="destination") help="The destination directory (default = current)", dest="destination")
parser.add_argument("--copy", "-c", action="store_true", dest="copy_files", \ parser.add_argument("--copy", "-c", action="store_true", dest="copy_files", \
help="Copy the files insted of moving them") help="Copy the files insted of moving them")
parser.add_argument("--existing", "-e", action="store", dest="existing_files", \
choises=["ask", "skip", "overwrite"], default="ask", \
help="What to do with existing files")
args = parser.parse_args() args = parser.parse_args()
# settings # settings
source_directory = args.source source_directory = args.source
destination_directory = args.destination destination_directory = args.destination
copy_files = args.copy_files copy_files = args.copy_files
existing_files = args.existing_files
# iterate through directory # iterate through directory
for filename in os.listdir(source_directory): for filename in os.listdir(source_directory):
if os.path.isfile(os.path.join(source_directory, filename)) and \ if os.path.isfile(os.path.join(source_directory, filename)) and \
@ -60,15 +78,21 @@ def main():
continue continue
directory = os.path.join(destination_directory, date) directory = os.path.join(destination_directory, date)
# create directory if it not exists # create directory if it not exists
if os.path.exists(directory): if not create_directory(directory):
if not os.path.isdir(directory):
print("'%s' exists but is no directory!" % (date))
continue continue
else:
print("Creating directory '%s'" % (directory))
os.mkdir(directory)
# copy or move file # copy or move file
if copy_files: write_file = True
if os.path.exists(os.path.join(destination_directory, date, filename)) and \
existing_files != "overwrite":
write_file = False
if existing_files == "ask":
overwrite = input("File '%s' exists! Overwrite? [yn]: ")
while overwrite not in ["y", "n"]:
overwrite = input("File '%s' exists! Overwrite? [yn]: ")
write_file = overwrite == "y"
if not write_file:
print("Skipping file '%s'" % (filename))
elif copy_files:
print("Copy file '%s' to '%s'" % (filename, date)) print("Copy file '%s' to '%s'" % (filename, date))
shutil.copy2(os.path.join(source_directory, filename), \ shutil.copy2(os.path.join(source_directory, filename), \
os.path.join(destination_directory, date, filename)) os.path.join(destination_directory, date, filename))

@ -146,6 +146,8 @@ assign [class="aurora"] → 2
assign [class="Opera"] → 2 assign [class="Opera"] → 2
assign [class="Midori"] → 2 assign [class="Midori"] → 2
assign [class="Chromium"] → 2 assign [class="Chromium"] → 2
assign [class="vivaldi-stable"] → 2
assign [class="Vivaldi-stable"] → 2
assign [class="Thunderbird"] → 3 assign [class="Thunderbird"] → 3
for_window [class="XTerm"] floating enable for_window [class="XTerm"] floating enable
for_window [class="feh"] floating enable for_window [class="feh"] floating enable

@ -42,6 +42,7 @@ Plug 'niklasl/vim-rdf'
Plug 'nathanaelkane/vim-indent-guides' Plug 'nathanaelkane/vim-indent-guides'
Plug 'chrisbra/csv.vim' Plug 'chrisbra/csv.vim'
Plug 'vim-scripts/icalendar.vim' Plug 'vim-scripts/icalendar.vim'
Plug 'cespare/vim-toml'
" Files " Files
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }

@ -11,5 +11,3 @@ fi
# Environment variables # Environment variables
# #
export GTK2_RC_FILES="$HOME/.gtkrc-2.0" export GTK2_RC_FILES="$HOME/.gtkrc-2.0"
xrandr --output DVI-0 --auto --left-of HDMI-0

Loading…
Cancel
Save