Skip to content

Commit

Permalink
Lots of new main() stuff. Merge branch 'develop' into feature/parse_ccc
Browse files Browse the repository at this point in the history
Conflicts:
	cdl_convert/cdl_convert.py
	tests/test_cdl_convert.py
  • Loading branch information
shidarin committed May 10, 2014
2 parents eebe634 + f779c95 commit 290ecc0
Show file tree
Hide file tree
Showing 4 changed files with 380 additions and 2 deletions.
130 changes: 129 additions & 1 deletion cdl_convert/cdl_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@

# HALT_ON_ERROR is the exception handling variable for exceptions that can
# be handled silently.
#
# If we begin to get more config options, this will be moved into a singleton
# config class.
#
# Used in the following places:
# Slope, power and sat values can't be negative and will truncate to 0.0
# If id given to ColorCorrection is blank, will set to number of CCs
Expand Down Expand Up @@ -667,6 +671,12 @@ class ColorCorrection(AscDescBase, AscColorSpaceBase, AscXMLBase): # pylint: di
file_out : (str)
Filepath this :class:`ColorCorrection` will be written to.
has_sat : (bool)
Returns True if SOP values are set
has_sop : (bool)
Returns True if SOP values are set
id : (str)
Unique XML URI to identify this CDL. Often a shot or sequence name.
Expand Down Expand Up @@ -791,6 +801,22 @@ def file_out(self):
"""Returns a theoretical absolute filepath based on output ext"""
return self._file_out

@property
def has_sat(self):
"""Returns True if SOP values are set"""
if self.sat_node:
return True
else:
return False

@property
def has_sop(self):
"""Returns True if SOP values are set"""
if self.sop_node:
return True
else:
return False

@property
def id(self): # pylint: disable=C0103
"""Returns unique color correction id field"""
Expand Down Expand Up @@ -2423,6 +2449,67 @@ def build_cc(line_id, edl_path, sop_dict, sat_value, title_line):
cdls.append(cdl)

return cdls
# ==============================================================================


def sanity_check(colcor):
"""Checks values on :class:`ColorCorrection` for sanity.
**Args:**
colcor : (:class:`ColorCorrection`)
The :class:`ColorCorrection` to check for sane values.
**Returns:**
(bool)
Returns True if all values are sane.
**Raises:**
N/A
Will print a warning to stdout if any values exceed normal limits.
Normal limits are defined as:
For Slope, Power and Saturation:
Any value over 3 or under 0.1
For Offset:
Any value over 1 or under -1
Note that depending on the desired look for a shot or sequence, it's
possible that a single ColorCorrection element might have very odd
looking values and still achieve a correct look.
"""
sane_values = True

def _check_value(value, range, value_type):
"""Checks if a value falls outside of min or max"""
if value <= range[0] or value >= range[1]:
print(
'The ColorCorrection "{id}" was given a {type} value of '
'"{value}", which might be incorrect.'.format(
id=colcor.id,
type=value_type,
value=value
)
)
return False
else:
return True

if colcor.has_sop:
for i in xrange(3):
slope = _check_value(colcor.slope[i], (0.1, 3.0), 'Slope')
offset = _check_value(colcor.offset[i], (-1.0, 1.0), 'Offset')
power = _check_value(colcor.power[i], (0.1, 3.0), 'Power')
if not slope or not offset or not power:
sane_values = False

if colcor.has_sat:
if not _check_value(colcor.sat, (0.1, 3.0), 'Saturation'):
sane_values = False

return sane_values

# ==============================================================================

Expand Down Expand Up @@ -2507,6 +2594,32 @@ def parse_args():
"accepted. Defaults to a .cc XML. Supported output formats are: " # pylint: disable=C0330
"{outputs}".format(outputs=str(OUTPUT_FORMATS.keys())) # pylint: disable=C0330
)
parser.add_argument(
"--halt",
action='store_true',
help="turns off exception handling default behavior. Turn this on if "
"you want the conversion process to fail and not continue," # pylint: disable=C0330
"rather than relying on default behavior for bad values. Examples " # pylint: disable=C0330
"are clipping negative values to 0.0 for Slope, Power and " # pylint: disable=C0330
"Saturation, and automatically generating a new id for a " # pylint: disable=C0330
"ColorCorrect if no or a bad id is given." # pylint: disable=C0330
)
parser.add_argument(
"--no-output",
action='store_true',
help="parses all incoming files but no files will be written. Use this "
"in conjunction with '--halt' and '--check to try and " # pylint: disable=C0330
"track down any oddities observed in the CDLs." # pylint: disable=C0330
)
parser.add_argument(
"--check",
action='store_true',
help="checks all ColorCorrects that were parsed for odd values. Odd "
"values are any values over 3 or under 0.1 for Slope, Power " # pylint: disable=C0330
"and Saturation. For offset, any value over 1 and under -1 is " # pylint: disable=C0330
"flagged. Note that depending on the look, these still might " # pylint: disable=C0330
"be correct values." # pylint: disable=C0330
)

