<commit_before># -*- coding: utf-8 -*-
"""Usage information for the main IPython applications.
"""
#-----------------------------------------------------------------------------
#  Copyright (C) 2008-2011  The IPython Development Team
#  Copyright (C) 2001-2007 Fernando Perez. <fperez@colorado.edu>
#
#  Distributed under the terms of the BSD License.  The full license is in
#  the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------

import sys
from IPython.core import release

cl_usage = """\
=========
 IPython
=========

Tools for Interactive Computing in Python
=========================================

    A Python shell with automatic history (input and output), dynamic object
    introspection, easier configuration, command completion, access to the
    system shell and more.  IPython can also be embedded in running programs.

Usage

    ipython [subcommand] [options] [-c cmd | -m mod | file] [--] [arg] ...

    If invoked with no options, it executes the file and exits, passing the
    remaining arguments to the script, just as if you had specified the same
    command with python. You may need to specify `--` before args to be passed
    to the script, to prevent IPython from attempting to parse them. If you
    specify the option `-i` before the filename, it will enter an interactive
    IPython session after running the script, rather than exiting. Files ending
    in .py will be treated as normal Python, but files ending in .ipy can
    contain special IPython syntax (magic commands, shell expansions, etc.).

    Almost all configuration in IPython is available via the command-line. Do
    `ipython --help-all` to see all available options.  For persistent
    configuration, look into your `ipython_config.py` configuration file for
    details.

    This file is typically installed in the `IPYTHONDIR` directory, and there
    is a separate configuration directory for each profile. The default profile
    directory will be located in $IPYTHONDIR/profile_default. IPYTHONDIR
    defaults to to `$HOME/.ipython`.  For Windows users, $HOME resolves to
    C:\\Users\\YourUserName in most instances.

    To initialize a profile with the default configuration file, do::

      $> ipython profile create

    and start editing `IPYTHONDIR/profile_default/ipython_config.py`

    In IPython's documentation, we will refer to this directory as
    `IPYTHONDIR`, you can change its default location by creating an
    environment variable with this name and setting it to the desired path.

    For more information, see the manual available in HTML and PDF in your
    installation, or online at http://ipython.org/documentation.html.
"""

interactive_usage = """
IPython -- An enhanced Interactive Python
=========================================

IPython offers fully compatible replacement for the standard Python
interpreter with convenient shell features, special commands, command
history mechanism and output results caching.

At your system command line, type 'ipython -h' to see the command line
options available. This document only describes interactive features.

GETTING HELP
------------

Within IPython you have various way to access help:

  ?         -> Introduction and overview of IPython's features (this screen).
  object?   -> Details about 'object'.
  object??  -> More detailed, verbose information about 'object'.
  %quickref -> Quick reference of all IPython specific syntax and magics.
  help      -> Access Python's own help system.

If you are in terminal IPython you can quit this screen by pressing `q`.

MAIN FEATURES
-------------

* Access to the standard Python help with object docstrings and the Python
  manuals. Simply type 'help' (no quotes) to invoke it.

* Magic commands: type %magic for information on the magic subsystem.

* System command aliases, via the %alias command or the configuration file(s).

* Dynamic object information:

  Typing ?word or word? prints detailed information about an object.  Long
  strings (docstrings, code, etc.) get snipped in the center for brevity.

  Typing ??word or word?? gives access to the full information without
  snipping long strings. Strings that are longer than the screen are printed
  through the less pager.

  The ?/?? system gives access to the full source code for any object (if
  available), shows function prototypes and other useful information.

  If you just want to see an object's docstring, type '%pdoc object' (without
  quotes, and without % if you have automagic on).

* Tab completion in the local namespace:

  At any time, hitting tab will complete any available python commands or
  variable names, and show you a list of the possible completions if there's
  no unambiguous one. It will also complete filenames in the current directory.

* Search previous command history in multiple ways:

  - Start typing, and then use Ctrl-p (previous, up) and Ctrl-n (next, down)
    to search through the history items that match what you've typed so
    far. At a blank prompt, Ctrl-p/Ctrl-n behave like normal arrow keys.

  - Hit Ctrl-r: opens a search prompt. Begin typing and the system searches
    your history for lines that match what you've typed so far, completing as
    much as it can.

  - %hist: search history by index.

* Persistent command history across sessions.

* Logging of input with the ability to save and restore a working session.

* System shell with !. Typing !ls will run 'ls' in the current directory.

* The reload command does a 'deep' reload of a module: changes made to the
  module since you imported will actually be available without having to exit.

* Verbose and colored exception traceback printouts. See the magic xmode and
  xcolor functions for details (just type %magic).

* Input caching system:

  IPython offers numbered prompts (In/Out) with input and output caching. All
  input is saved and can be retrieved as variables (besides the usual arrow
  key recall).

  The following GLOBAL variables always exist (so don't overwrite them!):
  _i: stores previous input.
  _ii: next previous.
  _iii: next-next previous.
  _ih : a list of all input _ih[n] is the input from line n.

  Additionally, global variables named _i<n> are dynamically created (<n>
  being the prompt counter), such that _i<n> == _ih[<n>]

  For example, what you typed at prompt 14 is available as _i14 and _ih[14].

  You can create macros which contain multiple input lines from this history,
  for later re-execution, with the %macro function.

  The history function %hist allows you to see any part of your input history
  by printing a range of the _i variables. Note that inputs which contain
  magic functions (%) appear in the history with a prepended comment. This is
  because they aren't really valid Python code, so you can't exec them.

* Output caching system:

  For output that is returned from actions, a system similar to the input
  cache exists but using _ instead of _i. Only actions that produce a result
  (NOT assignments, for example) are cached. If you are familiar with
  Mathematica, IPython's _ variables behave exactly like Mathematica's %
  variables.

  The following GLOBAL variables always exist (so don't overwrite them!):
  _ (one underscore): previous output.
  __ (two underscores): next previous.
  ___ (three underscores): next-next previous.

  Global variables named _<n> are dynamically created (<n> being the prompt
  counter), such that the result of output <n> is always available as _<n>.

  Finally, a global dictionary named _oh exists with entries for all lines
  which generated output.

* Directory history:

  Your history of visited directories is kept in the global list _dh, and the
  magic %cd command can be used to go to any entry in that list.

* Auto-parentheses and auto-quotes (adapted from Nathan Gray's LazyPython)

  1. Auto-parentheses

     Callable objects (i.e. functions, methods, etc) can be invoked like
     this (notice the commas between the arguments)::

         In [1]: callable_ob arg1, arg2, arg3

     and the input will be translated to this::

         callable_ob(arg1, arg2, arg3)

     This feature is off by default (in rare cases it can produce
     undesirable side-effects), but you can activate it at the command-line
     by starting IPython with `--autocall 1`, set it permanently in your
     configuration file, or turn on at runtime with `%autocall 1`.

     You can force auto-parentheses by using '/' as the first character
     of a line.  For example::

          In [1]: /globals             # becomes 'globals()'

     Note that the '/' MUST be the first character on the line!  This
     won't work::

          In [2]: print /globals    # syntax error

     In most cases the automatic algorithm should work, so you should
     rarely need to explicitly invoke /. One notable exception is if you
     are trying to call a function with a list of tuples as arguments (the
     parenthesis will confuse IPython)::

          In [1]: zip (1,2,3),(4,5,6)  # won't work

     but this will work::

          In [2]: /zip (1,2,3),(4,5,6)
          ------> zip ((1,2,3),(4,5,6))
          Out[2]= [(1, 4), (2, 5), (3, 6)]

     IPython tells you that it has altered your command line by
     displaying the new command line preceded by -->.  e.g.::

          In [18]: callable list
          -------> callable (list)

  2. Auto-Quoting

     You can force auto-quoting of a function's arguments by using ',' as
     the first character of a line.  For example::

          In [1]: ,my_function /home/me   # becomes my_function("/home/me")

     If you use ';' instead, the whole argument is quoted as a single
     string (while ',' splits on whitespace)::

          In [2]: ,my_function a b c   # becomes my_function("a","b","c")
          In [3]: ;my_function a b c   # becomes my_function("a b c")

     Note that the ',' MUST be the first character on the line!  This
     won't work::

          In [4]: x = ,my_function /home/me    # syntax error
"""

interactive_usage_min =  """\
An enhanced console for Python.
Some of its features are:
- Tab completion in the local namespace.
- Logging of input, see command-line options.
- System shell escape via ! , eg !ls.
- Magic commands, starting with a % (like %ls, %pwd, %cd, etc.)
- Keeps track of locally defined variables via %who, %whos.
- Show object information with a ? eg ?x or x? (use ?? for more info).
"""

