Skip to content

Commit

Permalink
PEP-08 compliance
Browse files Browse the repository at this point in the history
  • Loading branch information
kieranjol committed Aug 19, 2017
1 parent d079682 commit c4beb55
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 123 deletions.
24 changes: 17 additions & 7 deletions bitc.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ def set_options():
)
parser.add_argument(
'-crf',
help='Set quality. Default is 23, lower number = large file/high quality, high number = small file/poor quality'
help='Set quality. Default is 23, lower number ='
' large file/high quality, high number = small file/poor quality'
)
parser.add_argument(
'-o',
help='Set output directory. The default directory is the same directory as input.'
help='Set output directory.'
'The default directory is the same directory as input.'
)
parser.add_argument(
'-scale',
Expand Down Expand Up @@ -138,7 +140,7 @@ def get_filenames(args):
for files in os.listdir(cli_input):
if files.endswith(('.mov', '.mp4', '.mxf', '.mkv', '.avi')):
if files[0] != '.':
video_files.append(os.path.join(cli_input,files))
video_files.append(os.path.join(cli_input, files))
# Prints some stuff if input isn't a file or directory.
else:
print "Your input isn't a file or a directory."
Expand All @@ -159,12 +161,20 @@ def setup_drawtext(args, filename):
font_path = "fontfile=/usr/share/fonts/truetype/freefont/FreeSerifBold.ttf"
elif sys.platform == "win32":
font_path = "'fontfile=C\:\\\Windows\\\Fonts\\\\'arial.ttf'"
# Get starting timecode in a raw state that requires processing further on in the script.
timecode_test_raw = getffprobe('timecode_test_raw', 'format_tags=timecode:stream_tags=timecode', filename)
framerate = getffprobe('get_frame_rate', 'stream=avg_frame_rate', filename).rstrip()
# Get starting timecode
timecode_test_raw = getffprobe(
'timecode_test_raw',
'format_tags=timecode:stream_tags=timecode',
filename
)
framerate = getffprobe(
'get_frame_rate',
'stream=avg_frame_rate',
filename
).rstrip()
# This tests if there is actually a timecode present in the file.
if not timecode_test_raw:
# The timecode needs to be phrased in a way unique to each operating system.
# The timecode needs to be phrased in a way unique to each O.S.
# Note the backslashes.
# This section makes up a timecode if none is present in the file.
if sys.platform == "darwin" or sys.platform == "linux2":
Expand Down
50 changes: 34 additions & 16 deletions giffer.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,48 @@
#!/usr/bin/env python
'''
Takes a video file as source and generates a sidecar gif animation.
'''
import sys
import os
import subprocess


def make_palette(input):
cmd = ['ffmpeg',
'-i', input,
'-filter_complex',
'fps=24,scale=500:-1:flags=lanczos,palettegen',
'palette.png']
def make_palette(source):
'''
analyses your source file in order to determine the colour palette.
'''
cmd = [
'ffmpeg',
'-i', source,
'-filter_complex',
'fps=24,scale=500:-1:flags=lanczos,palettegen',
'palette.png'
]
subprocess.call(cmd)

def make_gif(input):
cmd = ['ffmpeg',
'-i', input,
'-i', 'palette.png',
'-filter_complex',
'[0:v]fps=24,scale=500:-1:flags=lanczos[v],[v][1:v]paletteuse',
input + '.gif']
def make_gif(source):
'''
Uses the palette that is generated by make_pallete() in order to
make a gif.
'''
cmd = [
'ffmpeg',
'-i', source,
'-i', 'palette.png',
'-filter_complex',
'[0:v]fps=24,scale=500:-1:flags=lanczos[v],[v][1:v]paletteuse',
source + '.gif'
]
subprocess.call(cmd)

def main():
input = sys.argv[1]
make_palette(input)
make_gif(input)
'''
Launches the other functions.
'''
source = sys.argv[1]
make_palette(source)
make_gif(source)
os.remove('palette.png')


Expand Down
3 changes: 2 additions & 1 deletion makeuuid.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
'''
This script will create a new UUID via ififuncs.create_uuid and print to terminal
This script will create a new UUID
via ififuncs.create_uuid and print to terminal
'''
from ififuncs import create_uuid

Expand Down
176 changes: 94 additions & 82 deletions manifest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python

'''
Generates sidecar MD5 checksum manifest.
'''
import sys
import subprocess
import os
import getpass
import argparse
import time
import shutil
Expand All @@ -13,96 +13,108 @@
from ififuncs import make_desktop_logs_dir, make_desktop_manifest_dir


def remove_bad_files(root_dir):
def remove_bad_files(root_dir, log_name_source):
'''
Removes unwanted files.
Verify if this is different than the same function in ififuncs.
'''
rm_these = ['.DS_Store', 'Thumbs.db', 'desktop.ini']
for root, dirs, files in os.walk(root_dir):
for root, _, files in os.walk(root_dir):
for name in files:
path = os.path.join(root, name)
for i in rm_these:
if name == i:
print '***********************' + 'removing: ' + path
generate_log(log_name_source, 'EVENT = Unwanted file removal - %s was removed' % path)
generate_log(
log_name_source,
'EVENT = Unwanted file removal - %s was removed' % path
)
try:
os.remove(path)
except OSError:
print 'can\'t delete as source is read-only'

parser = argparse.ArgumentParser(description='Generate manifest with checksums for a directory'
' Written by Kieran O\'Leary.')
parser.add_argument('source', help='Input directory')
parser.add_argument('-s', '-sidecar', action='store_true', help='Generates Sidecar')
parser.add_argument('-f', '-felix', action='store_true', help='Felix Meehan workflow - places manifest inside of source directory')

args = parser.parse_args()

source = args.source
source_parent_dir = os.path.dirname(source)
normpath = os.path.normpath(source)
dirname = os.path.split(os.path.basename(source))[1]
relative_path = normpath.split(os.sep)[-1]
log_name_source_ = os.path.basename(args.source) + time.strftime("_%Y_%m_%dT%H_%M_%S")
if args.s:
manifest = source_parent_dir + '/%s_manifest.md5' % relative_path
log_name_source = source_parent_dir + '/%s.log' % log_name_source_

elif args.f:
manifest = source + '/%s_manifest.md5' % relative_path
log_name_source = source_parent_dir + '/%s.log' % log_name_source_
else:
manifest_ = '/%s_manifest.md5' % relative_path
desktop_manifest_dir = make_desktop_manifest_dir()
manifest = "%s/%s" % (desktop_manifest_dir, manifest_)


desktop_logs_dir = make_desktop_logs_dir()
log_name_source = "%s/%s.log" % (desktop_logs_dir, log_name_source_)


generate_log(log_name_source, 'move.py started.')
generate_log(log_name_source, 'Source: %s' % source)

if os.path.isfile(source):
print '\nFile checksum is not currently supported, only directories.\n'
generate_log(log_name_source, 'Error: Attempted to generate manifest for file. Only Directories/Folders are currently supported')
generate_log(log_name_source, 'move.py exit')
sys.exit()
elif not os.path.isdir(source):
print ' %s is either not a directory or it does not exist' % source
generate_log(log_name_source, ' %s is either not a directory or it does not exist' % source)
generate_log(log_name_source, 'move.py exit')
sys.exit()

remove_bad_files(source)
source_count = 0
for root, directories, filenames in os.walk(source):
for files in filenames:
source_count +=1 #works in windows at least


if os.path.isfile(manifest):
count_in_manifest = manifest_file_count(manifest)
if source_count != count_in_manifest:
print 'This manifest may be outdated as the number of files in your directory does not match the number of files in the manifest'
generate_log(log_name_source, 'EVENT = Existing source manifest check - Failure - The number of files in the source directory is not equal to the number of files in the source manifest ')
def main():
'''
Overly long main function that makes a sidecar manifest.
This needs to get broken up into smaller functions.
'''
parser = argparse.ArgumentParser(description='Generate manifest with'
' checksums for a directory'
' Written by Kieran O\'Leary.')
parser.add_argument(
'source',
help='Input directory'
)
parser.add_argument(
'-s', '-sidecar',
action='store_true',
help='Generates Sidecar'
)
parser.add_argument(
'-f', '-felix',
action='store_true',
help='Felix Meehan workflow - places manifest inside of source directory'
)

args = parser.parse_args()
source = args.source
source_parent_dir = os.path.dirname(source)
normpath = os.path.normpath(source)
relative_path = normpath.split(os.sep)[-1]
log_name_source_ = os.path.basename(
args.source
) + time.strftime("_%Y_%m_%dT%H_%M_%S")
if args.s:
manifest = source_parent_dir + '/%s_manifest.md5' % relative_path
log_name_source = source_parent_dir + '/%s.log' % log_name_source_
elif args.f:
manifest = source + '/%s_manifest.md5' % relative_path
log_name_source = source_parent_dir + '/%s.log' % log_name_source_
else:
manifest_ = '/%s_manifest.md5' % relative_path
desktop_manifest_dir = make_desktop_manifest_dir()
manifest = "%s/%s" % (desktop_manifest_dir, manifest_)
desktop_logs_dir = make_desktop_logs_dir()
log_name_source = "%s/%s.log" % (desktop_logs_dir, log_name_source_)
generate_log(log_name_source, 'move.py started.')
generate_log(log_name_source, 'Source: %s' % source)
if os.path.isfile(source):
print '\nFile checksum is not currently supported, only directories.\n'
generate_log(log_name_source, 'Error: Attempted to generate manifest for file. Only Directories/Folders are currently supported')
generate_log(log_name_source, 'move.py exit')
sys.exit()
source_manifest_start_time = time.time()

if not os.path.isfile(manifest):
try:
print 'Generating source manifest'
if args.f:
hashlib_manifest(source, manifest,source)
shutil.move(log_name_source, source)
else:
hashlib_manifest(source, manifest,source_parent_dir)
generate_log(log_name_source, 'EVENT = Generating source manifest')


except OSError:
elif not os.path.isdir(source):
print ' %s is either not a directory or it does not exist' % source
generate_log(log_name_source, ' %s is either not a directory or it does not exist' % source)
generate_log(log_name_source, 'move.py exit')
sys.exit()
remove_bad_files(source, log_name_source)
source_count = 0
for _, _, filenames in os.walk(source):
# There has to be a better way to count the files..
for _ in filenames:
source_count += 1 #works in windows at least
if os.path.isfile(manifest):
count_in_manifest = manifest_file_count(manifest)
if source_count != count_in_manifest:
print 'This manifest may be outdated as the number of files in your directory does not match the number of files in the manifest'
generate_log(log_name_source, 'EVENT = Existing source manifest check - Failure - The number of files in the source directory is not equal to the number of files in the source manifest ')
sys.exit()
if not os.path.isfile(manifest):
try:
print 'Generating source manifest'
if args.f:
hashlib_manifest(source, manifest, source)
shutil.move(log_name_source, source)
else:
hashlib_manifest(source, manifest, source_parent_dir)
generate_log(log_name_source, 'EVENT = Generating source manifest')
except OSError:
print 'You do not have access to this directory. Perhaps it is read only, or the wrong file system\n'
sys.exit()
else:
generate_log(log_name_source, 'EVENT = Existing source manifest check - Source manifest already exists. Script will exit. ')
source_manifest_time = time.time() - source_manifest_start_time
else:
generate_log(log_name_source, 'EVENT = Existing source manifest check - Source manifest already exists. Script will exit. ')
print 'Manifest created in %s' % manifest

print 'Manifest created in %s' % manifest
if __name__ == '__main__':
main()
18 changes: 11 additions & 7 deletions masscopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
'''
Launches copyit.py for subfolders that have md5 anifests.
'''
import sys
import os
import subprocess
import argparse
import time
import copyit
from ififuncs import make_desktop_logs_dir

Expand Down Expand Up @@ -79,7 +76,9 @@ def find_manifest(args):
)
if os.path.isdir(full_subdirectory_path):
manifest = os.path.join(
os.path.dirname(full_subdirectory_path), subdirectories + '_manifest.md5'
os.path.dirname(
full_subdirectory_path
), subdirectories + '_manifest.md5'
)
if os.path.isfile(manifest):
dirlist.append(os.path.dirname(full_subdirectory_path))
Expand All @@ -101,7 +100,8 @@ def analyze_reports(log_names, desktop_logs_dir):
# look at log filename minus the seconds and '.log'
if os.path.basename(i)[:-7] in logs:
# make sure that the alternate log filename is more recent
if int(os.path.basename(logs)[-12:-4].replace('_', '')) > int(os.path.basename(i)[-12:-4].replace('_', '')):
if int(
os.path.basename(logs)[-12:-4].replace('_', '')) > int(os.path.basename(i)[-12:-4].replace('_', '')):
print 'trying to analyze %s' % logs
print "%-*s : %s" % (50, os.path.basename(logs)[:-24], analyze_log(os.path.join(desktop_logs_dir, logs)))

Expand All @@ -126,10 +126,14 @@ def main():
else:
desktop_logs_dir = make_desktop_logs_dir()
if args.l:
log_name = copyit.main(['-l', os.path.join(args.input, i), args.o])
log_name = copyit.main(
['-l', os.path.join(args.input, i), args.o]
)
log_names.append(log_name)
else:
log_name = copyit.main([ os.path.join(args.input, i), args.o])
log_name = copyit.main(
[os.path.join(args.input, i), args.o]
)
log_names.append(log_name)
processed_dirs.append(os.path.basename(os.path.join(args.input, i)))
print '********\nWARNING - Please check the ifiscripts_logs directory on your Desktop to verify if ALL of your transfers were successful'
Expand Down
Loading

0 comments on commit c4beb55

Please sign in to comment.