args = parser.parse_args()

Expand Down Expand Up @@ -2542,6 +2655,10 @@ def parse_args():
else:
args.output = ['cc', ]

if args.halt:
global HALT_ON_ERROR # pylint: disable=W0603
HALT_ON_ERROR = True

return args

# ==============================================================================
Expand All @@ -2551,6 +2668,9 @@ def main():
"""Will figure out input and destination filetypes, then convert"""
args = parse_args()

if args.no_output:
print("Dry run initiated, no files will be written.")

filepath = os.path.abspath(args.input_file)

if not args.input:
Expand All @@ -2568,9 +2688,17 @@ def write_single_file(cdl, ext):
path=cdl.file_out
)
)
OUTPUT_FORMATS[ext](cdl)
if not args.no_output:
OUTPUT_FORMATS[ext](cdl)

if color_decisions:
# Sanity Check
if filetype_in in COLLECTION_FORMATS:
for color_correct in color_decisions.color_corrections:
sanity_check(color_correct)
else:
sanity_check(color_decisions)
# Writing
for ext in args.output:
if ext in SINGLE_FORMATS:
if filetype_in in COLLECTION_FORMATS:
Expand Down
8 changes: 8 additions & 0 deletions docs/cdl_convert.rst
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ SopNode

.. autoclass:: cdl_convert.SopNode

General Functions
===============

Sanity Check
------------

.. autofunction:: cdl_convert.sanity_check

Parse Functions
===============

Expand Down
36 changes: 35 additions & 1 deletion docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,28 @@ input file format. This can be done with the ``-i`` flag.
but if you're running into trouble, it might help to indicate to
``cdl_convert`` what the input file type is.

When converting large batches of color corrections, it can be helpful to know
if there's anything odd about any of them. Using the ``--check`` flag will
cause any potentially invalid numbers to be flagged and printed to the shell.

For Slope, Power and Saturation, any values below ``0.1`` or above ``3.0`` will
flag. For Offset, any values below ``-1.0`` or above ``1.0`` will flag.
::
$ cdl_convert ./di_v001.flex
The ColorCorrection "a347.x700" was given a Slope value of "0.978", which
might be incorrect.
The ColorCorrection "a400.x050" was given a Saturation value of "3.1",
which might be incorrect.

This is especially useful when combined with the ``--no-output`` flag, which
will enable a dry run mode and allow you to spot odd values before running.

Full help is available using the standard ``--help`` command:
::
$ cdl_convert --help
usage: cdl_convert [-h] [-i INPUT] [-o OUTPUT] input_file
usage: cdl_convert.py [-h] [-i INPUT] [-o OUTPUT] [--halt] [--no-output]
[--check]
input_file

positional arguments:
input_file the file to be converted
Expand All @@ -51,6 +69,22 @@ Full help is available using the standard ``--help`` command:
specify the filetype to convert to, comma separated
lists are accepted. Defaults to a .cc XML. Supported
output formats are: ['cc', 'cdl']
--halt turns off exception handling default behavior. Turn
this on if you want the conversion process to fail and
not continue,rather than relying on default behavior
for bad values. Examples are clipping negative values
to 0.0 for Slope, Power and Saturation, and
automatically generating a new id for a ColorCorrect
if no or a bad id is given.
--no-output parses all incoming files but no files will be
written. Use this in conjunction with '--halt' and '--
check to try and track down any oddities observed in
the CDLs.
--check checks all ColorCorrects that were parsed for odd
values. Odd values are any values over 3 or under 0.1
for Slope, Power and Saturation. For offset, any value
over 1 and under -1 is flagged. Note that depending on
the look, these still might be correct values.

Python Usage
============
Expand Down
Loading

0 comments on commit 290ecc0

Please sign in to comment.