quick_reference = r"""
IPython -- An enhanced Interactive Python - Quick Reference Card
================================================================

obj?, obj??      : Get help, or more help for object (also works as
                   ?obj, ??obj).
?foo.*abc*       : List names in 'foo' containing 'abc' in them.
%magic           : Information about IPython's 'magic' % functions.

Magic functions are prefixed by % or %%, and typically take their arguments
without parentheses, quotes or even commas for convenience.  Line magics take a
single % and cell magics are prefixed with two %%.

Example magic function calls:

%alias d ls -F   : 'd' is now an alias for 'ls -F'
alias d ls -F    : Works if 'alias' not a python name
alist = %alias   : Get list of aliases to 'alist'
cd /usr/share    : Obvious. cd -<tab> to choose from visited dirs.
%cd??            : See help AND source for magic %cd
%timeit x=10     : time the 'x=10' statement with high precision.
%%timeit x=2**100
x**100           : time 'x**100' with a setup of 'x=2**100'; setup code is not
                   counted.  This is an example of a cell magic.

System commands:

!cp a.txt b/     : System command escape, calls os.system()
cp a.txt b/      : after %rehashx, most system commands work without !
cp ${f}.txt $bar : Variable expansion in magics and system commands
files = !ls /usr : Capture sytem command output
files.s, files.l, files.n: "a b c", ['a','b','c'], 'a\nb\nc'

History:

_i, _ii, _iii    : Previous, next previous, next next previous input
_i4, _ih[2:5]    : Input history line 4, lines 2-4
exec _i81        : Execute input history line #81 again
%rep 81          : Edit input history line #81
_, __, ___       : previous, next previous, next next previous output
_dh              : Directory history
_oh              : Output history
%hist            : Command history of current session.
%hist -g foo     : Search command history of (almost) all sessions for 'foo'.
%hist -g         : Command history of (almost) all sessions.
%hist 1/2-8      : Command history containing lines 2-8 of session 1.
%hist 1/ ~2/     : Command history of session 1 and 2 sessions before current.
%hist ~8/1-~6/5  : Command history from line 1 of 8 sessions ago to
                   line 5 of 6 sessions ago.
%edit 0/         : Open editor to execute code with history of current session.

Autocall:

f 1,2            : f(1,2)  # Off by default, enable with %autocall magic.
/f 1,2           : f(1,2) (forced autoparen)
,f 1 2           : f("1","2")
;f 1 2           : f("1 2")

Remember: TAB completion works in many contexts, not just file names
or python names.

The following magic functions are currently available:

"""

default_banner_parts = ["Python %s\n"%sys.version.split("\n")[0],
    "Type 'copyright', 'credits' or 'license' for more information\n" ,
    "IPython {version} -- An enhanced Interactive Python. Type '?' for help.\n".format(version=release.version),
]

default_banner = ''.join(default_banner_parts)

# deprecated GUI banner

default_gui_banner = '\n'.join([
    'DEPRECATED: IPython.core.usage.default_gui_banner is deprecated and will be removed',
    default_banner,
])
<commit_msg>Review fixes for interactive help<commit_after># -*- coding: utf-8 -*-
"""Usage information for the main IPython applications.
"""
#-----------------------------------------------------------------------------
#  Copyright (C) 2008-2011  The IPython Development Team
#  Copyright (C) 2001-2007 Fernando Perez. <fperez@colorado.edu>
#
#  Distributed under the terms of the BSD License.  The full license is in
#  the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------

import sys
from IPython.core import release

cl_usage = """\
=========
 IPython
=========

Tools for Interactive Computing in Python
=========================================

    A Python shell with automatic history (input and output), dynamic object
    introspection, easier configuration, command completion, access to the
    system shell and more.  IPython can also be embedded in running programs.

Usage

    ipython [subcommand] [options] [-c cmd | -m mod | file] [--] [arg] ...

    If invoked with no options, it executes the file and exits, passing the
    remaining arguments to the script, just as if you had specified the same
    command with python. You may need to specify `--` before args to be passed
    to the script, to prevent IPython from attempting to parse them. If you
    specify the option `-i` before the filename, it will enter an interactive
    IPython session after running the script, rather than exiting. Files ending
    in .py will be treated as normal Python, but files ending in .ipy can
    contain special IPython syntax (magic commands, shell expansions, etc.).

    Almost all configuration in IPython is available via the command-line. Do
    `ipython --help-all` to see all available options.  For persistent
    configuration, look into your `ipython_config.py` configuration file for
    details.

    This file is typically installed in the `IPYTHONDIR` directory, and there
    is a separate configuration directory for each profile. The default profile
    directory will be located in $IPYTHONDIR/profile_default. IPYTHONDIR
    defaults to to `$HOME/.ipython`.  For Windows users, $HOME resolves to
    C:\\Users\\YourUserName in most instances.

    To initialize a profile with the default configuration file, do::

      $> ipython profile create

    and start editing `IPYTHONDIR/profile_default/ipython_config.py`

    In IPython's documentation, we will refer to this directory as
    `IPYTHONDIR`, you can change its default location by creating an
    environment variable with this name and setting it to the desired path.

    For more information, see the manual available in HTML and PDF in your
    installation, or online at http://ipython.org/documentation.html.
"""

interactive_usage = """
IPython -- An enhanced Interactive Python
=========================================

IPython offers a fully compatible replacement for the standard Python
interpreter, with convenient shell features, special commands, command
history mechanism and output results caching.

At your system command line, type 'ipython -h' to see the command line
options available. This document only describes interactive features.

GETTING HELP
------------

Within IPython you have various way to access help:

  ?         -> Introduction and overview of IPython's features (this screen).
  object?   -> Details about 'object'.
  object??  -> More detailed, verbose information about 'object'.
  %quickref -> Quick reference of all IPython specific syntax and magics.
  help      -> Access Python's own help system.

If you are in terminal IPython you can quit this screen by pressing `q`.

MAIN FEATURES
-------------

* Access to the standard Python help with object docstrings and the Python
  manuals. Simply type 'help' (no quotes) to invoke it.

* Magic commands: type %magic for information on the magic subsystem.

* System command aliases, via the %alias command or the configuration file(s).

* Dynamic object information:

  Typing ?word or word? prints detailed information about an object. Certain
  long strings (code, etc.) get snipped in the center for brevity.

  Typing ??word or word?? gives access to the full information without
  snipping long strings. Strings that are longer than the screen are printed
  through the less pager.

  The ?/?? system gives access to the full source code for any object (if
  available), shows function prototypes and other useful information.

  If you just want to see an object's docstring, type '%pdoc object' (without
  quotes, and without % if you have automagic on).

* Tab completion in the local namespace:

  At any time, hitting tab will complete any available python commands or
  variable names, and show you a list of the possible completions if there's
  no unambiguous one. It will also complete filenames in the current directory.

* Search previous command history in multiple ways:

  - Start typing, and then use arrow keys up/down or (Ctrl-p/Ctrl-n) to search
    through the history items that match what you've typed so far.

  - Hit Ctrl-r: opens a search prompt. Begin typing and the system searches
    your history for lines that match what you've typed so far, completing as
    much as it can.

  - %hist: search history by index.

* Persistent command history across sessions.

* Logging of input with the ability to save and restore a working session.

* System shell with !. Typing !ls will run 'ls' in the current directory.

* The reload command does a 'deep' reload of a module: changes made to the
  module since you imported will actually be available without having to exit.

* Verbose and colored exception traceback printouts. See the magic xmode and
  xcolor functions for details (just type %magic).

* Input caching system:

  IPython offers numbered prompts (In/Out) with input and output caching. All
  input is saved and can be retrieved as variables (besides the usual arrow
  key recall).

  The following GLOBAL variables always exist (so don't overwrite them!):
  _i: stores previous input.
  _ii: next previous.
  _iii: next-next previous.
  _ih : a list of all input _ih[n] is the input from line n.

  Additionally, global variables named _i<n> are dynamically created (<n>
  being the prompt counter), such that _i<n> == _ih[<n>]

  For example, what you typed at prompt 14 is available as _i14 and _ih[14].

  You can create macros which contain multiple input lines from this history,
  for later re-execution, with the %macro function.

  The history function %hist allows you to see any part of your input history
  by printing a range of the _i variables. Note that inputs which contain
  magic functions (%) appear in the history with a prepended comment. This is
  because they aren't really valid Python code, so you can't exec them.

* Output caching system:

  For output that is returned from actions, a system similar to the input
  cache exists but using _ instead of _i. Only actions that produce a result
  (NOT assignments, for example) are cached. If you are familiar with
  Mathematica, IPython's _ variables behave exactly like Mathematica's %
  variables.

  The following GLOBAL variables always exist (so don't overwrite them!):
  _ (one underscore): previous output.
  __ (two underscores): next previous.
  ___ (three underscores): next-next previous.

  Global variables named _<n> are dynamically created (<n> being the prompt
  counter), such that the result of output <n> is always available as _<n>.

  Finally, a global dictionary named _oh exists with entries for all lines
  which generated output.

* Directory history:

  Your history of visited directories is kept in the global list _dh, and the
  magic %cd command can be used to go to any entry in that list.

* Auto-parentheses and auto-quotes (adapted from Nathan Gray's LazyPython)

  1. Auto-parentheses

     Callable objects (i.e. functions, methods, etc) can be invoked like
     this (notice the commas between the arguments)::

         In [1]: callable_ob arg1, arg2, arg3

     and the input will be translated to this::

         callable_ob(arg1, arg2, arg3)

     This feature is off by default (in rare cases it can produce
     undesirable side-effects), but you can activate it at the command-line
     by starting IPython with `--autocall 1`, set it permanently in your
     configuration file, or turn on at runtime with `%autocall 1`.

     You can force auto-parentheses by using '/' as the first character
     of a line.  For example::

          In [1]: /globals             # becomes 'globals()'

     Note that the '/' MUST be the first character on the line!  This
     won't work::

          In [2]: print /globals    # syntax error

     In most cases the automatic algorithm should work, so you should
     rarely need to explicitly invoke /. One notable exception is if you
     are trying to call a function with a list of tuples as arguments (the
     parenthesis will confuse IPython)::

          In [1]: zip (1,2,3),(4,5,6)  # won't work

     but this will work::

          In [2]: /zip (1,2,3),(4,5,6)
          ------> zip ((1,2,3),(4,5,6))
          Out[2]= [(1, 4), (2, 5), (3, 6)]

     IPython tells you that it has altered your command line by
     displaying the new command line preceded by -->.  e.g.::

          In [18]: callable list
          -------> callable (list)

  2. Auto-Quoting

     You can force auto-quoting of a function's arguments by using ',' as
     the first character of a line.  For example::

          In [1]: ,my_function /home/me   # becomes my_function("/home/me")

     If you use ';' instead, the whole argument is quoted as a single
     string (while ',' splits on whitespace)::

          In [2]: ,my_function a b c   # becomes my_function("a","b","c")
          In [3]: ;my_function a b c   # becomes my_function("a b c")

     Note that the ',' MUST be the first character on the line!  This
     won't work::

          In [4]: x = ,my_function /home/me    # syntax error
"""

