Differences From Artifact [8c5f02dc69]:
- Executable file debian/garradin — part of check-in [fb49f7d43e] at 2013-07-28 11:03:21 on branch trunk — Débuts de la version hors-ligne (user: bohwaz, size: 2486) [annotate] [blame] [check-ins using]
To Artifact [1ece109feb]:
- Executable file
debian/garradin
— part of check-in
[70a0af2c30]
at
2013-07-28 14:00:23
on branch trunk
— Le single-mode est le seul mode possible de l'exécutable, sinon il faut utiliser directement php en mode serveur.
Ca simplifie le code. Ensuite la commande devient facultative, UI est le comportement par défaut. (user: bohwaz, size: 2725) [annotate] [blame] [check-ins using]
1 2 3 4 | #!/usr/bin/php <?php # Fixme: utiliser un routeur (path du script routeur à passer en argument à PHP) | > | > | | < > > > > > > > > > > > > > > > > > > > | > | | | > > < < < < < < < < < < < < < < < < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | #!/usr/bin/php <?php # Fixme: utiliser un routeur (path du script routeur à passer en argument à PHP) # Fixme: faire passer le fait qu'on est en mode CLI et l'user via la directive ini : -d cli_server.color="$USER" # Fixme: implémenter le fichier de config # Fixme: faire en sorte qu'en mode UI le serveur web et le navigateur soient fermés tous les deux avec un Ctrl-C # Fixme: loguer la sortie du serveur web $config = [ 'browser' => '/usr/bin/www-browser', 'x-browser' => '/usr/bin/x-www-browser', 'port' => 8000, 'root' => '/usr/share/garradin/www', ]; if (isset($_SERVER['HOME'])) { $home = $_SERVER['HOME']; if (file_exists($home . '/.config/garradin/config.ini')) { $config = array_merge($config, parse_ini_file($home . '/.config/garradin/config.ini')); } } $options = getopt('p::v', ['port::', 'verbose']); // Remove options from $argv array foreach ($argv as $k=>$v) { if (($v[0] == '-' && ($opt == substr($v, 1)) && array_key_exists($opt, $options)) || (substr($v, 0, 2) == '--' && ($opt == substr($v, 2)) && array_key_exists($opt, $options))) { if ($options[$opt] !== false) { unset($argv[$k+1]); } unset($argv[$k]) } } $command = isset($argv[1]) ? $argv[1] : false; $verbose = isset($options['v']) || isset($options['verbose']); $port = isset($options['p']) ? (int) $options['p'] : (isset($options['port']) ? (int) $options['port'] : (int)$config['port']); switch ($command) { case 'server': system('php -S localhost:' . $port . ' -t ' . escapeshellarg($config['root'])); break; case 'ui': $browser = !empty($_SERVER['DISPLAY']) ? $config['x-browser'] : $config['browser']; system('php -S localhost:' . $port . ' -t ' . escapeshellarg($config['root']) . ' > /dev/null &'); system($browser . ' ' . escapeshellarg('http://localhost:' . $port)); break; default: echo <<<EOF Usage : $argv[0] [COMMANDE] [PROJET] Où COMMANDE peut être : server [-p|--port PORT] Démarre un serveur web Garradin sur le port spécifié (ou sur le port 8000 par défaut) ui [-p|--port PORT] Idem que 'server' mais démarre ensuite le navigateur web par défaut et connecte automatiquement avec le premier administrateur de l'association. Si aucune COMMANDE n'est donnée, Garradin utilisera 'ui' par défaut. PROJET est le chemin menant à un projet Garradin précis (fichier *.garradin.sqlite). Si aucun projet n'est indiqué, le dernier projet ouvert sera rouvert. Si aucun projet n'a jamais été ouvert un nouveau projet sera créé. Options : -p|--port PORT Spécifie le port pour le mode ui ou le mode serveur. -v|--verbose Affiche les requêtes reçues sur le serveur web. Configuration dans ~/.config/garradin/config.ini EOF; break; } |