Exemple #1
0
def main(argv = None):
  """Main function.

  Args:
    argv: Sequence of command line arguments.
  """
  if argv is None:
    argv = flags.FLAGS(sys.argv)

  if FLAGS.time:
    start_time = time.time()

  suffixes = ['.js']
  if FLAGS.additional_extensions:
    suffixes += ['.%s' % ext for ext in FLAGS.additional_extensions]
  if FLAGS.check_html:
    suffixes += ['.html', '.htm']
  files = fileflags.GetFileList(argv, 'JavaScript', suffixes)

  error_handler = None
  if FLAGS.unix_mode:
    error_handler = errorprinter.ErrorPrinter(errors.NEW_ERRORS)
    error_handler.SetFormat(errorprinter.UNIX_FORMAT)

  runner = checker.GJsLintRunner()
  result = runner.Run(files, error_handler)
  result.PrintSummary()

  exit_code = 0
  if result.HasOldErrors():
    exit_code += 1
  if result.HasNewErrors():
    exit_code += 2

  if exit_code:
    if FLAGS.summary:
      result.PrintFileSummary()

    if FLAGS.beep:
      # Make a beep noise.
      sys.stdout.write(chr(7))

    # Write out instructions for using fixjsstyle script to fix some of the
    # reported errors.
    fix_args = []
    for flag in sys.argv[1:]:
      for f in GJSLINT_ONLY_FLAGS:
        if flag.startswith(f):
          break
      else:
        fix_args.append(flag)

    print """
Some of the errors reported by GJsLint may be auto-fixable using the script
fixjsstyle. Please double check any changes it makes and report any bugs. The
script can be run by executing:

fixjsstyle %s """ % ' '.join(fix_args)

  if FLAGS.time:
    print 'Done in %s.' % FormatTime(time.time() - start_time)

  sys.exit(exit_code)
def main(argv=None):
    """
        Main function.

        Args:
          argv: Sequence of command line arguments.
    """
    if argv is None:
        argv = flags.FLAGS(sys.argv)

    if FLAGS.time:
        start_time = time.time()

    suffixes = ['.js']
    if FLAGS.additional_extensions:
        suffixes += ['.%s' % ext for ext in FLAGS.additional_extensions]
    if FLAGS.check_html:
        suffixes += ['.html', '.htm']
    paths = fileflags.GetFileList(argv, 'JavaScript', suffixes)

    if FLAGS.multiprocess:
        records_iter = _MultiprocessCheckPaths(paths)
    else:
        records_iter = _CheckPaths(paths)

    exit_code = 0
    message = ''

    records_iter, records_iter_copy = itertools.tee(records_iter, 2)
    message = _PrintErrorRecords(records_iter_copy)

    error_records = list(records_iter)
    _PrintSummary(paths, error_records)

    # If there are any errors
    if error_records:
        exit_code += 1

    # If there are any new errors
    if [r for r in error_records if r.new_error]:
        exit_code += 2

    if exit_code:
        if FLAGS.summary:
            _PrintFileSummary(paths, error_records)

        if FLAGS.beep:
            # Make a beep noise.
            sys.stdout.write(chr(7))

        # Write out instructions for using fixjsstyle script to fix some of the
        # reported errors.
        fix_args = []
        for flag in sys.argv[1:]:
            for f in GJSLINT_ONLY_FLAGS:
                if flag.startswith(f):
                    break
            else:
                fix_args.append(flag)

        fixjsstyle_path = str(os.path.dirname(os.path.realpath(__file__))) + \
                          os.sep + 'fixjsstyle.py'
        message += """
        TRY:

        """ + fixjsstyle_path + """ %s

        """ % ' '.join(fix_args)
        exit_code = message

    if FLAGS.time:
        print 'Done in %s.' % _FormatTime(time.time() - start_time)

    sys.exit(exit_code)
Exemple #3
0
    "shape beyond the first dimension, and they will be combined"
    " in alphabetical order.")
gflags.DEFINE_string("name", "mat",
                     "The variable name used in the output matlab file.")
FLAGS = gflags.FLAGS


def convert(files):
    files.sort()
    if len(files) == 0:
        return
    if FLAGS.output != "":
        # combine features
        mat = np.vstack([np.load(f) for f in files])
        output = FLAGS.output
        if not output.endswith('.mat'):
            output += '.mat'
        io.savemat(output, {FLAGS.name: mat}, oned_as='column')
    else:
        for filename in files:
            mat = np.load(filename)
            output = filename
            if output.endswith('.npy'):
                output = output[:-4]
            output += '.mat'
            io.savemat(output, {FLAGS.name: mat}, oned_as='column')