interactive_usage_min =  """\
An enhanced console for Python.
Some of its features are:
- Tab completion in the local namespace.
- Logging of input, see command-line options.
- System shell escape via ! , eg !ls.
- Magic commands, starting with a % (like %ls, %pwd, %cd, etc.)
- Keeps track of locally defined variables via %who, %whos.
- Show object information with a ? eg ?x or x? (use ?? for more info).
"""

quick_reference = r"""
IPython -- An enhanced Interactive Python - Quick Reference Card
================================================================

obj?, obj??      : Get help, or more help for object (also works as
                   ?obj, ??obj).
?foo.*abc*       : List names in 'foo' containing 'abc' in them.
%magic           : Information about IPython's 'magic' % functions.

Magic functions are prefixed by % or %%, and typically take their arguments
without parentheses, quotes or even commas for convenience.  Line magics take a
single % and cell magics are prefixed with two %%.

Example magic function calls:

%alias d ls -F   : 'd' is now an alias for 'ls -F'
alias d ls -F    : Works if 'alias' not a python name
alist = %alias   : Get list of aliases to 'alist'
cd /usr/share    : Obvious. cd -<tab> to choose from visited dirs.
%cd??            : See help AND source for magic %cd
%timeit x=10     : time the 'x=10' statement with high precision.
%%timeit x=2**100
x**100           : time 'x**100' with a setup of 'x=2**100'; setup code is not
                   counted.  This is an example of a cell magic.

System commands:

!cp a.txt b/     : System command escape, calls os.system()
cp a.txt b/      : after %rehashx, most system commands work without !
cp ${f}.txt $bar : Variable expansion in magics and system commands
files = !ls /usr : Capture sytem command output
files.s, files.l, files.n: "a b c", ['a','b','c'], 'a\nb\nc'

History:

_i, _ii, _iii    : Previous, next previous, next next previous input
_i4, _ih[2:5]    : Input history line 4, lines 2-4
exec _i81        : Execute input history line #81 again
%rep 81          : Edit input history line #81
_, __, ___       : previous, next previous, next next previous output
_dh              : Directory history
_oh              : Output history
%hist            : Command history of current session.
%hist -g foo     : Search command history of (almost) all sessions for 'foo'.
%hist -g         : Command history of (almost) all sessions.
%hist 1/2-8      : Command history containing lines 2-8 of session 1.
%hist 1/ ~2/     : Command history of session 1 and 2 sessions before current.
%hist ~8/1-~6/5  : Command history from line 1 of 8 sessions ago to
                   line 5 of 6 sessions ago.
%edit 0/         : Open editor to execute code with history of current session.

Autocall:

f 1,2            : f(1,2)  # Off by default, enable with %autocall magic.
/f 1,2           : f(1,2) (forced autoparen)
,f 1 2           : f("1","2")
;f 1 2           : f("1 2")

Remember: TAB completion works in many contexts, not just file names
or python names.

The following magic functions are currently available:

"""

default_banner_parts = ["Python %s\n"%sys.version.split("\n")[0],
    "Type 'copyright', 'credits' or 'license' for more information\n" ,
    "IPython {version} -- An enhanced Interactive Python. Type '?' for help.\n".format(version=release.version),
]

default_banner = ''.join(default_banner_parts)

# deprecated GUI banner

default_gui_banner = '\n'.join([
    'DEPRECATED: IPython.core.usage.default_gui_banner is deprecated and will be removed',
    default_banner,
])
<|endoftext|>


<commit_before>from pygiftgrab import Codec, ColourSpace

def pytest_addoption(parser):
    parser.addoption('--codec', action='store',
                     help='Codec (HEVC, Xvid, or VP9)')
    parser.addoption('--colour-space', action='store',
                     help='Colour space specification (BGRA or I420)')

def pytest_generate_tests(metafunc):
    if 'codec' in metafunc.fixturenames:
        codec_str = str(metafunc.config.option.codec)
        case_insensitive = codec_str.lower()
        if case_insensitive == 'hevc':
            codec = Codec.HEVC
        elif case_insensitive == 'xvid':
            codec = Codec.Xvid
        elif case_insensitive == 'vp9':
            codec = Codec.VP9
        else:
            raise RuntimeError('Could not recognise codec ' +
                               codec_str)
        metafunc.parametrize('codec', [codec])

    if 'colour_space' in metafunc.fixturenames:
        colour_space_str = str(metafunc.config.option.colour_space)
        case_insensitive = colour_space_str.lower()
        if case_insensitive == 'bgra':
            colour_space = ColourSpace.BGRA
        elif case_insensitive == 'i420':
            colour_space = ColourSpace.I420
        else:
            raise RuntimeError('Could not recognise colour space ' +
                               colour_space_str)
        metafunc.parametrize('colour_space', [colour_space])
<commit_msg>Issue #5: added UYVY colour space option to target tests<commit_after>from pygiftgrab import Codec, ColourSpace

def pytest_addoption(parser):
    parser.addoption('--codec', action='store',
                     help='Codec (HEVC, Xvid, or VP9)')
    parser.addoption('--colour-space', action='store',
                     help='Colour space specification (BGRA, I420, or UYVY)')

def pytest_generate_tests(metafunc):
    if 'codec' in metafunc.fixturenames:
        codec_str = str(metafunc.config.option.codec)
        case_insensitive = codec_str.lower()
        if case_insensitive == 'hevc':
            codec = Codec.HEVC
        elif case_insensitive == 'xvid':
            codec = Codec.Xvid
        elif case_insensitive == 'vp9':
            codec = Codec.VP9
        else:
            raise RuntimeError('Could not recognise codec ' +
                               codec_str)
        metafunc.parametrize('codec', [codec])

    if 'colour_space' in metafunc.fixturenames:
        colour_space_str = str(metafunc.config.option.colour_space)
        case_insensitive = colour_space_str.lower()
        if case_insensitive == 'bgra':
            colour_space = ColourSpace.BGRA
        elif case_insensitive == 'i420':
            colour_space = ColourSpace.I420
        elif case_insensitive == 'uyvy':
            colour_space = ColourSpace.UYVY
        else:
            raise RuntimeError('Could not recognise colour space ' +
                               colour_space_str)
        metafunc.parametrize('colour_space', [colour_space])
<|endoftext|>


<commit_before>#!/usr/bin/env python
'''
Created on Sep 21, 2013

@author: waldo
'''

import glob
import sys
import os

def reduceName(flist):
    '''
    Return a list of classes whose data is being dealt with

    This routine takes the file names supplied by edX and returns a
    list of classes that can be used to isolate the data files by
    course. The current algorithm simply removes the 'HarvardX-'
    prefix, and the '.mongo' extension; it assumes that it is fed
    only the results of the an operation that will give examplars
    of the *.mongo files supplied.

    This is something of a hack. As we continue to talk with edX
    about naming conventions, this should be one of the few places
    that will require change.
    '''
    clist = []
    for f in flist:
        clist.append(f[9: -6])
    return clist

def writeList(of, cl):
    '''
    Writes a class list passed in as cl to the open file of

    Saves a classlist to a file. The file must be opened for write
    or append. The contents of cl will be written one entry per line
    '''
    for c in cl:
        of.write(c + '\n')

def readList(inf):
    '''
    Reads a classlist from the open file inf and returns a list

    Returns a list of the contents of inf, with each entry in the
    list being a single line of the file. Intended to return a
    classlist of the type written by writeList, with the newline removed
    '''
    cl = [];
    for line in inf:
        cl.append(line[ :-1])
    return cl

if __name__ == '__main__':
    if len(sys.argv) > 0:
        os.chdir(sys.argv[1])
    flist = glob.glob('*.mongo')
    clist = reduceName(flist)
    ofile = open('WeeklyClassList', 'w')
    writeList(ofile, clist)
    <commit_msg>Added program to construct a list of classes from an edX dump<commit_after>#!/usr/bin/env python
'''
Created on Sep 21, 2013

@author: waldo
'''

import glob
import sys
import os

def reduceName(flist):
    '''
    Return a list of classes whose data is being dealt with

    This routine takes the file names supplied by edX and returns a
    list of classes that can be used to isolate the data files by
    course. The current algorithm simply removes the 'HarvardX-'
    prefix, and the '.mongo' extension; it assumes that it is fed
    only the results of the an operation that will give examplars
    of the *.mongo files supplied.

    This is something of a hack. As we continue to talk with edX
    about naming conventions, this should be one of the few places
    that will require change.
    '''
    clist = []
    for f in flist:
        clist.append(f[9: -6])
    return clist

def writeList(of, cl):
    '''
    Writes a class list passed in as cl to the open file of

    Saves a classlist to a file. The file must be opened for write
    or append. The contents of cl will be written one entry per line
    '''
    for c in cl:
        of.write(c + '\n')

def readList(inf):
    '''
    Reads a classlist from the open file inf and returns a list

    Returns a list of the contents of inf, with each entry in the
    list being a single line of the file. Intended to return a
    classlist of the type written by writeList, with the newline removed
    '''
    cl = [];
    for line in inf:
        cl.append(line[ :-1])
    return cl

