Skip to content

Commit

Permalink
Deprecate $ConfSitePATH global.
Browse files Browse the repository at this point in the history
* Introduce SiteLoader class.
* Reorganize getopt_rest so it is autoloadable.
* Move src/sample.pdf to etc/sample.pdf.
  • Loading branch information
kohler committed Jun 14, 2020
1 parent 0c0960d commit 2cd7755
Show file tree
Hide file tree
Showing 40 changed files with 396 additions and 424 deletions.
7 changes: 3 additions & 4 deletions batch/assign.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php
$ConfSitePATH = preg_replace(',/batch/[^/]+,', '', __FILE__);
require_once("$ConfSitePATH/lib/getopt.php");
require_once(preg_replace('/\/batch\/[^\/]+/', '/src/siteloader.php', __FILE__));

$arg = getopt_rest($argv, "hn:d", ["help", "name:", "dry-run"]);
$arg = Getopt::rest($argv, "hn:d", ["help", "name:", "dry-run"]);
if (isset($arg["h"]) || isset($arg["help"]) || count($arg["_"]) > 1) {
fwrite(STDOUT, "Usage: php batch/assign.php [-n CONFID] [-d|--dry-run] [FILE]
Perform a CSV bulk assignment.
Expand All @@ -12,7 +11,7 @@
exit(0);
}

require_once("$ConfSitePATH/src/init.php");
require_once(SiteLoader::find("src/init.php"));

if (empty($arg["_"])) {
$filename = "<stdin>";
Expand Down
6 changes: 3 additions & 3 deletions batch/banaldocstore.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
if (isset($arg[$s]) && !isset($arg[$l]))
$arg[$l] = $arg[$s];
}
if (isset($arg["silent"]))
if (isset($arg["silent"])) {
$arg["quiet"] = false;
}
if (isset($arg["h"]) || isset($arg["help"])) {
fwrite(STDOUT, "Usage: php batch/cleandocstore.php [-c COUNT] [-V] [-m MATCH]\n"
. " [-d|--dry-run] [-o OUTPUTDIR]\n");
Expand All @@ -20,8 +21,7 @@
exit(1);
}

$ConfSitePATH = preg_replace(',/batch/[^/]+,', '', __FILE__);
require_once("$ConfSitePATH/src/init.php");
require_once(preg_replace('/\/batch\/[^\/]+/', '/src/init.php', __FILE__));

$dp = $Conf->docstore();
if (!$dp) {
Expand Down
6 changes: 2 additions & 4 deletions batch/checkinvariants.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php
$ConfSitePATH = preg_replace(',/batch/[^/]+,', '', __FILE__);
require_once("$ConfSitePATH/src/init.php");
require_once("$ConfSitePATH/lib/getopt.php");
require_once(preg_replace('/\/batch\/[^\/]+/', '/src/init.php', __FILE__));

$arg = getopt_rest($argv, "hn:", array("help", "name:", "json-reviews", "fix-json-reviews", "fix-autosearch"));
$arg = Getopt::rest($argv, "hn:", array("help", "name:", "json-reviews", "fix-json-reviews", "fix-autosearch"));
if (isset($arg["h"]) || isset($arg["help"])
|| count($arg["_"]) > 0) {
fwrite(STDOUT, "Usage: php batch/checkinvariants.php [-n CONFID] [--fix-autosearch]\n");
Expand Down
7 changes: 3 additions & 4 deletions batch/cleandocstore.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
// cleandocstore.php -- HotCRP maintenance script
// Copyright (c) 2006-2020 Eddie Kohler; see LICENSE.

$ConfSitePATH = preg_replace(',/batch/[^/]+,', '', __FILE__);
require_once("$ConfSitePATH/lib/getopt.php");
require_once(preg_replace('/\/batch\/[^\/]+/', '/src/siteloader.php', __FILE__));

$arg = getopt_rest($argv, "hn:c:Vm:du:q", ["help", "name:", "count:", "verbose", "match:",
$arg = Getopt::rest($argv, "hn:c:Vm:du:q", ["help", "name:", "count:", "verbose", "match:",
"dry-run", "max-usage:", "quiet", "silent", "keep-temp", "docstore"]);
foreach (["c" => "count", "V" => "verbose", "m" => "match", "d" => "dry-run",
"u" => "max-usage", "q" => "quiet"] as $s => $l) {
Expand All @@ -25,7 +24,7 @@
exit(1);
}

require_once("$ConfSitePATH/src/init.php");
require_once(SiteLoader::find("src/init.php"));

class Batch_CleanDocstore {
/** @var list<?DocumentFileTree> */
Expand Down
8 changes: 3 additions & 5 deletions batch/deletepapers.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php
$ConfSitePATH = preg_replace(',/batch/[^/]+,', '', __FILE__);
require_once(preg_replace('/\/batch\/[^\/]+/', '/src/siteloader.php', __FILE__));

require_once("$ConfSitePATH/lib/getopt.php");
$arg = getopt_rest($argv, "hn:yq",
["help", "name:", "yes", "quiet"]);
$arg = Getopt::rest($argv, "hn:yq", ["help", "name:", "yes", "quiet"]);
if (isset($arg["h"]) || isset($arg["help"])
|| count($arg["_"]) == 0) {
fwrite(STDOUT, "Usage: php batch/deletepapers.php [-n CONFID] [OPTIONS] PAPER...
Expand All @@ -14,7 +12,7 @@
exit(0);
}

require_once("$ConfSitePATH/src/init.php");
require_once(SiteLoader::find("src/init.php"));

$yes = isset($arg["y"]) || isset($arg["yes"]);
$quiet = isset($arg["q"]) || isset($arg["quiet"]);
Expand Down
4 changes: 1 addition & 3 deletions batch/downgradedb.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
// Systematically downgrade a current HotCRP database
// into a version at schema version 11 (commit b0054f80185d624597d5bbbec0f2eafc73afe69b)

$ConfSitePATH = preg_replace(',/batch/[^/]+,', '', __FILE__);
require_once("$ConfSitePATH/src/init.php");
require_once("$ConfSitePATH/lib/getopt.php");
require_once(preg_replace('/\/batch\/[^\/]+/', '/src/init.php', __FILE__));

$arg = getopt("hn:", array("help", "name:"));
if (isset($arg["h"]) || isset($arg["help"])) {
Expand Down
13 changes: 6 additions & 7 deletions batch/fakenames.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php
$ConfSitePATH = preg_replace(',/batch/[^/]+,', '', __FILE__);
require_once("$ConfSitePATH/src/init.php");
require_once("$ConfSitePATH/lib/getopt.php");
require_once(preg_replace('/\/batch\/[^\/]+/', '/src/init.php', __FILE__));

$arg = getopt("hn:", array("help", "name:"));
if (isset($arg["h"]) || isset($arg["help"])) {
Expand All @@ -13,11 +11,12 @@ class Fakes {
private $data = [];

function load($file = null) {
global $ConfSitePATH;
if ($file === null)
$file = "$ConfSitePATH/extra/fakenames.csv";
if (($s = file_get_contents($file)) === false)
if ($file === null) {
$file = SiteLoader::find("extra/fakenames.csv");
}
if (($s = file_get_contents($file)) === false) {
return false;
}
$csv = new CsvParser($s);
while (($x = $csv->next_array())) {
list($name, $type, $count) = $x;
Expand Down
6 changes: 2 additions & 4 deletions batch/fixdelegation.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php
$ConfSitePATH = preg_replace(',/batch/[^/]+,', '', __FILE__);
require_once("$ConfSitePATH/src/init.php");
require_once("$ConfSitePATH/lib/getopt.php");
require_once(preg_replace('/\/batch\/[^\/]+/', '/src/init.php', __FILE__));

$arg = getopt_rest($argv, "hn:q", array("help", "name:"));
$arg = Getopt::rest($argv, "hn:q", array("help", "name:"));
if (isset($arg["h"]) || isset($arg["help"])
|| count($arg["_"]) > 0) {
fwrite(STDOUT, "Usage: php batch/fixdelegation.php [-n CONFID]\n");
Expand Down
3 changes: 1 addition & 2 deletions batch/killinactivedoc.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
$ConfSitePATH = preg_replace(',/batch/[^/]+,', '', __FILE__);
require_once("$ConfSitePATH/src/init.php");
require_once(preg_replace('/\/batch\/[^\/]+/', '/src/init.php', __FILE__));

$arg = getopt("hfn:", array("help", "force", "name:"));
if (isset($arg["h"]) || isset($arg["help"])) {
Expand Down
7 changes: 3 additions & 4 deletions batch/reviews.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php
$ConfSitePATH = preg_replace(',/batch/[^/]+,', '', __FILE__);
require_once("$ConfSitePATH/lib/getopt.php");
require_once(preg_replace('/\/batch\/[^\/]+/', '/src/siteloader.php', __FILE__));

$arg = getopt_rest($argv, "hn:t:xwacN", ["help", "name:", "type:", "narrow", "wide", "all", "no-header", "comments", "sitename"]);
$arg = Getopt::rest($argv, "hn:t:xwacN", ["help", "name:", "type:", "narrow", "wide", "all", "no-header", "comments", "sitename"]);
if (isset($arg["h"]) || isset($arg["help"])) {
fwrite(STDOUT, "Usage: php batch/reviews.php [-n CONFID] [-t COLLECTION] [-acx] [QUERY...]
Output a CSV file containing all reviews for the papers matching QUERY.
Expand All @@ -25,7 +24,7 @@
exit(1);
}

require_once("$ConfSitePATH/src/init.php");
require_once(SiteLoader::find("src/init.php"));

$user = $Conf->root_user();
$t = get($arg, "t", "s");
Expand Down
6 changes: 2 additions & 4 deletions batch/s3test.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php
$ConfSitePATH = preg_replace(',/batch/[^/]+,', '', __FILE__);
require_once("$ConfSitePATH/src/init.php");
require_once("$ConfSitePATH/lib/getopt.php");
require_once(preg_replace('/\/batch\/[^\/]+/', '/src/init.php', __FILE__));

$arg = getopt_rest($argv, "hn:qeV", array("help", "name:", "quiet", "extensions", "verbose"));
$arg = Getopt::rest($argv, "hn:qeV", array("help", "name:", "quiet", "extensions", "verbose"));
if (isset($arg["h"]) || isset($arg["help"])) {
fwrite(STDOUT, "Usage: php batch/s3test.php [-q] [--extensions] [FILE...]\n");
exit(0);
Expand Down
3 changes: 1 addition & 2 deletions batch/s3transfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
exit(0);
}

$ConfSitePATH = preg_replace(',/batch/[^/]+,', '', __FILE__);
require_once("$ConfSitePATH/src/init.php");
require_once(preg_replace('/\/batch\/[^\/]+/', '/src/init.php', __FILE__));

$active = false;
if (isset($arg["a"]) || isset($arg["active"])) {
Expand Down
4 changes: 2 additions & 2 deletions batch/s3verifyall.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
$ConfSitePATH = preg_replace(',/batch/[^/]+,', '', __FILE__);
require_once(preg_replace('/\/batch\/[^\/]+/', '/src/siteloader.php', __FILE__));

$arg = getopt("hn:c:Vm:", ["help", "name:", "count:", "verbose", "match:"]);
if (isset($arg["c"]) && !isset($arg["count"])) {
Expand All @@ -16,7 +16,7 @@
exit(0);
}

require_once("$ConfSitePATH/src/init.php");
require_once(SiteLoader::find("src/init.php"));

$count = isset($arg["count"]) ? intval($arg["count"]) : null;
$verbose = isset($arg["verbose"]);
Expand Down
7 changes: 3 additions & 4 deletions batch/savepapers.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php
$ConfSitePATH = preg_replace(',/batch/[^/]+,', '', __FILE__);
require_once(preg_replace('/\/batch\/[^\/]+/', '/src/siteloader.php', __FILE__));

require_once("$ConfSitePATH/lib/getopt.php");
$arg = getopt_rest($argv, "hn:qrf:",
$arg = Getopt::rest($argv, "hn:qrf:",
["help", "name:", "filter=f:", "quiet", "disable", "disable-users",
"reviews", "match-title", "ignore-pid", "ignore-errors", "add-topics"]);
if (isset($arg["h"]) || isset($arg["help"])
Expand All @@ -22,7 +21,7 @@
exit(0);
}

require_once("$ConfSitePATH/src/init.php");
require_once(SiteLoader::find("src/init.php"));

$file = count($arg["_"]) ? $arg["_"][0] : "-";
$quiet = isset($arg["q"]) || isset($arg["quiet"]);
Expand Down
7 changes: 3 additions & 4 deletions batch/saveusers.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php
$ConfSitePATH = preg_replace(',/batch/[^/]+,', '', __FILE__);
require_once("$ConfSitePATH/lib/getopt.php");
require_once(preg_replace('/\/batch\/[^\/]+/', '/src/siteloader.php', __FILE__));

$arg = getopt_rest($argv, "hn:e:u:r:", ["help", "name:", "no-email", "no-notify", "modify-only", "create-only", "no-modify", "no-create", "expression:", "expr:", "user:", "roles:", "uname:"]);
$arg = Getopt::rest($argv, "hn:e:u:r:", ["help", "name:", "no-email", "no-notify", "modify-only", "create-only", "no-modify", "no-create", "expression:", "expr:", "user:", "roles:", "uname:"]);
foreach (["expr" => "e", "expression" => "e", "no-email" => "no-notify",
"no-create" => "modify-only", "no-modify" => "create-only",
"user" => "u", "roles" => "r", "help" => "h"] as $long => $short) {
Expand All @@ -25,7 +24,7 @@
exit($status);
}

require_once("$ConfSitePATH/src/init.php");
require_once(SiteLoader::find("src/init.php"));

function save_contact(UserStatus $ustatus, $key, $cj, $arg) {
global $status;
Expand Down
7 changes: 3 additions & 4 deletions batch/search.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php
$ConfSitePATH = preg_replace(',/batch/[^/]+,', '', __FILE__);
require_once("$ConfSitePATH/lib/getopt.php");
require_once(preg_replace('/\/batch\/[^\/]+/', '/src/siteloader.php', __FILE__));

$arg = getopt_rest($argv, "hn:t:f:N", ["help", "name:", "type:", "field:", "show:", "header", "no-header", "sitename"]);
$arg = Getopt::rest($argv, "hn:t:f:N", ["help", "name:", "type:", "field:", "show:", "header", "no-header", "sitename"]);
if (isset($arg["h"]) || isset($arg["help"])) {
fwrite(STDOUT, "Usage: php batch/search.php [-n CONFID] [-t COLLECTION] [-f FIELD]+ [QUERY...]
Output a CSV file containing the FIELDs for the papers matching QUERY.
Expand All @@ -20,7 +19,7 @@
$arg["t"] = $arg["type"];
}

require_once("$ConfSitePATH/src/init.php");
require_once(SiteLoader::find("src/init.php"));

$user = $Conf->root_user();
$t = get($arg, "t", "s");
Expand Down
7 changes: 3 additions & 4 deletions batch/updatecontactdb.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php
$ConfSitePATH = preg_replace(',/batch/[^/]+,', '', __FILE__);
require_once("$ConfSitePATH/lib/getopt.php");
require_once(preg_replace('/\/batch\/[^\/]+/', '/src/siteloader.php', __FILE__));

$arg = getopt_rest($argv, "hn:pu", ["help", "name:", "papers", "users", "collaborators"]);
$arg = Getopt::rest($argv, "hn:pu", ["help", "name:", "papers", "users", "collaborators"]);
if (isset($arg["h"]) || isset($arg["help"])
|| count($arg["_"]) > 1
|| (count($arg["_"]) && $arg["_"][0] !== "-" && $arg["_"][0][0] === "-")) {
Expand All @@ -18,7 +17,7 @@
$users = $papers = true;
}

require_once("$ConfSitePATH/src/init.php");
require_once(SiteLoader::find("src/init.php"));
if (!$Conf->opt("contactdb_dsn")) {
fwrite(STDERR, "Conference has no contactdb_dsn\n");
exit(1);
Expand Down
15 changes: 5 additions & 10 deletions batch/updateemojicodes.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
$ConfSitePATH = preg_replace(',/batch/[^/]+,', '', __FILE__);
require_once("$ConfSitePATH/src/init.php");
require_once(preg_replace('/\/batch\/[^\/]+/', '/src/init.php', __FILE__));

$optind = null;
$arg = getopt("acdmn:t", ["absent", "common", "dups", "modifier-bases", "name:", "terminators"], $optind);
Expand Down Expand Up @@ -44,8 +43,7 @@ function parse_emoji_data_stdin() {
}

function list_duplicate_codes() {
global $ConfSitePATH;
$emoji = json_decode(file_get_contents("$ConfSitePATH/scripts/emojicodes.json"));
$emoji = json_decode(file_get_contents(SiteLoader::find("scripts/emojicodes.json")));
$codes = $dups = [];
foreach ((array) $emoji->emoji as $code => $text) {
if (!isset($codes[$text]))
Expand Down Expand Up @@ -86,8 +84,7 @@ function emoji_to_code_set($emoji) {
}

function list_common_emoji() {
global $ConfSitePATH;
$emoji = json_decode(file_get_contents("$ConfSitePATH/scripts/emojicodes.json"));
$emoji = json_decode(file_get_contents(SiteLoader::find("scripts/emojicodes.json")));
$back = emoji_to_code_set($emoji);

$rankings = json_decode(stream_get_contents(STDIN));
Expand Down Expand Up @@ -128,8 +125,7 @@ function list_common_emoji() {
}

function list_terminators() {
global $ConfSitePATH;
$emoji = json_decode(file_get_contents("$ConfSitePATH/scripts/emojicodes.json"));
$emoji = json_decode(file_get_contents(SiteLoader::find("scripts/emojicodes.json")));
$x = [];
foreach ((array) $emoji->emoji as $text) {
preg_match('/.\z/u', $text, $m);
Expand Down Expand Up @@ -189,8 +185,7 @@ function modifier_base_regex() {
}

function list_absent($args) {
global $ConfSitePATH;
$emoji = json_decode(file_get_contents("$ConfSitePATH/scripts/emojicodes.json"));
$emoji = json_decode(file_get_contents(SiteLoader::find("scripts/emojicodes.json")));
$codes = [];
foreach ((array) $emoji->emoji as $text) {
$codes[$text] = true;
Expand Down
10 changes: 3 additions & 7 deletions batch/updateutf8trans.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<?php
$ConfSitePATH = preg_replace(',/batch/[^/]+,', '', __FILE__);
require_once("$ConfSitePATH/src/init.php");
require_once("$ConfSitePATH/lib/getopt.php");
require_once("$ConfSitePATH/lib/unicodehelper.php");
require_once(preg_replace('/\/batch\/[^\/]+/', '/src/init.php', __FILE__));

$arg = getopt_rest($argv, "hn:f:Vuto:",
$arg = Getopt::rest($argv, "hn:f:Vuto:",
["help", "name:", "file:", "verbose", "unparse", "time", "output:"]);
if (isset($arg["h"]) || isset($arg["help"])) {
fwrite(STDOUT, "Usage: php batch/updateutf8trans.php CODEPOINT STRING...\n");
Expand Down Expand Up @@ -199,7 +196,6 @@ function parse_file($filename, $unparse, $verbose) {
}

function run($arg) {
global $ConfSitePATH;
$verbose = isset($arg["V"]) || isset($arg["verbose"]);
$unparse = isset($arg["u"]) || isset($arg["unparse"]);
if (isset($arg["t"]) || isset($arg["time"])) {
Expand Down Expand Up @@ -228,7 +224,7 @@ function run($arg) {
ksort($this->trans[2], SORT_STRING);
ksort($this->trans[3], SORT_STRING);

$unicode_helper = file_get_contents("$ConfSitePATH/lib/unicodehelper.php");
$unicode_helper = file_get_contents(SiteLoader::find("lib/unicodehelper.php"));
fwrite(STDOUT, substr($unicode_helper, 0, strpos($unicode_helper, "define(")));

$m = $n = "";
Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions lib/csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
// Copyright (c) 2006-2020 Eddie Kohler; see LICENSE.

if (!function_exists("gmp_init")) {
global $ConfSitePATH;
require_once("$ConfSitePATH/lib/polyfills.php");
require_once(SiteLoader::find("lib/polyfills.php"));
}

class CsvRow implements ArrayAccess, IteratorAggregate, Countable, JsonSerializable {
Expand Down
Loading

0 comments on commit 2cd7755

Please sign in to comment.