Пример #1
0
def Run():
  """This must be called from __main__ modules main, instead of app.run().

  app.run will base its actions on its stacktrace.

  Returns:
    app.run()
  """
  app.parse_flags_with_usage = ParseFlagsWithUsage
  app.really_start = _CommandsStart
  app.usage = _ReplacementAppUsage
  return app.run()
Пример #2
0
  def testGetSudoContextWithoutCertHandler(self):
    self._SudoContextHelper()

    self.mox.StubOutWithMock(certs.getauth, 'GetPassword')
    certs.getauth.GetPassword(
        gui=True, title='Get sudo Password', prompt='sudo password',
        text='Enter local machine password').AndReturn('pass')
    self.mox.ReplayAll()
    sudo, sudo_pass = certs._GetSudoContext(self.keychain, gui=True)
    self.mox.VerifyAll()
    self.assertTrue(sudo)
    self.assertEqual(sudo_pass, 'pass')

  def testGetSudoContextNoSudo(self):
    self._SudoContextHelper()

    self.mox.ReplayAll()
    sudo, sudo_pass = certs._GetSudoContext('notsystemkeychain')
    self.mox.VerifyAll()
    self.assertFalse(sudo)
    self.assertEqual(sudo_pass, None)


def main(unused_argv):
  basetest.main()


if __name__ == '__main__':
  app.run()
#!/usr/bin/env python
"""Broken due to access to flags before parsing."""

from google.apputils import app
import gflags

# Defines string with default value of 'default value'
gflags.DEFINE_string('test_flag', 'default value', 'Test flag')

FLAGS = gflags.FLAGS

# Assigns value of FLAGS.test_flag (string) to MY_CONST during module execution.
# Since flags were not parsed yet FLAGS.test_flag will always return default
# value of the flag.
MY_CONST = FLAGS.test_flag


def main(_):
  print MY_CONST  # Will ALWAYS output 'default value'

if __name__ == '__main__':
  app.run()  # Does a lot of useful stuff, including parsing flags.
Пример #4
0
            except emulated_device.TransientEmulatorFailure as e:
                if attempts < FLAGS.retry_attempts:
                    logging.warning('Transient failure: %s', e)
                else:
                    reporter.ReportFailure(
                        'tools.android.emulator.SoMuchDeath', {
                            'message': str(e),
                            'attempts': attempts
                        })
                    logging.error('Tried %s times - failure: %s', attempts, e)
                    raise e
    finally:
        reporter.Emit()
    logging.debug('return from main function.')


def AddFileLogHandler():
    """Adds a handler to the root logger which writes to a temp file."""
    with tempfile.NamedTemporaryFile(prefix='unified_launcher_',
                                     suffix='.log',
                                     delete=False) as f:
        log_filename = f.name
    file_handler = logging.FileHandler(log_filename)
    root_logger = logging.getLogger()
    root_logger.addHandler(file_handler)


if __name__ == '__main__':
    AddFileLogHandler()
    app.run()