if __name__ == '__main__':
    if len(sys.argv) > 1:
        os.chdir(sys.argv[1])
    flist = glob.glob('*.mongo')
    clist = reduceName(flist)
    ofile = open('WeeklyClassList', 'w')
    writeList(ofile, clist)

<|endoftext|>


<commit_before>from sockets.socket_closed_exception import SocketClosedException
from sockets.stream_socket import StreamSocket

from groundstation import settings
import groundstation.logger
log = groundstation.logger.getLogger(__name__)

class PeerSocket(StreamSocket):
    """Wrapper for a peer who just connected, or one we've connected to

    Since the communication protocol should be implicitly bidirectional, the
    factory methods should be the only instanciation methods"""

    def __init__(self, conn, peer):
        self._sock = conn
        super(PeerSocket, self).__init__()
        self.peer = peer

    @classmethod
    def from_accept(klass, args):
        return klass(*args)

    @classmethod
    def from_connect(klass, args):
        return klass(*args)

    def __repr__(self):
        return "<%s: from %s>" % (self.__class__, self.peer)

class PeerSocketClosedException(SocketClosedException):
    """Raised when a peer closes their socket"""
    pass
<commit_msg>Wrap StreamSocket's send and recv in dedicated exception handling<commit_after>from sockets.socket_closed_exception import SocketClosedException
from sockets.stream_socket import StreamSocket
import socket.error

from groundstation import settings
import groundstation.logger
log = groundstation.logger.getLogger(__name__)

class PeerSocket(StreamSocket):
    """Wrapper for a peer who just connected, or one we've connected to

    Since the communication protocol should be implicitly bidirectional, the
    factory methods should be the only instanciation methods"""

    def __init__(self, conn, peer):
        self._sock = conn
        super(PeerSocket, self).__init__()
        self.peer = peer

    @classmethod
    def from_accept(klass, args):
        return klass(*args)

    @classmethod
    def from_connect(klass, args):
        return klass(*args)

    def __repr__(self):
        return "<%s: from %s>" % (self.__class__, self.peer)

    # Wrap StreamSocket's send and recv in exception handling
    def send(self, *args, **kwargs):
        try:
            return super(PeerSocket, self).send(*args, **kwargs)
        except socket.error as e:
            raise PeerSocketClosedException(e)

    def recv(self, *args, **kwargs):
        try:
            return super(PeerSocket, self).send(*args, **kwargs)
        except socket.error as e:
            raise PeerSocketClosedException(e)

class PeerSocketClosedException(SocketClosedException):
    """Raised when a peer closes their socket"""
    pass
<|endoftext|>


<commit_before># -*- coding: utf-8 -*-
# Copyright 2015 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Additional help text for throttling gsutil."""

from __future__ import absolute_import

from gslib.help_provider import HelpProvider

_DETAILED_HELP_TEXT = ("""
OVERVIEW
  Particularly when used with the -m (multi-threading) option, gsutil can
  consume a significant amount of network bandwidth. In some cases this can
  cause problems, for example if you start a large rsync operation over a
  network connection used by a number of other important production tasks.

  While gsutil has no built-in support for throttling requests, there are
  various tools available on Linux and MacOS that can be used to throttle
  gsutil requests.

  One tool is `trickle<http://monkey.org/~marius/pages/?page=trickle>`_
  (available via apt-get on Ubuntu systems), which will let you limit how much
  bandwidth gsutil consumes. For example, the following command would limit
  upload and download bandwidth consumed by gsutil rsync to 100 KBps:

      trickle -d 100 -u 100 gsutil -m rsync -r ./dir gs://some bucket

  Another tool is
  `ionice<http://www.tutorialspoint.com/unix_commands/ionice.htm>`_ (built
  in to many Linux systems), which will let you limit how much I/O capacity
  gsutil consumes (e.g., to avoid letting it monopolize your local disk). For
  example, the following command would reduce I/O priority of gsutil so it
  doesn't monopolize your local disk:

      ionice -c 2 -n 7 gsutil gsutil -m rsync -r ./dir gs://some bucket
""")

class CommandOptions(HelpProvider):
  """Additional help text for throttling gsutil."""

  # Help specification. See help_provider.py for documentation.
  help_spec = HelpProvider.HelpSpec(
      help_name='throttling',
      help_name_aliases=['bandwidth', 'limit', 'nice'],
      help_type='additional_help',
      help_one_line_summary='Throttling gsutil',
      help_text=_DETAILED_HELP_TEXT,
      subcommand_help_text={},
  )
<commit_msg>Fix gsutil throttling doc typos<commit_after># -*- coding: utf-8 -*-
# Copyright 2015 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Additional help text for throttling gsutil."""

from __future__ import absolute_import

from gslib.help_provider import HelpProvider

_DETAILED_HELP_TEXT = ("""
OVERVIEW
  Particularly when used with the -m (multi-threading) option, gsutil can
  consume a significant amount of network bandwidth. In some cases this can
  cause problems, for example if you start a large rsync operation over a
  network link that's also used by a number of other important jobs.

  While gsutil has no built-in support for throttling requests, there are
  various tools available on Linux and MacOS that can be used to throttle
  gsutil requests.

  One tool is `trickle<http://monkey.org/~marius/pages/?page=trickle>`_
  (available via apt-get on Ubuntu systems), which will let you limit how much
  bandwidth gsutil consumes. For example, the following command would limit
  upload and download bandwidth consumed by gsutil rsync to 100 KBps:

      trickle -d 100 -u 100 gsutil -m rsync -r ./dir gs://some bucket

  Another tool is
  `ionice<http://www.tutorialspoint.com/unix_commands/ionice.htm>`_ (built
  in to many Linux systems), which will let you limit how much I/O capacity
  gsutil consumes (e.g., to avoid letting it monopolize your local disk). For
  example, the following command would reduce I/O priority of gsutil so it
  doesn't monopolize your local disk:

      ionice -c 2 -n 7 gsutil -m rsync -r ./dir gs://some bucket
""")

class CommandOptions(HelpProvider):
  """Additional help text for throttling gsutil."""

  # Help specification. See help_provider.py for documentation.
  help_spec = HelpProvider.HelpSpec(
      help_name='throttling',
      help_name_aliases=['bandwidth', 'limit', 'nice'],
      help_type='additional_help',
      help_one_line_summary='Throttling gsutil',
      help_text=_DETAILED_HELP_TEXT,
      subcommand_help_text={},
  )
<|endoftext|>


<commit_before>import logging
import subprocess
import sys

import numpy as np

import traci
from rllab.core.serializable import Serializable
from rllab.envs.base import Env
from rllab.envs.base import Step

from cistar.core.util import ensure_dir

"""
This file provides the interface for controlling a SUMO simulation. Using the environment class, you can
start sumo, provide a scenario to specify a configuration and controllers, perform simulation steps, and
reset the simulation to an initial configuration.

SumoEnv must be be Serializable to allow for pickling of the policy.

This class cannot be used as is: you must extend it to implement an action applicator method, and
properties to define the MDP if you choose to use it with RLLab.

"""

COLORS = [(255, 0, 0, 0), (0, 255, 0, 0), (0, 0, 255, 0), (255, 255, 0, 0), (0, 255, 255, 0), (255, 0, 255, 0),
          (255, 255, 255, 0)]

