A PHP Error was encountered

Severity: 8192

Message: Function create_function() is deprecated

Filename: geshi/geshi.php

Line Number: 4698

Backtrace:

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 4698
Function: _error_handler

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 4621
Function: _optimize_regexp_list_tokens_to_string

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 1655
Function: optimize_regexp_list

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 2029
Function: optimize_keyword_group

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 2168
Function: build_parse_cache

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/Process.php
Line: 45
Function: parse_code

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/models/Pastes.php
Line: 517
Function: syntax

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/controllers/Main.php
Line: 693
Function: getPaste

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/index.php
Line: 315
Function: require_once

Test - Stikked
From Jonathan, 10 Years ago, written in Python.
Embed
  1. #!/usr/bin/env python
  2. # Copyright 2015 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5.  
  6. import argparse
  7. import json
  8. import logging
  9. import os
  10. import re
  11. import signal
  12. import socket
  13. import subprocess
  14. import sys
  15. import urlparse
  16. import time
  17.  
  18. # TODO(eseidel): This should be BIN_DIR.
  19. LIB_DIR = os.path.realpath(os.path.dirname(os.path.abspath(__file__)))
  20. SKY_PACKAGE_ROOT = os.path.realpath(os.path.dirname(LIB_DIR))
  21.  
  22. SKY_SERVER_PORT = 9888
  23. APK_NAME = 'SkyDemo.apk'
  24. ANDROID_PACKAGE = "org.domokit.sky.demo"
  25. # FIXME: This assumes adb is in $PATH, we could look for ANDROID_HOME, etc?
  26. ADB_PATH = 'adb'
  27.  
  28. PID_FILE_PATH = "/tmp/sky_tool.pids"
  29. PID_FILE_KEYS = frozenset([
  30.     'remote_sky_server_port',
  31.     'sky_server_pid',
  32.     'sky_server_port',
  33.     'sky_server_root',
  34.     'build_dir',
  35. ])
  36.  
  37.  
  38. def _port_in_use(port):
  39.     sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  40.     return sock.connect_ex(('localhost', port)) == 0
  41.  
  42.  
  43. # We need something to serve sky files, python's httpserver is sufficient.
  44. def _start_http_server(port, root):
  45.     server_command = [
  46.         'python', '-m', 'SimpleHTTPServer', str(port),
  47.     ]
  48.     return subprocess.Popen(server_command, cwd=root).pid
  49.  
  50.  
  51. # This 'strict dictionary' approach is useful for catching typos.
  52. class Pids(object):
  53.     def __init__(self, known_keys, contents=None):
  54.         self._known_keys = known_keys
  55.         self._dict = contents if contents is not None else {}
  56.  
  57.     def __len__(self):
  58.         return len(self._dict)
  59.  
  60.     def get(self, key, default=None):
  61.         assert key in self._known_keys, '%s not in known_keys' % key
  62.         return self._dict.get(key, default)
  63.  
  64.     def __getitem__(self, key):
  65.         assert key in self._known_keys, '%s not in known_keys' % key
  66.         return self._dict[key]
  67.  
  68.     def __setitem__(self, key, value):
  69.         assert key in self._known_keys, '%s not in known_keys' % key
  70.         self._dict[key] = value
  71.  
  72.     def __delitem__(self, key):
  73.         assert key in self._known_keys, '%s not in known_keys' % key
  74.         del self._dict[key]
  75.  
  76.     def __iter__(self):
  77.         return iter(self._dict)
  78.  
  79.     def __contains__(self, key):
  80.         assert key in self._known_keys, '%s not in allowed_keys' % key
  81.         return key in self._dict
  82.  
  83.     def clear(self):
  84.         self._dict = {}
  85.  
  86.     def pop(self, key, default=None):
  87.         assert key in self._known_keys, '%s not in known_keys' % key
  88.         return self._dict.pop(key, default)
  89.  
  90.     @classmethod
  91.     def read_from(cls, path, known_keys):
  92.         contents = {}
  93.         try:
  94.             with open(path, 'r') as pid_file:
  95.                 contents = json.load(pid_file)
  96.         except:
  97.             if os.path.exists(path):
  98.                 logging.warn('Failed to read pid file: %s' % path)
  99.         return cls(known_keys, contents)
  100.  
  101.     def write_to(self, path):
  102.         try:
  103.             with open(path, 'w') as pid_file:
  104.                 json.dump(self._dict, pid_file, indent=2, sort_keys=True)
  105.         except:
  106.             logging.warn('Failed to write pid file: %s' % path)
  107.  
  108.  
  109. def _url_for_path(port, root, path):
  110.     relative_path = os.path.relpath(path, root)
  111.     return 'sky://localhost:%s/%s' % (port, relative_path)
  112.  
  113.  
  114. class StartSky(object):
  115.     def add_subparser(self, subparsers):
  116.         start_parser = subparsers.add_parser('start',
  117.             help='launch %s on the device' % APK_NAME)
  118.         start_parser.add_argument('--install', action='store_true')
  119.         start_parser.add_argument('project_or_path', nargs='?', type=str,
  120.             default='main.sky')
  121.         start_parser.set_defaults(func=self.run)
  122.  
  123.     def _is_package_installed(self, package_name):
  124.         pm_path_cmd = [ADB_PATH, 'shell', 'pm', 'path', package_name]
  125.         return subprocess.check_output(pm_path_cmd).strip() != ''
  126.  
  127.     def run(self, args, pids):
  128.         StopSky().run(args, pids)
  129.  
  130.         if not self._is_package_installed(ANDROID_PACKAGE):
  131.             print '%s is not installed, installing.' % APK_NAME
  132.             args.install = True
  133.  
  134.         if args.install:
  135.             apk_path = os.path.join(SKY_PACKAGE_ROOT, 'apks', APK_NAME)
  136.             if not os.path.exists(apk_path):
  137.                 print "'%s' does not exist?" % apk_path
  138.                 return 2
  139.  
  140.             subprocess.check_call([ADB_PATH, 'install', '-r', apk_path])
  141.  
  142.         project_or_path = os.path.abspath(args.project_or_path)
  143.  
  144.         if os.path.isdir(project_or_path):
  145.             sky_server_root = project_or_path
  146.             main_sky = os.path.join(project_or_path, 'main.sky')
  147.             missing_msg = "Missing main.sky in project: %s" % sky_server_root
  148.         else:
  149.             sky_server_root = os.path.dirname(project_or_path)
  150.             main_sky = project_or_path
  151.             missing_msg = "%s does not exist." % main_sky
  152.  
  153.         if not os.path.isfile(main_sky):
  154.             print missing_msg
  155.             return 2
  156.  
  157.         sky_server_port = SKY_SERVER_PORT
  158.         pids['sky_server_port'] = sky_server_port
  159.         if _port_in_use(sky_server_port):
  160.             logging.warn(('Port %s already in use. '
  161.             ' Not starting server for %s') % (sky_server_port, sky_server_root))
  162.         else:
  163.             sky_server_pid = _start_http_server(sky_server_port, sky_server_root)
  164.             pids['sky_server_pid'] = sky_server_pid
  165.             pids['sky_server_root'] = sky_server_root
  166.  
  167.         port_string = 'tcp:%s' % sky_server_port
  168.         subprocess.check_call([
  169.             ADB_PATH, 'reverse', port_string, port_string
  170.         ])
  171.         pids['remote_sky_server_port'] = sky_server_port
  172.  
  173.         # The load happens on the remote device, use the remote port.
  174.         sky_url = _url_for_path(pids['remote_sky_server_port'], sky_server_root,
  175.             main_sky)
  176.  
  177.         subprocess.check_call([ADB_PATH, 'shell',
  178.             'am', 'start',
  179.             '-a', 'android.intent.action.VIEW',
  180.             '-d', sky_url])
  181.  
  182.  
  183. class StopSky(object):
  184.     def add_subparser(self, subparsers):
  185.         stop_parser = subparsers.add_parser('stop',
  186.             help=('kill all running SkyShell.apk processes'))
  187.         stop_parser.set_defaults(func=self.run)
  188.  
  189.     def _kill_if_exists(self, pids, key, name):
  190.         pid = pids.pop(key, None)
  191.         if not pid:
  192.             logging.info('No pid for %s, nothing to do.' % name)
  193.             return
  194.         logging.info('Killing %s (%d).' % (name, pid))
  195.         try:
  196.             os.kill(pid, signal.SIGTERM)
  197.         except OSError:
  198.             logging.info('%s (%d) already gone.' % (name, pid))
  199.  
  200.     def run(self, args, pids):
  201.         self._kill_if_exists(pids, 'sky_server_pid', 'sky_server')
  202.  
  203.         if 'remote_sky_server_port' in pids:
  204.             port_string = 'tcp:%s' % pids['remote_sky_server_port']
  205.             subprocess.call([ADB_PATH, 'reverse', '--remove', port_string])
  206.  
  207.         subprocess.call([
  208.             ADB_PATH, 'shell', 'am', 'force-stop', ANDROID_PACKAGE])
  209.  
  210.         pids.clear()
  211.  
  212.  
  213. class StartTracing(object):
  214.     def add_subparser(self, subparsers):
  215.         start_tracing_parser = subparsers.add_parser('start_tracing',
  216.             help=('start tracing a running sky instance'))
  217.         start_tracing_parser.set_defaults(func=self.run)
  218.  
  219.     def run(self, args, pids):
  220.         subprocess.check_output([ADB_PATH, 'shell',
  221.             'am', 'broadcast',
  222.             '-a', 'org.domokit.sky.demo.TRACING_START'])
  223.  
  224.  
  225. TRACE_COMPLETE_REGEXP = re.compile('Trace complete')
  226. TRACE_FILE_REGEXP = re.compile(r'Saving trace to (?P<path>S+)')
  227.  
  228.  
  229. class StopTracing(object):
  230.     def add_subparser(self, subparsers):
  231.         stop_tracing_parser = subparsers.add_parser('stop_tracing',
  232.             help=('stop tracing a running sky instance'))
  233.         stop_tracing_parser.set_defaults(func=self.run)
  234.  
  235.     def run(self, args, pids):
  236.         subprocess.check_output([ADB_PATH, 'logcat', '-c'])
  237.         subprocess.check_output([ADB_PATH, 'shell',
  238.             'am', 'broadcast',
  239.             '-a', 'org.domokit.sky.demo.TRACING_STOP'])
  240.         device_path = None
  241.         is_complete = False
  242.         while not is_complete:
  243.             time.sleep(0.2)
  244.             log = subprocess.check_output([ADB_PATH, 'logcat', '-d'])
  245.             if device_path is None:
  246.                 result = TRACE_FILE_REGEXP.search(log)
  247.                 if result:
  248.                     device_path = result.group('path')
  249.             is_complete = TRACE_COMPLETE_REGEXP.search(log) is not None
  250.  
  251.         print 'Downloading trace %s ...' % os.path.basename(device_path)
  252.  
  253.         if device_path:
  254.             subprocess.check_output([ADB_PATH, 'pull', device_path])
  255.             subprocess.check_output([ADB_PATH, 'shell', 'rm', device_path])
  256.  
  257.  
  258. class SkyShellRunner(object):
  259.     def _check_for_adb(self):
  260.         try:
  261.             subprocess.check_output([ADB_PATH, 'devices'])
  262.         except OSError:
  263.             print "'adb' (from the Android SDK) not in $PATH, can't continue."
  264.             return False
  265.         return True
  266.  
  267.     def main(self):
  268.         logging.basicConfig(level=logging.WARNING)
  269.         if not self._check_for_adb():
  270.             sys.exit(2)
  271.  
  272.         parser = argparse.ArgumentParser(description='Sky Demo Runner')
  273.         subparsers = parser.add_subparsers(help='sub-command help')
  274.  
  275.         for command in [StartSky(), StopSky(), StartTracing(), StopTracing()]:
  276.             command.add_subparser(subparsers)
  277.  
  278.         args = parser.parse_args()
  279.         pids = Pids.read_from(PID_FILE_PATH, PID_FILE_KEYS)
  280.         exit_code = args.func(args, pids)
  281.         # We could do this with an at-exit handler instead?
  282.         pids.write_to(PID_FILE_PATH)
  283.         sys.exit(exit_code)
  284.  
  285.  
  286. if __name__ == '__main__':
  287.     SkyShellRunner().main()
  288.