if __name__ == "__main__":
    files = gflags.FLAGS(sys.argv)[1:]
    convert(files)
Exemple #4
0
def main(argv):
    try:
        argv = gflags.FLAGS(argv)  # parse flags
    except gflags.FlagsError, e:
        print '%s\\nUsage: %s ARGS\\n%s' % (e, sys.argv[0], gflags.FLAGS)
        sys.exit(1)
# limitations under the License.

"""Medium tests for the gpylint auto-fixer."""

__author__ = '[email protected] (Robby Walker)'

import StringIO

import gflags as flags
import unittest as googletest
from closure_linter import error_fixer
from closure_linter import runner


_RESOURCE_PREFIX = 'closure_linter/fixjsstyle_testdata'
flags.FLAGS([])


class FixJsStyleTest(googletest.TestCase):
  """Test case to for gjslint auto-fixing."""

  def setUp(self):
    flags.FLAGS.dot_on_next_line = True
    flags.FLAGS.check_trailing_comma = False
    flags.FLAGS.strict = True
    flags.FLAGS.limited_doc_files = ('dummy.js', 'externs.js')
    flags.FLAGS.closurized_namespaces = ('goog', 'dummy')

  def tearDown(self):
    flags.FLAGS.dot_on_next_line = False
Exemple #6
0
def main():
    """Entry point."""
    gflags.FLAGS(sys.argv)
    frame_populator = FramePopulator(gflags.FLAGS)
    frame_populator.process_record_file()
    return
Exemple #7
0
def main():
    """Entry point."""
    gflags.FLAGS(sys.argv)
    process_record_file(gflags.FLAGS)
    return
Exemple #8
0
def main(argv=None):
    """Main function.

  Args:
    argv: Sequence of command line arguments.
  """
    if argv is None:
        argv = flags.FLAGS(sys.argv)

    if FLAGS.time:
        start_time = time.time()

    suffixes = ['.js']
    if FLAGS.additional_extensions:
        suffixes += ['.%s' % ext for ext in FLAGS.additional_extensions]
    if FLAGS.check_html:
        suffixes += ['.html', '.htm']
    paths = fileflags.GetFileList(argv, 'JavaScript', suffixes)

    if FLAGS.multiprocess:
        records_iter = _MultiprocessCheckPaths(paths)
    else:
        records_iter = _CheckPaths(paths)

    records_iter, records_iter_copy = itertools.tee(records_iter, 2)
    _PrintErrorRecords(records_iter_copy)

    error_records = list(records_iter)
    _PrintSummary(paths, error_records)

    exit_code = 0

    # If there are any errors
    if error_records:
        exit_code += 1

    # If there are any new errors
    if [r for r in error_records if r.new_error]:
        exit_code += 2

    if exit_code:
        if FLAGS.summary:
            _PrintFileSummary(paths, error_records)

        if FLAGS.beep:
            # Make a beep noise.
            sys.stdout.write(chr(7))

        # Write out instructions for using fixjsstyle script to fix some of the
        # reported errors.
        fix_args = []
        for flag in sys.argv[1:]:
            for f in GJSLINT_ONLY_FLAGS:
                if flag.startswith(f):
                    break
            else:
                fix_args.append(flag)

        print """
Some of the errors reported by GJsLint may be auto-fixable using the script
fixjsstyle. Please double check any changes it makes and report any bugs. The
script can be run by executing:

fixjsstyle %s """ % ' '.join(fix_args)

    if FLAGS.time:
        print 'Done in %s.' % _FormatTime(time.time() - start_time)

    sys.exit(exit_code)