class SumoEnvironment(Env, Serializable):
    def __init__(self, env_params, sumo_binary, sumo_params, scenario):
        """[summary]

        [description]

        Arguments:
            env_params {dictionary} -- [description]
            sumo_binary {string} -- Either "sumo" or "sumo-gui"
            sumo_params {dictionary} -- {"port": {integer} connection to SUMO,
                            "timestep": {float} default=0.01s, SUMO default=1.0s}
            scenario {Scenario} -- @see Scenario; abstraction of the SUMO XML files
                                    which specify the vehicles placed on the net

        Raises:
            ValueError -- Raised if a SUMO port not provided
        """
        Serializable.quick_init(self, locals())

        self.env_params = env_params
        self.sumo_binary = sumo_binary
        self.scenario = scenario
        self.sumo_params = sumo_params
        self.timer = 0  # Represents number of steps taken
        self.vehicles = {}  # Vehicles: Key = Vehicle ID, Value = Dictionary describing the vehicle
        # Initial state: Key = Vehicle ID, Entry = (type_id, route_id, lane_index, lane_pos, speed, pos)
        self.initial_state = {}
        self.ids = []
        self.controlled_ids, self.rl_ids = [], []

        # SUMO Params
        if "port" not in sumo_params:
            raise ValueError("SUMO port not defined")
        else:
            self.port = sumo_params['port']

        if "time_step" in sumo_params:
            self.time_step = sumo_params["time_step"]
        else:
            self.time_step = 0.01  # 0.01 = default time step for our research

        if "emission_path" in sumo_params:
            data_folder = sumo_params['emission_path']
            ensure_dir(data_folder)
            self.emission_out = data_folder + "emission.xml"
        else:
            self.emission_out = None

        # Env Params
        if 'fail-safe' in env_params:
            self.fail_safe = env_params['fail-safe']
        else:
            self.fail_safe = 'instantaneous'

        self._start_sumo()
        self.setup_initial_state()

    def restart_sumo(self, sumo_params, sumo_binary=None):
        traci.close(False)
        if sumo_binary:
            self.sumo_binary = sumo_binary
        if "port" in sumo_params:
            self.port = sumo_params['port']

        if "emission_path" in sumo_params:
            data_folder = sumo_params['emission_path']
            ensure_dir(data_folder)
            self.emission_out = data_folder + "emission.xml"

        self._start_sumo()
        self.setup_initial_state()

    def _start_sumo(self):
        logging.info(" Starting SUMO on port " + str(self.port))
        logging.debug(" Cfg file " + str(self.scenario.cfg))
        logging.debug(" Emission file: " + str(self.emission_out))
        logging.debug(" Time step: " + str(self.time_step))

        # TODO: find a better way to do this
        # Opening the I/O thread to SUMO
        cfg_file = self.scenario.cfg
        if "mode" in self.env_params and self.env_params["mode"] == "ec2":
            cfg_file = "/root/code/rllab/" + cfg_file

        sumo_call = [self.sumo_binary,
                     "-c", cfg_file,
                     "--remote-port", str(self.port),
                     "--step-length", str(self.time_step)]

        if self.emission_out:
            sumo_call.append("--emission-output")
            sumo_call.append(self.emission_out)

        subprocess.Popen(sumo_call, stdout=sys.stdout, stderr=sys.stderr)

        logging.debug(" Initializing TraCI on port " + str(self.port) + "!")

        traci.init(self.port)

        traci.simulationStep()

        # Density = num vehicles / length (in meters)
        # so density in vehicles/km would be 1000 * self.density
        self.density = self.scenario.num_vehicles / self.scenario.net_params['length']

    def setup_initial_state(self):
        """
        Store initial state so that simulation can be reset at the end.
        TODO: Make traci calls as bulk as possible
        Initial state is a dictionary: key = vehicle IDs, value = state describing car
        """

        self.ids = traci.vehicle.getIDList()
        self.controlled_ids.clear()
        self.rl_ids.clear()
        self.vehicles.clear()
        for i in self.ids:
            if traci.vehicle.getTypeID(i) == "rl":
                self.rl_ids.append(i)
            else:
                self.controlled_ids.append(i)

        for veh_id in self.ids:
            vehicle = dict()
            vehicle["id"] = veh_id
            veh_type = traci.vehicle.getTypeID(veh_id)
            vehicle["type"] = veh_type
            vehicle["edge"] = traci.vehicle.getRoadID(veh_id)
            vehicle["position"] = traci.vehicle.getLanePosition(veh_id)
            vehicle["lane"] = traci.vehicle.getLaneIndex(veh_id)
            vehicle["speed"] = traci.vehicle.getSpeed(veh_id)
            vehicle["length"] = traci.vehicle.getLength(veh_id)
            vehicle["max_speed"] = traci.vehicle.getMaxSpeed(veh_id)
            vehicle["distance"] = traci.vehicle.getDistance(veh_id)

            # implement flexibility in controller
            controller_params = self.scenario.type_params[veh_type][1]
            vehicle['controller'] = controller_params[0](veh_id=veh_id, **controller_params[1])

            # initializes lane-changing controller
            lane_changer_params = self.scenario.type_params[veh_type][2]
            if lane_changer_params is not None:
                vehicle['lane_changer'] = lane_changer_params[0](veh_id = veh_id, **lane_changer_params[1])
            else:
                vehicle['lane_changer'] = None

            self.vehicles[veh_id] = vehicle
            traci.vehicle.setSpeedMode(veh_id, 0)

            # Saving initial state
            route_id = traci.vehicle.getRouteID(veh_id)
            pos = traci.vehicle.getPosition(veh_id)

            self.initial_state[veh_id] = (vehicle["type"], route_id, vehicle["lane"],
                                          vehicle["position"], vehicle["speed"], pos)

    def step(self, rl_actions):
        """
        Run one timestep of the environment's dynamics. "Self-driving cars" will
        step forward based on rl_actions, provided by the RL algorithm. Other cars
        will step forward based on their car following model. When end of episode
        is reached, reset() should be called to reset the environment's internal state.
        Input
        -----
        rl_actions : an action provided by the rl algorithm
        Outputs
        -------
        (observation, reward, done, info)
        observation : agent's observation of the current environment
        reward [Float] : amount of reward due to the previous action
        done : a boolean, indicating whether the episode has ended
        info : a dictionary containing other diagnostic information from the previous action
        """
        for veh_id in self.controlled_ids:
            action = self.vehicles[veh_id]['controller'].get_action(self)
            if self.fail_safe == 'instantaneous':
                safe_action = self.vehicles[veh_id]['controller'].get_safe_action_instantaneous(self, action)
            elif self.fail_safe == 'eugene':
                safe_action = self.vehicles[veh_id]['controller'].get_safe_action(self, action)
            else:
                safe_action = action
            if safe_action is None:
                print('')
                print('safe action is None')
                pass
            else:
                self.apply_action(veh_id, action=safe_action)
                # pass

        for index, veh_id in enumerate(self.rl_ids):
            action = rl_actions[index]
            if self.fail_safe == 'instantaneous':
                safe_action = self.vehicles[veh_id]['controller'].get_safe_action_instantaneous(self, action)
            elif self.fail_safe == 'eugene':
                safe_action = self.vehicles[veh_id]['controller'].get_safe_action(self, action)
            else:
                safe_action = action
            self.apply_action(veh_id, action=safe_action)

<<<<<<< HEAD
        self.timer += self.time_step

        # TODO: Turn 10 into a hyperparameter
        # if it's been long enough try and change lanes
        # if self.timer % 10 == 0: # every ten seconds
            # for veh_id in self.controlled_ids:
                # car_type = self.vehicles[veh_id]["type"]
                # newlane = self.scenario.type_params[car_type][2](veh_id, self)

                # newlane = self.vehicles[veh_id]['lane_changer'].get_action(self)
                # traci.vehicle.changeLane(veh_id, newlane, 10000)

        traci.simulationStep()

        speeds = []
=======

        # TODO: Fix Lane Changing
        self.timer += 1
        if self.timer % 100 == 0:
            # if it's been long enough try and change lanes
            for veh_id in self.controlled_ids:
                newlane = self.vehicles[veh_id]['lane_changer'].get_action(self)
                traci.vehicle.changeLane(veh_id, newlane, 10000)

        traci.simulationStep()

>>>>>>> e93b2d8034d4efaaf45e3c0edad91a0beef6c0db
        for veh_id in self.ids:
            self.vehicles[veh_id]["type"] = traci.vehicle.getTypeID(veh_id)
            this_edge = traci.vehicle.getRoadID(veh_id)
            if this_edge is None:
                print('Null edge for vehicle:', veh_id)
            else:
                self.vehicles[veh_id]["edge"] = this_edge
            self.vehicles[veh_id]["position"] = traci.vehicle.getLanePosition(veh_id)
            self.vehicles[veh_id]["lane"] = traci.vehicle.getLaneIndex(veh_id)
            veh_speed = traci.vehicle.getSpeed(veh_id)
            self.vehicles[veh_id]["speed"] = veh_speed
            speeds.append(veh_speed)
            self.vehicles[veh_id]["fuel"] = traci.vehicle.getFuelConsumption(veh_id)
            self.vehicles[veh_id]["distance"] = traci.vehicle.getDistance(veh_id)

        if round(self.timer, 1) == round(self.timer, 3):
            mean_speed = np.mean(speeds)
            print('time:', round(self.timer,1), '; avg speed:', mean_speed, '; flow (cars/km):', mean_speed * self.density * 3600)
            print('')

        # TODO: Can self._state be initialized, saved and updated so that we can
        # exploit numpy speed
        self._state = self.getState()
        reward = self.compute_reward(self._state)
        # TODO: Allow for partial observability
        next_observation = np.copy(self._state)
        if traci.simulation.getEndingTeleportNumber() != 0:
            # Crash has occurred, end rollout
            if self.fail_safe == "None":
                return Step(observation=next_observation, reward=reward, done=True)
            else:
                print("Crash has occurred! Check failsafes!")
        else:
            return Step(observation=next_observation, reward=reward, done=False)

    def reset(self):
        """
        Resets the state of the environment, returning an initial observation.
        Outputs
        -------
        observation : the initial observation of the space. (Initial reward is assumed to be 0.)
        """
        color = COLORS[np.random.choice(len(COLORS))]
        for veh_id in self.ids:
            type_id, route_id, lane_index, lane_pos, speed, pos = self.initial_state[veh_id]

            # clears controller acceleration queue
            if not self.vehicles[veh_id]['type'] == 'rl':
                self.vehicles[veh_id]['controller'].reset_delay(self)

            traci.vehicle.remove(veh_id)
            traci.vehicle.addFull(veh_id, route_id, typeID=str(type_id), departLane=str(lane_index),
                                  departPos=str(lane_pos), departSpeed=str(speed))
            traci.vehicle.setColor(veh_id, color)

        traci.simulationStep()

        # TODO: Replace these traci calls with initial_state accesses
        for veh_id in self.ids:
            traci.vehicle.setSpeedMode(veh_id, 0)
            self.vehicles[veh_id]["type"] = traci.vehicle.getTypeID(veh_id)
            self.vehicles[veh_id]["edge"] = traci.vehicle.getRoadID(veh_id)
            self.vehicles[veh_id]["position"] = traci.vehicle.getLanePosition(veh_id)
            self.vehicles[veh_id]["lane"] = traci.vehicle.getLaneIndex(veh_id)
            self.vehicles[veh_id]["speed"] = traci.vehicle.getSpeed(veh_id)
            self.vehicles[veh_id]["fuel"] = traci.vehicle.getFuelConsumption(veh_id)
            self.vehicles[veh_id]["distance"] = traci.vehicle.getDistance(veh_id)

        self._state = self.getState()
        observation = np.copy(self._state)

        return observation

    def apply_action(self, veh_id, action):
        """
        :param veh_id: {string}
        :param action: as specified by a controller or rllab, usually a scalar value
        """
        raise NotImplementedError

    def getState(self):
        """
        returns the state of the simulation, dependent on the experiment/environment
        :return:
        """
        raise NotImplementedError

    @property
    def action_space(self):
        """
        Returns an action space object
        """
        raise NotImplementedError

    @property
    def observation_space(self):
        """
        Returns an observation space object
        """
        raise NotImplementedError

    def compute_reward(self, state):
        """Reward function for RL.

        Arguments:
            state {Array-type} -- State of all the vehicles in the simulation
        """
        raise NotImplementedError

    def render(self):
        """Description of the state for when verbose mode is on."""
        raise NotImplementedError

    def terminate(self):
        """Closes the TraCI I/O connection. Should be done at end of every experiment.
        Must be in Environment because the environment opens the TraCI connection.
        """
        traci.close()

    def close(self):
        self.terminate()
