Exemple #1
0
def compile(input, output=None, flags=None):
    """Prepares command-line call to Closure Compiler.

    Args:
      source_paths: Source paths to build, in order.

    Returns:
      The compiled source, as a string, or None if compilation failed.
    """

    # User friendly version check.
    if not (distutils.version.LooseVersion(_GetJavaVersion()) >=
                distutils.version.LooseVersion('1.6')):
        logging.error('Requires Java 1.6 or higher. '
                      'Please visit http://www.java.com/getjava')
        return

    svn.try_lock(output)

    args = ['java', '-jar', os.path.dirname(__file__) + '/lib/yuicompressor-2.4.7.jar', input, '--line-break', '1000',
            '--charset', 'gb2312']

    if output:
        args += ['-o', output]

    if flags:
        args += flags

    command.run(' '.join(args), show_log=True)

    return output
Exemple #2
0
 def disabled_test_sudo(self):
     with self.assertRaises(command.TimoutError) as cm:
         command.run(['echo', 'abc'], timout=default_timout, sudo=True)
     e = cm.exception
     self.assertEqual(e.result.stdout, '')
     self.assertRegex(e.result.stderr, '\\[sudo\\] password for .*:')
     self.assertFalse(result.success())
     self.assertEqual(e.result.exit_code, 1)
Exemple #3
0
def commit(paths, msg, show_log=False, cwd=None):
    changelist = "my-changelist-" + str(time())
    command.run("svn changelist " + changelist + " " + " ".join(paths), show_log=show_log)
    cmd_str = "svn commit --no-unlock"
    if msg:
        cmd_str += ' -m "' + msg + '"'
    cmd_str += " --changelist " + changelist
    if not cwd:
        cwd = os.path.dirname(list(paths)[0])
    command.run(cmd_str, cwd=cwd, show_log=show_log)
Exemple #4
0
 def test_timout_actually_works_with_child(self):
     import time
     start = time.perf_counter()
     with self.assertRaises(command.TimoutError) as cm:
         command.run(['sh', '-c', 'sleep ' + str(default_time_long)],
                     timout=default_timout)
     end = time.perf_counter()
     elapsed = end - start
     self.assertGreater(elapsed, default_timout)
     self.assertLess(elapsed, default_timout + default_timout_tolerance)
Exemple #5
0
def commit(paths, msg, show_log=False, cwd=None):
    changelist = "my-changelist-" + str(time())
    command.run("svn changelist " + changelist + " " + " ".join(paths),
                show_log=show_log)
    cmd_str = "svn commit --no-unlock"
    if msg:
        cmd_str += " -m \"" + msg + "\""
    cmd_str += " --changelist " + changelist
    if not cwd:
        cwd = os.path.dirname(list(paths)[0])
    command.run(cmd_str, cwd=cwd, show_log=show_log)
Exemple #6
0
 def test_output_from_timout(self):
     with self.assertRaises(command.TimoutError) as cm:
         command.run([
             'sh', '-c',
             'echo abc; sleep ' + str(default_time_long) + '; echo xyz'
         ],
                     timout=default_timout)
     e = cm.exception
     self.assertTrue(e.result.timout())
     self.assertFalse(e.result.success())
     self.assertEqual(e.result.stdout, 'abc\n')
     self.assertEqual(e.result.stderr, '')
     self.assertEqual(e.result.exit_code, -signal.SIGTERM)
Exemple #7
0
 def test_sleep_timout(self):
     with self.assertRaises(command.TimoutError) as cm:
         command.run(['sleep', str(default_time_long)],
                     timout=default_timout)
     e = cm.exception
     self.assertEqual(e.result.stdout, '')
     self.assertEqual(e.result.stderr, '')
     self.assertFalse(e.result.success())
     self.assertTrue(e.result.timout())
     self.assertTrue(e.result.terminated())
     self.assertFalse(e.result.killed())
     self.assertTrue(e.result.found())
     self.assertEqual(e.result.exit_code, -signal.SIGTERM)
Exemple #8
0
 def test_false_raise(self):
     with self.assertRaises(command.FailError) as cm:
         command.run(['false'])
     e = cm.exception
     self.assertEqual(
         e.args,
         ('false',
          ))  # not sure why it turns the args into a tupel, but who cares
     self.assertFalse(e.result.success())
     self.assertEqual(e.result.exit_code, 1)
     self.assertTrue(e.result.found())
     self.assertFalse(e.result.timout())
     self.assertEqual(e.result.stdout, '')
     self.assertEqual(e.result.stderr, '')
Exemple #9
0
 def test_sleep_short(self):
     result = command.run(['sleep', str(default_timout)],
                          timout=default_timout * 2)
     self.assertTrue(result.success())
     self.assertFalse(result.timout())
     self.assertEqual(result.stdout, '')
     self.assertEqual(result.stderr, '')