Exemple #9
0
def corrupt():
    """
    Corrupt clean dataset by noise type and rate
    :return:
    """
    gflags.FLAGS(sys.argv)
    # dataset name
    dataset = gflags.FLAGS.dataset
    # noise type
    noise_type = gflags.FLAGS.noise_type
    # noise rate
    noise_rate = gflags.FLAGS.noise_rate
    # class number
    class_num = dataset2classnum[dataset]
    # data path
    data_path = "./data/%s/" % dataset
    if not os.path.exists(data_path):
        os.makedirs(data_path)
    print("dataset: %s, noise_type: %s, noise_rate: %f" %
          (dataset, noise_type, noise_rate))
    if noise_type == "SYMMETRY":
        c_m = noise_rate / (class_num - 1) * np.ones((class_num, class_num))
        for c in xrange(class_num):
            c_m[c][c] = 1 - noise_rate
    elif noise_type == "PAIR":
        c_m = np.zeros((class_num, class_num))
        for c in xrange(class_num):
            c_m[c][c] = 1 - noise_rate
            c_m[c][(c + 1) % class_num] = noise_rate

    print(c_m)
    items = list()
    for line in open(data_path + "ori_data.txt"):
        item = json.loads(line)
        item["ori_id"] = copy.deepcopy(item["id"])
        items.append(item)
    random.shuffle(items)

    m = int(round(noise_rate * len(items)))
    flipper = np.random.RandomState(0)
    for item in items:
        i = int(item["id"][0])
        flipped = flipper.multinomial(1, c_m[i, :], 1)[0]
        _i = np.where(flipped == 1)[0][0]
        #print i, _i
        _id = str(_i)
        item["id"][0] = _id

    cnt = 0
    predix_dir = data_path + str(noise_type) + "_%02d" % int(100 * noise_rate)
    if not os.path.exists(predix_dir):
        os.mkdir(predix_dir)
    with open(predix_dir + "_data.txt", "wb") as f:
        for item in items:
            if item["id"][0] != item["ori_id"][0]:
                item["id"].append("1")
                cnt += 1
            else:
                item["id"].append("0")
            f.write(json.dumps(item) + "\n")
        f.close()
    print("noise ratio:", round(100.0 * cnt / len(items), 2))
    if not os.path.exists(predix_dir):
        os.mkdirs(predix_dir)
    creat_db_txt(predix_dir + "_data.txt", predix_dir + "/train.txt", "train")
    creat_db_txt(data_path + "validation_test.txt", predix_dir + "/test.txt",
                 "test")
Exemple #10
0
    f = open(
        log_folder + str(num_robots) + '_' + environment + '_' +
        str(int(comm_model.COMM_RANGE)) + '_' +
        gflags.FLAGS.point_selection_policy + '.dat', "wb")
    pickle.dump((errors, variances_all, times_all), f)
    f.close()


if __name__ == '__main__':

    os.chdir("/home/andrea/catkin_ws/src/strategy/")

    # Parsing of gflags.
    try:
        sys.argv = gflags.FLAGS(sys.argv)  # parse flags
    except gflags.FlagsError, e:
        print '%s\\nUsage: %s ARGS\\n%s' % (e, sys.argv[0], gflags.FLAGS)
        sys.exit(1)
    if gflags.FLAGS.task == 'evaluate':
        evaluate(gflags.FLAGS.environment, gflags.FLAGS.num_robots,
                 gflags.FLAGS.num_runs, gflags.FLAGS.is_simulation,
                 gflags.FLAGS.communication_model_path,
                 gflags.FLAGS.granularity, gflags.FLAGS.mission_duration,
                 gflags.FLAGS.plot_communication_map,
                 (gflags.FLAGS.fixed_robot_x, gflags.FLAGS.fixed_robot_y),
                 gflags.FLAGS.test_set_size, gflags.FLAGS.log_folder)
    elif gflags.FLAGS.task == 'plot':
        plot(gflags.FLAGS.environment, gflags.FLAGS.num_robots,
             gflags.FLAGS.communication_model_path, gflags.FLAGS.granularity,
             gflags.FLAGS.mission_duration)
Exemple #11
0
    def GetSwitchChips(self):
        return self._yaml['switch_chips']

    # TODO: Split this section of network.yaml into its own file.
    def GetSwitches(self):
        return self._yaml['switches']


def ParseGenerationFlags(argv):
    """Use gflags to parse arguments specific to network.yaml code generation."""

    gflags.DEFINE_string('autogen_root', makani.HOME,
                         'Root of the source tree for the output files.')

    gflags.DEFINE_string('output_dir', '.',
                         'Full path to the directory for output files.')

    gflags.DEFINE_string(
        'network_file', None,
        'Full path to the yaml file that describes the network.')

    try:
        argv = gflags.FLAGS(argv)
    except gflags.FlagsError, e:
        sys.stderr.write('\nError: %s\n\nUsage: %s ARGS\n%s\n' %
                         (e, argv[0], gflags.FLAGS))
        sys.exit(1)

    argv = gflags.FLAGS(argv)
    return gflags.FLAGS, argv