<commit_msg>fixed merge, whoops<commit_after>import logging
import subprocess
import sys

import numpy as np

import traci
from rllab.core.serializable import Serializable
from rllab.envs.base import Env
from rllab.envs.base import Step

from cistar.core.util import ensure_dir

"""
This file provides the interface for controlling a SUMO simulation. Using the environment class, you can
start sumo, provide a scenario to specify a configuration and controllers, perform simulation steps, and
reset the simulation to an initial configuration.

SumoEnv must be be Serializable to allow for pickling of the policy.

This class cannot be used as is: you must extend it to implement an action applicator method, and
properties to define the MDP if you choose to use it with RLLab.

"""

COLORS = [(255, 0, 0, 0), (0, 255, 0, 0), (0, 0, 255, 0), (255, 255, 0, 0), (0, 255, 255, 0), (255, 0, 255, 0),
          (255, 255, 255, 0)]

class SumoEnvironment(Env, Serializable):
    def __init__(self, env_params, sumo_binary, sumo_params, scenario):
        """[summary]

        [description]

        Arguments:
            env_params {dictionary} -- [description]
            sumo_binary {string} -- Either "sumo" or "sumo-gui"
            sumo_params {dictionary} -- {"port": {integer} connection to SUMO,
                            "timestep": {float} default=0.01s, SUMO default=1.0s}
            scenario {Scenario} -- @see Scenario; abstraction of the SUMO XML files
                                    which specify the vehicles placed on the net

        Raises:
            ValueError -- Raised if a SUMO port not provided
        """
        Serializable.quick_init(self, locals())

        self.env_params = env_params
        self.sumo_binary = sumo_binary
        self.scenario = scenario
        self.sumo_params = sumo_params
        self.timer = 0  # Represents number of steps taken
        self.vehicles = {}  # Vehicles: Key = Vehicle ID, Value = Dictionary describing the vehicle
        # Initial state: Key = Vehicle ID, Entry = (type_id, route_id, lane_index, lane_pos, speed, pos)
        self.initial_state = {}
        self.ids = []
        self.controlled_ids, self.rl_ids = [], []

        # SUMO Params
        if "port" not in sumo_params:
            raise ValueError("SUMO port not defined")
        else:
            self.port = sumo_params['port']

        if "time_step" in sumo_params:
            self.time_step = sumo_params["time_step"]
        else:
            self.time_step = 0.01  # 0.01 = default time step for our research

        if "emission_path" in sumo_params:
            data_folder = sumo_params['emission_path']
            ensure_dir(data_folder)
            self.emission_out = data_folder + "emission.xml"
        else:
            self.emission_out = None

        # Env Params
        if 'fail-safe' in env_params:
            self.fail_safe = env_params['fail-safe']
        else:
            self.fail_safe = 'instantaneous'

        self._start_sumo()
        self.setup_initial_state()

    def restart_sumo(self, sumo_params, sumo_binary=None):
        traci.close(False)
        if sumo_binary:
            self.sumo_binary = sumo_binary
        if "port" in sumo_params:
            self.port = sumo_params['port']

        if "emission_path" in sumo_params:
            data_folder = sumo_params['emission_path']
            ensure_dir(data_folder)
            self.emission_out = data_folder + "emission.xml"

        self._start_sumo()
        self.setup_initial_state()

    def _start_sumo(self):
        logging.info(" Starting SUMO on port " + str(self.port))
        logging.debug(" Cfg file " + str(self.scenario.cfg))
        logging.debug(" Emission file: " + str(self.emission_out))
        logging.debug(" Time step: " + str(self.time_step))

        # TODO: find a better way to do this
        # Opening the I/O thread to SUMO
        cfg_file = self.scenario.cfg
        if "mode" in self.env_params and self.env_params["mode"] == "ec2":
            cfg_file = "/root/code/rllab/" + cfg_file

        sumo_call = [self.sumo_binary,
                     "-c", cfg_file,
                     "--remote-port", str(self.port),
                     "--step-length", str(self.time_step)]

        if self.emission_out:
            sumo_call.append("--emission-output")
            sumo_call.append(self.emission_out)

        subprocess.Popen(sumo_call, stdout=sys.stdout, stderr=sys.stderr)

        logging.debug(" Initializing TraCI on port " + str(self.port) + "!")

        traci.init(self.port)

        traci.simulationStep()

        # Density = num vehicles / length (in meters)
        # so density in vehicles/km would be 1000 * self.density
        self.density = self.scenario.num_vehicles / self.scenario.net_params['length']

    def setup_initial_state(self):
        """
        Store initial state so that simulation can be reset at the end.
        TODO: Make traci calls as bulk as possible
        Initial state is a dictionary: key = vehicle IDs, value = state describing car
        """

        self.ids = traci.vehicle.getIDList()
        self.controlled_ids.clear()
        self.rl_ids.clear()
        self.vehicles.clear()
        for i in self.ids:
            if traci.vehicle.getTypeID(i) == "rl":
                self.rl_ids.append(i)
            else:
                self.controlled_ids.append(i)

        for veh_id in self.ids:
            vehicle = dict()
            vehicle["id"] = veh_id
            veh_type = traci.vehicle.getTypeID(veh_id)
            vehicle["type"] = veh_type
            vehicle["edge"] = traci.vehicle.getRoadID(veh_id)
            vehicle["position"] = traci.vehicle.getLanePosition(veh_id)
            vehicle["lane"] = traci.vehicle.getLaneIndex(veh_id)
            vehicle["speed"] = traci.vehicle.getSpeed(veh_id)
            vehicle["length"] = traci.vehicle.getLength(veh_id)
            vehicle["max_speed"] = traci.vehicle.getMaxSpeed(veh_id)
            vehicle["distance"] = traci.vehicle.getDistance(veh_id)

            # implement flexibility in controller
            controller_params = self.scenario.type_params[veh_type][1]
            vehicle['controller'] = controller_params[0](veh_id=veh_id, **controller_params[1])

            # initializes lane-changing controller
            lane_changer_params = self.scenario.type_params[veh_type][2]
            if lane_changer_params is not None:
                vehicle['lane_changer'] = lane_changer_params[0](veh_id = veh_id, **lane_changer_params[1])
            else:
                vehicle['lane_changer'] = None

            self.vehicles[veh_id] = vehicle
            traci.vehicle.setSpeedMode(veh_id, 0)

            # Saving initial state
            route_id = traci.vehicle.getRouteID(veh_id)
            pos = traci.vehicle.getPosition(veh_id)

            self.initial_state[veh_id] = (vehicle["type"], route_id, vehicle["lane"],
                                          vehicle["position"], vehicle["speed"], pos)

    def step(self, rl_actions):
        """
        Run one timestep of the environment's dynamics. "Self-driving cars" will
        step forward based on rl_actions, provided by the RL algorithm. Other cars
        will step forward based on their car following model. When end of episode
        is reached, reset() should be called to reset the environment's internal state.
        Input
        -----
        rl_actions : an action provided by the rl algorithm
        Outputs
        -------
        (observation, reward, done, info)
        observation : agent's observation of the current environment
        reward [Float] : amount of reward due to the previous action
        done : a boolean, indicating whether the episode has ended
        info : a dictionary containing other diagnostic information from the previous action
        """
        for veh_id in self.controlled_ids:
            action = self.vehicles[veh_id]['controller'].get_action(self)
            if self.fail_safe == 'instantaneous':
                safe_action = self.vehicles[veh_id]['controller'].get_safe_action_instantaneous(self, action)
            elif self.fail_safe == 'eugene':
                safe_action = self.vehicles[veh_id]['controller'].get_safe_action(self, action)
            else:
                safe_action = action
            if safe_action is None:
                print('')
                print('safe action is None')
                pass
            else:
                self.apply_action(veh_id, action=safe_action)
                # pass

        for index, veh_id in enumerate(self.rl_ids):
            action = rl_actions[index]
            if self.fail_safe == 'instantaneous':
                safe_action = self.vehicles[veh_id]['controller'].get_safe_action_instantaneous(self, action)
            elif self.fail_safe == 'eugene':
                safe_action = self.vehicles[veh_id]['controller'].get_safe_action(self, action)
            else:
                safe_action = action
            self.apply_action(veh_id, action=safe_action)

        self.timer += self.time_step

        # TODO: Turn 10 into a hyperparameter
        # if it's been long enough try and change lanes
        # if self.timer % 10 == 0: # every ten seconds
            # for veh_id in self.controlled_ids:
                # car_type = self.vehicles[veh_id]["type"]
                # newlane = self.scenario.type_params[car_type][2](veh_id, self)

                # newlane = self.vehicles[veh_id]['lane_changer'].get_action(self)
                # traci.vehicle.changeLane(veh_id, newlane, 10000)

        traci.simulationStep()

        speeds = []

        for veh_id in self.ids:
            self.vehicles[veh_id]["type"] = traci.vehicle.getTypeID(veh_id)
            this_edge = traci.vehicle.getRoadID(veh_id)
            if this_edge is None:
                print('Null edge for vehicle:', veh_id)
            else:
                self.vehicles[veh_id]["edge"] = this_edge
            self.vehicles[veh_id]["position"] = traci.vehicle.getLanePosition(veh_id)
            self.vehicles[veh_id]["lane"] = traci.vehicle.getLaneIndex(veh_id)
            veh_speed = traci.vehicle.getSpeed(veh_id)
            self.vehicles[veh_id]["speed"] = veh_speed
            speeds.append(veh_speed)
            self.vehicles[veh_id]["fuel"] = traci.vehicle.getFuelConsumption(veh_id)
            self.vehicles[veh_id]["distance"] = traci.vehicle.getDistance(veh_id)

        if round(self.timer, 1) == round(self.timer, 3):
            mean_speed = np.mean(speeds)
            print('time:', round(self.timer,1), '; avg speed:', mean_speed, '; flow (cars/km):', mean_speed * self.density * 3600)
            print('')

        # TODO: Can self._state be initialized, saved and updated so that we can
        # exploit numpy speed
        self._state = self.getState()
        reward = self.compute_reward(self._state)
        # TODO: Allow for partial observability
        next_observation = np.copy(self._state)
        if traci.simulation.getEndingTeleportNumber() != 0:
            # Crash has occurred, end rollout
            if self.fail_safe == "None":
                return Step(observation=next_observation, reward=reward, done=True)
            else:
                print("Crash has occurred! Check failsafes!")
        else:
            return Step(observation=next_observation, reward=reward, done=False)

    def reset(self):
        """
        Resets the state of the environment, returning an initial observation.
        Outputs
        -------
        observation : the initial observation of the space. (Initial reward is assumed to be 0.)
        """
        color = COLORS[np.random.choice(len(COLORS))]
        for veh_id in self.ids:
            type_id, route_id, lane_index, lane_pos, speed, pos = self.initial_state[veh_id]

            # clears controller acceleration queue
            if not self.vehicles[veh_id]['type'] == 'rl':
                self.vehicles[veh_id]['controller'].reset_delay(self)

            traci.vehicle.remove(veh_id)
            traci.vehicle.addFull(veh_id, route_id, typeID=str(type_id), departLane=str(lane_index),
                                  departPos=str(lane_pos), departSpeed=str(speed))
            traci.vehicle.setColor(veh_id, color)

        traci.simulationStep()

        # TODO: Replace these traci calls with initial_state accesses
        for veh_id in self.ids:
            traci.vehicle.setSpeedMode(veh_id, 0)
            self.vehicles[veh_id]["type"] = traci.vehicle.getTypeID(veh_id)
            self.vehicles[veh_id]["edge"] = traci.vehicle.getRoadID(veh_id)
            self.vehicles[veh_id]["position"] = traci.vehicle.getLanePosition(veh_id)
            self.vehicles[veh_id]["lane"] = traci.vehicle.getLaneIndex(veh_id)
            self.vehicles[veh_id]["speed"] = traci.vehicle.getSpeed(veh_id)
            self.vehicles[veh_id]["fuel"] = traci.vehicle.getFuelConsumption(veh_id)
            self.vehicles[veh_id]["distance"] = traci.vehicle.getDistance(veh_id)

        self._state = self.getState()
        observation = np.copy(self._state)

        return observation

    def apply_action(self, veh_id, action):
        """
        :param veh_id: {string}
        :param action: as specified by a controller or rllab, usually a scalar value
        """
        raise NotImplementedError

    def getState(self):
        """
        returns the state of the simulation, dependent on the experiment/environment
        :return:
        """
        raise NotImplementedError

    @property
    def action_space(self):
        """
        Returns an action space object
        """
        raise NotImplementedError

    @property
    def observation_space(self):
        """
        Returns an observation space object
        """
        raise NotImplementedError

    def compute_reward(self, state):
        """Reward function for RL.

        Arguments:
            state {Array-type} -- State of all the vehicles in the simulation
        """
        raise NotImplementedError

    def render(self):
        """Description of the state for when verbose mode is on."""
        raise NotImplementedError

    def terminate(self):
        """Closes the TraCI I/O connection. Should be done at end of every experiment.
        Must be in Environment because the environment opens the TraCI connection.
        """
        traci.close()

    def close(self):
        self.terminate()