Exemple #10
0
        def test_uncooperative_child_gets_killed(self):
            with self.assertRaises(command.TimoutError) as cm:
                result = command.run([
                    'python3', '-c', '''
import time
import signal
import sys
def signal_term_handler(signal, frame):
    print('c')
    sys.stdout.flush()
signal.signal(signal.SIGTERM, signal_term_handler)
try:
    print('a')
    sys.stdout.flush()
    time.sleep(''' + str(default_time_long) + ''')
except:
    print('b')
    sys.stdout.flush()
                    '''
                ],
                                     timout=default_python_timout)
            e = cm.exception
            self.assertFalse(e.result.success())
            self.assertTrue(e.result.timout())
            self.assertFalse(e.result.terminated())
            self.assertTrue(e.result.killed())
            self.assertEqual(e.result.stdout, 'a\nc\n')
            self.assertEqual(e.result.stderr, '')
            self.assertEqual(
                e.result.exit_code, -signal.SIGKILL
            )  # Note the SIGKILL instead of SIGTERM, like in the rest
Exemple #11
0
 def test_echo(self):
     result = command.run(['echo', 'abc'])
     self.assertTrue(result.success())
     self.assertTrue(result.found())
     self.assertFalse(result.timout())
     self.assertFalse(result.terminated())
     self.assertFalse(result.killed())
     self.assertEqual(result.stdout, 'abc\n')
     self.assertEqual(result.stderr, '')
     self.assertEqual(result.exit_code, 0)
Exemple #12
0
 def test_not_found_no_raise(self):
     result = command.run(['a_command_that_doesnt_exist'],
                          ignore_error=True)
     self.assertFalse(result.success())
     self.assertFalse(result.found())
     self.assertEqual(result.exit_code, 127)
     self.assertFalse(result.timout())
     self.assertFalse(result.terminated())
     self.assertFalse(result.killed())
     self.assertEqual(result.stdout, None)
     self.assertEqual(result.stderr, None)
Exemple #13
0
 def test_output_from_timout_no_raise(self):
     result = command.run([
         'sh', '-c',
         'echo abc; sleep ' + str(default_time_long) + '; echo xyz'
     ],
                          timout=default_timout,
                          ignore_error=True)
     self.assertTrue(result.timout())
     self.assertFalse(result.success())
     self.assertEqual(result.stdout, 'abc\n')
     self.assertEqual(result.stderr, '')
     self.assertEqual(result.exit_code, -signal.SIGTERM)
Exemple #14
0
        def test_cooperative_child_gets_terminated(self):
            with self.assertRaises(command.TimoutError) as cm:
                command.run([
                    'python3', '-c', '''
import time
import sys
try:
    print('a')
    sys.stdout.flush()
    time.sleep(''' + str(default_time_long) + ''')
except:
    print('b')
    sys.stdout.flush()
                    '''
                ],
                            timout=default_python_timout)
            e = cm.exception
            self.assertFalse(e.result.success())
            self.assertTrue(e.result.timout())
            self.assertTrue(e.result.terminated())
            self.assertFalse(e.result.killed())
            self.assertEqual(e.result.stdout, 'a\n')
            self.assertEqual(e.result.stderr, '')
            self.assertEqual(e.result.exit_code, -signal.SIGTERM)
Exemple #15
0
 def test_not_found(self):
     with self.assertRaises(command.NotFoundError) as cm:
         result = command.run(['a_command_that_doesnt_exist'])
     self.assertEqual(cm.exception.name, 'a_command_that_doesnt_exist')
     self.assertFalse(hasattr(cm.exception, 'result'))
Exemple #16
0
def status(path, show_log=False):
    status_str = (command.run("svn status -v " + path, show_log=show_log))[:8]
    return status_str
Exemple #17
0
def add(paths, show_log=False):
    command.run("svn add --force " + " ".join(paths), show_log=show_log)
Exemple #18
0
def lock(force, path, show_log):
    cmd_str = "svn lock"
    if force:
        cmd_str += ' --force'
    cmd_str += ' ' + path
    command.run(cmd_str, show_log=show_log)
Exemple #19
0
def status(path, show_log=False):
    status_str = (command.run("svn status -v " + path, show_log=show_log))[:8]
    return status_str
Exemple #20
0
 def test_true_capturing(self):
     result = command.run(['true'])
     self.assertTrue(result.success())
     self.assertEqual(result.stdout, '')
     self.assertEqual(result.stderr, '')
Exemple #21
0
def add(paths, show_log=False):
    command.run("svn add --force " + " ".join(paths), show_log=show_log)
Exemple #22
0
def lock(force, path, show_log):
    cmd_str = "svn lock"
    if force:
        cmd_str += " --force"
    cmd_str += " " + path
    command.run(cmd_str, show_log=show_log)
Exemple #23
0
 def test_true_noncapturing(self):
     result = command.run(['true'], passthrough=True)
     self.assertTrue(result.success())
     self.assertEqual(result.stdout, None)
     self.assertEqual(result.stderr, None)
Exemple #24
0
 def test_cwd(self):
     current = command.run(['ls'], cwd='.')
     dev = command.run(['ls'], cwd='/dev')
     self.assertNotEqual(current.stdout, dev.stdout)
     self.assertIn('null', {i: None for i in dev.stdout.split()})
Exemple #25
0
 def test_input(self):
     result = command.run(['cat'], input_str='xyz\n')
     self.assertEqual(result.stdout, 'xyz\n')
Exemple #26
0
 def test_false_result(self):
     result = command.run(['false'], ignore_error=True)
     self.assertFalse(result.success())
     self.assertEqual(result.exit_code, 1)
     self.assertFalse(result.timout())