Exemple #12
0
def main():
    """Entry point."""
    gflags.FLAGS(sys.argv)
    with rosbag.Bag(gflags.FLAGS.input_bag) as bag:
        process_bag(bag, gflags.FLAGS)
Exemple #13
0
def main():
    gflags.FLAGS(sys.argv)
    SensorStreamer.CreateAndServeForever(
        [SensorSet.FromSpec(spec) for spec in FLAGS.sensors], FLAGS.port)
Exemple #14
0
def main():
    gflags.FLAGS(sys.argv)
    print('a {} flower'.format(gflags.FLAGS.color))
Exemple #15
0
def test():
    image_dir = root_dir + "data/LFW/"

    image_files = set()
    pairs = list()
    for k, line in enumerate(open(image_dir + "pairs.txt")):
        item = line.strip().split()
        item[0] = image_dir + "images/" + item[0]
        item[1] = image_dir + "images/" + item[1]
        assert len(item) == 3
        pairs.append(tuple(item))
        image_files.add(item[0])
        image_files.add(item[1])

    feature_file = image_dir + "feature_%d.pkl" % layer_num
    if not os.path.exists(feature_file):
        gflags.FLAGS(sys.argv)
        model_dir = gflags.FLAGS.model_dir + "/"
        featurer = Featurer(deploy_prototxt=model_dir + "deploy.prototxt", \
                            model_file=model_dir + "train.caffemodel", \
                            mean_file=model_dir + "mean.binaryproto", \
                            ratio_file=model_dir + "ratio.txt", \
                            label_file=model_dir + "label.txt", \
                            device_id=gflags.FLAGS.device_id, \
                            ratio=gflags.FLAGS.ratio, \
                            scale=gflags.FLAGS.scale, \
                            resize_height=gflags.FLAGS.resize_height, \
                            resize_width=gflags.FLAGS.resize_width, \
                            raw_scale=gflags.FLAGS.raw_scale, \
                            input_scale=gflags.FLAGS.input_scale, \
                            gray=gflags.FLAGS.gray, \
                            oversample=gflags.FLAGS.oversample, \
                            feature_layer_names=eval(gflags.FLAGS.feature_layer_names))
        features = dict()
        for k, image_file in enumerate(image_files):
            if not features.has_key(image_file):
                features[image_file.replace(
                    root_dir, "")] = featurer.test(image_file=image_file)
            print "processed:", k
            sys.stdout.flush()
        cPickle.dump(features, open(feature_file, "wb"))
    else:
        features = cPickle.load(open(feature_file, "rb"))

    sims = list()
    threds = list()
    for pair in pairs:
        image_file1, image_file2, tag = pair[:3]
        # person1
        feature1 = features[image_file1.replace(root_dir, "")]
        # person2
        feature2 = features[image_file2.replace(root_dir, "")]
        # sim
        #sim = cos_sim(feature1, feature2)
        sim = norml2_sim(feature1, feature2)
        sims.append((sim, int(tag), image_file1, image_file2))
        threds.append(sim)

    best_accuracy = 0.0
    best_thred = 0.0
    with open(image_dir + "roc_%d.txt" % layer_num, "wb") as f:
        for thred in sorted(threds):
            tp = 0
            fn = 0
            tn = 0
            fp = 0
            for sim, tag, image_file1, image_file2 in sims:
                if tag == 1:
                    if sim >= thred:
                        tp += 1
                    else:
                        fn += 1
                        #print "fp", image_file1, image_file2
                if tag == 0:
                    if sim < thred:
                        tn += 1
                    else:
                        fp += 1
                        #print "fn", image_file1, image_file2
            tpr = 1.0 * tp / max(tp + fn, 1)
            fnr = 1.0 * fn / max(tp + fn, 1)
            tnr = 1.0 * tn / max(tn + fp, 1)
            fpr = 1.0 * fp / max(tn + fp, 1)
            accuracy = 1.0 * (tp + tn) / (tp + fp + tn + fn)
            if accuracy > best_accuracy:
                best_accuracy = accuracy
                best_thred = thred
            f.write("%.6f %.6f\n" % (tpr, fpr))
            #print thred, (tp + fp + tn + fn), tpr, tnr, accuracy
        print "best:", len(pairs), best_thred, best_accuracy
Exemple #16
0
def parse_args(args):  # pragma: no cover
    try:
        flags.FLAGS(args)  # Parses flags. Any remaining args are unused.
    except flags.FlagsError, err:
        logging.error('%s\nUsage: %s ARGS\n%s', err, sys.argv[0], flags.FLAGS)
        sys.exit(1)