<|endoftext|>


<commit_before># Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
{
  'targets': [
    {
      'target_name': 'background',
      'variables': {
        'depends': [
          '../../../../third_party/jstemplate/compiled_resources.gyp:jstemplate',
          '../../../webui/resources/js/cr.js',
          '../../../webui/resources/js/cr/event_target.js',
          '../../../webui/resources/js/cr/ui.js',
          '../../../webui/resources/js/cr/ui/array_data_model.js',
          '../../../webui/resources/js/cr/ui/dialogs.js',
          '../../../webui/resources/js/load_time_data.js',
          '../../../webui/resources/js/util.js',
          '../../file_manager/common/js/util.js',
          '../../file_manager/common/js/async_util.js',
          '../../file_manager/common/js/volume_manager_common.js',
          '../../file_manager/common/js/error_util.js',
          '../../file_manager/common/js/file_type.js',
          '../../file_manager/common/js/metrics_base.js',
          '../../file_manager/common/js/metrics_events.js',
          '../../file_manager/common/js/metrics.js',
          '../../file_manager/background/js/app_window_wrapper.js',
          '../../file_manager/background/js/background_base.js',
          '../../file_manager/background/js/volume_manager.js',
        ],
        'externs': [
          '<(EXTERNS_DIR)/chrome_send.js',
          '<(EXTERNS_DIR)/chrome_extensions.js',
          '<(EXTERNS_DIR)/file_manager_private.js',
          '<(EXTERNS_DIR)/metrics_private.js',
          '../../../../third_party/analytics/externs.js',
          '../../externs/chrome_test.js',
          '../../externs/es6_workaround.js',
          '../../externs/gallery_background.js',
          '../../externs/platform.js',
        ],
      },
      'includes': [
        '../../../../third_party/closure_compiler/compile_js.gypi'
      ],
    },
    {
      'target_name': 'gallery',
      'variables': {
        'depends': [
          '../../../../third_party/jstemplate/compiled_resources.gyp:jstemplate',
          '../../../../third_party/polymer/v1_0/components-chromium/iron-a11y-keys-behavior/iron-a11y-keys-behavior-extracted.js',
          '../../../../third_party/polymer/v1_0/components-chromium/iron-behaviors/iron-button-state-extracted.js',
          '../../../../third_party/polymer/v1_0/components-chromium/iron-behaviors/iron-control-state-extracted.js',
          '../../../../third_party/polymer/v1_0/components-chromium/iron-form-element-behavior/iron-form-element-behavior-extracted.js',
          '../../../../third_party/polymer/v1_0/components-chromium/paper-behaviors/paper-inky-focus-behavior-extracted.js',
          '../../../../third_party/polymer/v1_0/components-chromium/paper-checkbox/paper-checkbox-extracted.js',
          '../../../../third_party/polymer/v1_0/components-chromium/paper-input/paper-input-behavior-extracted.js',
          '../../../../third_party/polymer/v1_0/components-chromium/paper-input/paper-input-container-extracted.js',
          '../../../../third_party/polymer/v1_0/components-chromium/paper-input/paper-input-extracted.js',
          '../../../webui/resources/js/util.js',
          '../../../webui/resources/js/event_tracker.js',
          '../../../webui/resources/js/load_time_data.js',
          '../../../webui/resources/js/cr.js',
          '../../../webui/resources/js/cr/ui.js',
          '../../../webui/resources/js/cr/event_target.js',
          '../../../webui/resources/js/cr/ui/touch_handler.js',
          '../../../webui/resources/js/cr/ui/array_data_model.js',
          '../../../webui/resources/js/cr/ui/dialogs.js',
          '../../../webui/resources/js/cr/ui/list_item.js',
          '../../../webui/resources/js/cr/ui/list_selection_model.js',
          '../../../webui/resources/js/cr/ui/list_single_selection_model.js',
          '../../../webui/resources/js/cr/ui/list_selection_controller.js',
          '../../../webui/resources/js/cr/ui/list.js',
          '../../../webui/resources/js/cr/ui/grid.js',
          '../../../webui/resources/js/compiled_resources.gyp:i18n_template_no_process',
          '../../file_manager/common/js/volume_manager_common.js',
          '../../file_manager/common/js/lru_cache.js',
          '../../file_manager/common/js/async_util.js',
          '../../file_manager/common/js/file_type.js',
          '../../file_manager/common/js/util.js',
          '../../file_manager/common/js/metrics_base.js',
          '../../file_manager/common/js/metrics_events.js',
          '../../file_manager/common/js/metrics.js',
          '../../file_manager/foreground/js/metrics_start.js',
          '../../file_manager/foreground/js/metadata/content_metadata_provider.js',
          '../../file_manager/foreground/js/metadata/exif_constants.js',
          '../../file_manager/foreground/js/metadata/external_metadata_provider.js',
          '../../file_manager/foreground/js/metadata/file_system_metadata_provider.js',
          '../../file_manager/foreground/js/metadata/metadata_cache_item.js',
          '../../file_manager/foreground/js/metadata/metadata_cache_set.js',
          '../../file_manager/foreground/js/metadata/metadata_item.js',
          '../../file_manager/foreground/js/metadata/metadata_model.js',
          '../../file_manager/foreground/js/metadata/multi_metadata_provider.js',
          '../../file_manager/foreground/js/metadata/new_metadata_provider.js',
          '../../file_manager/foreground/js/metadata/thumbnail_model.js',
          '../../file_manager/foreground/js/share_client.js',
          '../../file_manager/foreground/js/thumbnail_loader.js',
          '../../file_manager/foreground/js/ui/file_manager_dialog_base.js',
          '../../file_manager/foreground/js/ui/share_dialog.js',
          '../../file_manager/foreground/js/volume_manager_wrapper.js',
          '../../file_manager/background/js/volume_manager.js',
          '../../image_loader/image_loader_client.js',
          './image_editor/commands.js',
          './image_editor/exif_encoder.js',
          './image_editor/filter.js',
          './image_editor/image_adjust.js',
          './image_editor/image_buffer.js',
          './image_editor/image_editor.js',
          './image_editor/image_encoder.js',
          './image_editor/image_transform.js',
          './image_editor/image_util.js',
          './image_editor/image_view.js',
          './image_editor/viewport.js',
          './chromevox_state_watcher.js',
          './dimmable_ui_controller.js',
          './entry_list_watcher.js',
          './error_banner.js',
          './gallery_data_model.js',
          './gallery_item.js',
          './gallery_util.js',
          './ribbon.js',
          './slide_mode.js',
          './thumbnail_mode.js',
        ],
        'externs': [
          '<(EXTERNS_DIR)/chrome_send.js',
          '<(EXTERNS_DIR)/chrome_extensions.js',
          '<(EXTERNS_DIR)/file_manager_private.js',
          '<(EXTERNS_DIR)/metrics_private.js',
          '../../../../third_party/analytics/externs.js',
          '../../externs/chrome_test.js',
          '../../externs/es6_workaround.js',
          '../../externs/exif_entry.js',
          '../../externs/files_elements.js',
          '../../externs/gallery_foreground.js',
          '../../externs/paper_elements.js',
          '../../externs/platform.js',
          '../../externs/webview_tag.js',
        ],
      },
      'includes': [
        '../../../../third_party/closure_compiler/compile_js.gypi'
      ],
    }
  ],
}
<commit_msg>Fix file_manager compiled_resources for latest Polymer update<commit_after># Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
{
  'targets': [
    {
      'target_name': 'background',
      'variables': {
        'depends': [
          '../../../../third_party/jstemplate/compiled_resources.gyp:jstemplate',
          '../../../webui/resources/js/cr.js',
          '../../../webui/resources/js/cr/event_target.js',
          '../../../webui/resources/js/cr/ui.js',
          '../../../webui/resources/js/cr/ui/array_data_model.js',
          '../../../webui/resources/js/cr/ui/dialogs.js',
          '../../../webui/resources/js/load_time_data.js',
          '../../../webui/resources/js/util.js',
          '../../file_manager/common/js/util.js',
          '../../file_manager/common/js/async_util.js',
          '../../file_manager/common/js/volume_manager_common.js',
          '../../file_manager/common/js/error_util.js',
          '../../file_manager/common/js/file_type.js',
          '../../file_manager/common/js/metrics_base.js',
          '../../file_manager/common/js/metrics_events.js',
          '../../file_manager/common/js/metrics.js',
          '../../file_manager/background/js/app_window_wrapper.js',
          '../../file_manager/background/js/background_base.js',
          '../../file_manager/background/js/volume_manager.js',
        ],
        'externs': [
          '<(EXTERNS_DIR)/chrome_send.js',
          '<(EXTERNS_DIR)/chrome_extensions.js',
          '<(EXTERNS_DIR)/file_manager_private.js',
          '<(EXTERNS_DIR)/metrics_private.js',
          '../../../../third_party/analytics/externs.js',
          '../../externs/chrome_test.js',
          '../../externs/es6_workaround.js',
          '../../externs/gallery_background.js',
          '../../externs/platform.js',
        ],
      },
      'includes': [
        '../../../../third_party/closure_compiler/compile_js.gypi'
      ],
    },
    {
      'target_name': 'gallery',
      'variables': {
        'depends': [
          '../../../../third_party/jstemplate/compiled_resources.gyp:jstemplate',
          '../../../../third_party/polymer/v1_0/components-chromium/iron-a11y-keys-behavior/iron-a11y-keys-behavior-extracted.js',
          '../../../../third_party/polymer/v1_0/components-chromium/iron-behaviors/iron-button-state-extracted.js',
          '../../../../third_party/polymer/v1_0/components-chromium/iron-behaviors/iron-control-state-extracted.js',
          '../../../../third_party/polymer/v1_0/components-chromium/iron-checked-element-behavior/iron-checked-element-behavior-extracted.js',
          '../../../../third_party/polymer/v1_0/components-chromium/iron-form-element-behavior/iron-form-element-behavior-extracted.js',
          '../../../../third_party/polymer/v1_0/components-chromium/iron-validatable-behavior/iron-validatable-behavior-extracted.js',
          '../../../../third_party/polymer/v1_0/components-chromium/paper-behaviors/paper-inky-focus-behavior-extracted.js',
          '../../../../third_party/polymer/v1_0/components-chromium/paper-checkbox/paper-checkbox-extracted.js',
          '../../../../third_party/polymer/v1_0/components-chromium/paper-input/paper-input-behavior-extracted.js',
          '../../../../third_party/polymer/v1_0/components-chromium/paper-input/paper-input-container-extracted.js',
          '../../../../third_party/polymer/v1_0/components-chromium/paper-input/paper-input-extracted.js',
          '../../../webui/resources/js/util.js',
          '../../../webui/resources/js/event_tracker.js',
          '../../../webui/resources/js/load_time_data.js',
          '../../../webui/resources/js/cr.js',
          '../../../webui/resources/js/cr/ui.js',
          '../../../webui/resources/js/cr/event_target.js',
          '../../../webui/resources/js/cr/ui/touch_handler.js',
          '../../../webui/resources/js/cr/ui/array_data_model.js',
          '../../../webui/resources/js/cr/ui/dialogs.js',
          '../../../webui/resources/js/cr/ui/list_item.js',
          '../../../webui/resources/js/cr/ui/list_selection_model.js',
          '../../../webui/resources/js/cr/ui/list_single_selection_model.js',
          '../../../webui/resources/js/cr/ui/list_selection_controller.js',
          '../../../webui/resources/js/cr/ui/list.js',
          '../../../webui/resources/js/cr/ui/grid.js',
          '../../../webui/resources/js/compiled_resources.gyp:i18n_template_no_process',
          '../../file_manager/common/js/volume_manager_common.js',
          '../../file_manager/common/js/lru_cache.js',
          '../../file_manager/common/js/async_util.js',
          '../../file_manager/common/js/file_type.js',
          '../../file_manager/common/js/util.js',
          '../../file_manager/common/js/metrics_base.js',
          '../../file_manager/common/js/metrics_events.js',
          '../../file_manager/common/js/metrics.js',
          '../../file_manager/foreground/js/metrics_start.js',
          '../../file_manager/foreground/js/metadata/content_metadata_provider.js',
          '../../file_manager/foreground/js/metadata/exif_constants.js',
          '../../file_manager/foreground/js/metadata/external_metadata_provider.js',
          '../../file_manager/foreground/js/metadata/file_system_metadata_provider.js',
          '../../file_manager/foreground/js/metadata/metadata_cache_item.js',
          '../../file_manager/foreground/js/metadata/metadata_cache_set.js',
          '../../file_manager/foreground/js/metadata/metadata_item.js',
          '../../file_manager/foreground/js/metadata/metadata_model.js',
          '../../file_manager/foreground/js/metadata/multi_metadata_provider.js',
          '../../file_manager/foreground/js/metadata/new_metadata_provider.js',
          '../../file_manager/foreground/js/metadata/thumbnail_model.js',
          '../../file_manager/foreground/js/share_client.js',
          '../../file_manager/foreground/js/thumbnail_loader.js',
          '../../file_manager/foreground/js/ui/file_manager_dialog_base.js',
          '../../file_manager/foreground/js/ui/share_dialog.js',
          '../../file_manager/foreground/js/volume_manager_wrapper.js',
          '../../file_manager/background/js/volume_manager.js',
          '../../image_loader/image_loader_client.js',
          './image_editor/commands.js',
          './image_editor/exif_encoder.js',
          './image_editor/filter.js',
          './image_editor/image_adjust.js',
          './image_editor/image_buffer.js',
          './image_editor/image_editor.js',
          './image_editor/image_encoder.js',
          './image_editor/image_transform.js',
          './image_editor/image_util.js',
          './image_editor/image_view.js',
          './image_editor/viewport.js',
          './chromevox_state_watcher.js',
          './dimmable_ui_controller.js',
          './entry_list_watcher.js',
          './error_banner.js',
          './gallery_data_model.js',
          './gallery_item.js',
          './gallery_util.js',
          './ribbon.js',
          './slide_mode.js',
          './thumbnail_mode.js',
        ],
        'externs': [
          '<(EXTERNS_DIR)/chrome_send.js',
          '<(EXTERNS_DIR)/chrome_extensions.js',
          '<(EXTERNS_DIR)/file_manager_private.js',
          '<(EXTERNS_DIR)/metrics_private.js',
          '../../../../third_party/analytics/externs.js',
          '../../externs/chrome_test.js',
          '../../externs/es6_workaround.js',
          '../../externs/exif_entry.js',
          '../../externs/files_elements.js',
          '../../externs/gallery_foreground.js',
          '../../externs/paper_elements.js',
          '../../externs/platform.js',
          '../../externs/webview_tag.js',
        ],
      },
      'includes': [
        '../../../../third_party/closure_compiler/compile_js.gypi'
      ],
    }
  ],
}
<|endoftext|>