Exemple #17
0
from __future__ import absolute_import

from copy import deepcopy
import gflags
import unittest

from causeway.because_data import CausalityStandoffReader
from causeway.because_data.iaa import CausalityMetrics
from nlpypline.tests import get_sentences_from_file
from nlpypline.util.metrics import ClassificationMetrics, f1

gflags.FLAGS([]) # Prevent UnparsedFlagAccessError


class CausalityMetricsTest(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        gflags.FLAGS.metrics_log_raw_counts = True

    @staticmethod
    def _get_sentences_with_swapped_args(sentences):
        swapped_sentences = []
        for sentence in sentences:
            swapped_sentence = deepcopy(sentence)
            for instance in swapped_sentence.causation_instances:
                instance.cause, instance.effect = (
                    instance.effect, instance.cause)
            swapped_sentences.append(swapped_sentence)
        return swapped_sentences

    def _test_metrics(
Exemple #18
0
def main(argv=None):
    """Main function.

  Args:
    argv: Sequence of command line arguments.
  """
    if argv is None:
        argv = flags.FLAGS(sys.argv)

    if FLAGS.time:
        start_time = time.time()

    # Emacs sets the environment variable INSIDE_EMACS in the subshell.
    # Request Unix mode as emacs will expect output to be in Unix format
    # for integration.
    # See https://www.gnu.org/software/emacs/manual/html_node/emacs/
    # Interactive-Shell.html
    if 'INSIDE_EMACS' in os.environ:
        FLAGS.unix_mode = True

    suffixes = ['.js']
    if FLAGS.additional_extensions:
        suffixes += ['.%s' % ext for ext in FLAGS.additional_extensions]
    if FLAGS.check_html:
        suffixes += ['.html', '.htm']
    paths = fileflags.GetFileList(argv, 'JavaScript', suffixes)

    if FLAGS.multiprocess:
        records_iter = _MultiprocessCheckPaths(paths)
    else:
        records_iter = _CheckPaths(paths)

    records_iter, records_iter_copy = itertools.tee(records_iter, 2)
    _PrintErrorRecords(records_iter_copy)

    error_records = list(records_iter)
    _PrintSummary(paths, error_records)

    exit_code = 0

    # If there are any errors
    if error_records:
        exit_code += 1

    # If there are any new errors
    if [r for r in error_records if r.new_error]:
        exit_code += 2

    if exit_code:
        if FLAGS.summary:
            _PrintFileSummary(paths, error_records)

        if FLAGS.beep:
            # Make a beep noise.
            sys.stdout.write(chr(7))

        # Write out instructions for using fixjsstyle script to fix some of the
        # reported errors.
        fix_args = []
        for flag in sys.argv[1:]:
            for f in GJSLINT_ONLY_FLAGS:
                if flag.startswith(f):
                    break
            else:
                fix_args.append(flag)

        if not FLAGS.quiet:
            print """
Some of the errors reported by GJsLint may be auto-fixable using the script
fixjsstyle. Please double check any changes it makes and report any bugs. The
script can be run by executing:

fixjsstyle %s """ % ' '.join(fix_args)

    if FLAGS.time:
        print 'Done in %s.' % _FormatTime(time.time() - start_time)

    sys.exit(exit_code)
Exemple #19
0
def test():
    image_dir = root_dir + "data/YTF/"

    # pairs
    image_dirs = set()
    pairs = list()
    for k, line in enumerate(open(image_dir + "pairs.txt")):
        item = line.strip().split()[2:]
        item[0] = image_dir + "images/" + item[0] + "/"
        item[1] = image_dir + "images/" + item[1] + "/"
        assert len(item) == 3
        pairs.append(tuple(item))
        image_dirs.add(item[0])
        image_dirs.add(item[1])

    # features
    feature_file = image_dir + "feature_%d.pkl" % layer_num
    if not os.path.exists(feature_file):
        gflags.FLAGS(sys.argv)
        model_dir = gflags.FLAGS.model_dir + "/"
        featurer = Featurer(deploy_prototxt=model_dir + "deploy.prototxt", \
                            model_file=model_dir + "train.caffemodel", \
                            mean_file=model_dir + "mean.binaryproto", \
                            ratio_file=model_dir + "ratio.txt", \
                            label_file=model_dir + "label.txt", \
                            device_id=gflags.FLAGS.device_id, \
                            ratio=gflags.FLAGS.ratio, \
                            scale=gflags.FLAGS.scale, \
                            resize_height=gflags.FLAGS.resize_height, \
                            resize_width=gflags.FLAGS.resize_width, \
                            raw_scale=gflags.FLAGS.raw_scale, \
                            input_scale=gflags.FLAGS.input_scale, \
                            gray=gflags.FLAGS.gray, \
                            oversample=gflags.FLAGS.oversample, \
                            feature_layer_names=eval(gflags.FLAGS.feature_layer_names))
        features = dict()
        for k, image_dir in enumerate(image_dirs):
            if not features.has_key(image_dir):
                features[image_dir.replace(root_dir, "")] = get_feature(
                    featurer, image_dir)
            print "processed:", k
            sys.stdout.flush()
        cPickle.dump(features, open(feature_file, "wb"))
    else:
        features = cPickle.load(open(feature_file, "rb"))

    # sims
    sims = list()
    for k, pair in enumerate(pairs):
        image_dir1, image_dir2, tag = pair[:3]
        # person1
        feature1 = features[image_dir1.replace(root_dir, "")]
        # person2
        feature2 = features[image_dir2.replace(root_dir, "")]
        # sim
        sim = cos_sim(feature1, feature2)
        sims.append((sim, int(tag), image_dir1, image_dir2))
    sims = sorted(sims, key=lambda item: item[0])

    # roc
    tn = 0
    fn = 0
    tp = len(filter(lambda item: item[1] == 1, sims))
    fp = len(filter(lambda item: item[1] == 0, sims))
    best_accuracy = 0.0
    best_thred = 0.0
    with open(image_dir + "roc_%d.txt" % layer_num, "wb") as f:
        for k, sim in enumerate(sims):
            thred, tag, image_file1, image_file2 = sim
            if tag == 0:
                tn += 1
                fp -= 1
            else:
                fn += 1
                tp -= 1
            tpr = 1.0 * tp / max(tp + fn, 1)
            fnr = 1.0 * fn / max(tp + fn, 1)
            tnr = 1.0 * tn / max(tn + fp, 1)
            fpr = 1.0 * fp / max(tn + fp, 1)
            accuracy = 1.0 * (tp + tn) / (tp + fp + tn + fn)
            if accuracy > best_accuracy:
                best_accuracy = accuracy
                best_thred = thred
            f.write("%.6f %.6f\n" % (tpr, fpr))
    print "best:", len(pairs), best_thred, best_accuracy
Exemple #20
0
        print 'WarehouseQuery.search returns {} results for query={}'.format(
            response.total_count, query)
        return response

    @staticmethod
    def get_task(task_id):
        """Get a task from DB according to task_id."""
        query = {'id': task_id}
        col = Mongo.collection(gflags.FLAGS.collection)
        doc = col.find_one(query)
        print 'WarehouseQuery.get_task with query={}'.format(query)
        ret = Task()
        if doc:
            Mongo.doc_to_pb(doc, ret)
        else:
            flask.flash('Error: Cannot find task with ID.')
        return ret


if __name__ == '__main__':
    gflags.FLAGS(sys.argv)
    request = SearchRequest()
    request.count = 1

    response = WarehouseQuery.search(request)
    print response, '\n\n'

    task = WarehouseQuery.get_task(response.tasks[0].id)
    print task.id
Exemple #21
0
        pass  # Directory already exists

    log_path = os.path.join(log_dir, 'app.log')
    handler = logging.FileHandler(log_path)
    handler.setLevel(logging.DEBUG)
    handler.setFormatter(
        logging.Formatter(
            '%(levelname)s %(filename)s:%(lineno)s] %(message)s'))
    logging.getLogger().addHandler(handler)

# Load up our app and all its dependencies. Make the environment sane.
from dpxdt.tools import run_server

# Initialize flags from flags file or enviornment.
import gflags
gflags.FLAGS(['dpxdt_server', '--flagfile=flags.cfg'])
logging.info('BEGIN Flags')
for key, flag in gflags.FLAGS.FlagDict().iteritems():
    logging.info('%s = %s', key, flag.value)
logging.info('END Flags')

# When in production use precompiled templates. Sometimes templates break
# in production. To debug templates there, comment this out entirely.
if os.environ.get('SERVER_SOFTWARE', '').startswith('Google App Engine'):
    import jinja2
    from dpxdt.server import app
    app.jinja_env.auto_reload = False
    app.jinja_env.loader = jinja2.ModuleLoader('templates_compiled.zip')

# Install dpxdt.server override hooks.
from dpxdt.server import api