mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-18 11:30:55 +01:00
Improve bin/lipsum UX
Summary: Ref T9156. This makes the UX a little more modern/standard/safe. Test Plan: ``` epriestley@orbital ~/dev/phabricator $ ./bin/lipsum generate Choose which type or types of test data you want to generate, or select "all". - Differential Revisions - Files - Maniphest Tasks - Pastes - Pholio Mocks - Projects - User Accounts ``` Reviewers: chad Reviewed By: chad Maniphest Tasks: T9156 Differential Revision: https://secure.phabricator.com/D14873
This commit is contained in:
parent
1c572d1da5
commit
ba37149bf9
10 changed files with 141 additions and 67 deletions
|
@ -5,10 +5,10 @@ $root = dirname(dirname(dirname(__FILE__)));
|
||||||
require_once $root.'/scripts/__init_script__.php';
|
require_once $root.'/scripts/__init_script__.php';
|
||||||
|
|
||||||
$args = new PhutilArgumentParser($argv);
|
$args = new PhutilArgumentParser($argv);
|
||||||
$args->setTagline(pht('manage lipsum'));
|
$args->setTagline(pht('synthetic data generator'));
|
||||||
$args->setSynopsis(<<<EOSYNOPSIS
|
$args->setSynopsis(<<<EOSYNOPSIS
|
||||||
**lipsum** __command__ [__options__]
|
**lipsum** __command__ [__options__]
|
||||||
Manage Phabricator Test Data Generator.
|
Generate synthetic test data to make development easier.
|
||||||
|
|
||||||
EOSYNOPSIS
|
EOSYNOPSIS
|
||||||
);
|
);
|
||||||
|
|
|
@ -3,7 +3,11 @@
|
||||||
final class PhabricatorDifferentialRevisionTestDataGenerator
|
final class PhabricatorDifferentialRevisionTestDataGenerator
|
||||||
extends PhabricatorTestDataGenerator {
|
extends PhabricatorTestDataGenerator {
|
||||||
|
|
||||||
public function generate() {
|
public function getGeneratorName() {
|
||||||
|
return pht('Differential Revisions');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function generateObject() {
|
||||||
$author = $this->loadPhabrictorUser();
|
$author = $this->loadPhabrictorUser();
|
||||||
|
|
||||||
$revision = DifferentialRevision::initializeNewRevision($author);
|
$revision = DifferentialRevision::initializeNewRevision($author);
|
||||||
|
|
|
@ -3,7 +3,11 @@
|
||||||
final class PhabricatorFileTestDataGenerator
|
final class PhabricatorFileTestDataGenerator
|
||||||
extends PhabricatorTestDataGenerator {
|
extends PhabricatorTestDataGenerator {
|
||||||
|
|
||||||
public function generate() {
|
public function getGeneratorName() {
|
||||||
|
return pht('Files');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function generateObject() {
|
||||||
$author_phid = $this->loadPhabrictorUserPHID();
|
$author_phid = $this->loadPhabrictorUserPHID();
|
||||||
$dimension = 1 << rand(5, 12);
|
$dimension = 1 << rand(5, 12);
|
||||||
$image = id(new PhabricatorLipsumMondrianArtist())
|
$image = id(new PhabricatorLipsumMondrianArtist())
|
||||||
|
|
|
@ -2,9 +2,8 @@
|
||||||
|
|
||||||
abstract class PhabricatorTestDataGenerator extends Phobject {
|
abstract class PhabricatorTestDataGenerator extends Phobject {
|
||||||
|
|
||||||
public function generate() {
|
abstract public function getGeneratorName();
|
||||||
return;
|
abstract public function generateObject();
|
||||||
}
|
|
||||||
|
|
||||||
public function loadOneRandom($classname) {
|
public function loadOneRandom($classname) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -7,7 +7,7 @@ final class PhabricatorLipsumGenerateWorkflow
|
||||||
$this
|
$this
|
||||||
->setName('generate')
|
->setName('generate')
|
||||||
->setExamples('**generate**')
|
->setExamples('**generate**')
|
||||||
->setSynopsis(pht('Generate some lipsum.'))
|
->setSynopsis(pht('Generate synthetic test objects.'))
|
||||||
->setArguments(
|
->setArguments(
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
|
@ -18,77 +18,124 @@ final class PhabricatorLipsumGenerateWorkflow
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute(PhutilArgumentParser $args) {
|
public function execute(PhutilArgumentParser $args) {
|
||||||
$console = PhutilConsole::getConsole();
|
$config_key = 'phabricator.developer-mode';
|
||||||
|
if (!PhabricatorEnv::getEnvConfig($config_key)) {
|
||||||
|
throw new PhutilArgumentUsageException(
|
||||||
|
pht(
|
||||||
|
'lipsum is a development and testing tool and may only be run '.
|
||||||
|
'on installs in developer mode. Enable "%s" in your configuration '.
|
||||||
|
'to enable lipsum.',
|
||||||
|
$config_key));
|
||||||
|
}
|
||||||
|
|
||||||
$supported_types = id(new PhutilClassMapQuery())
|
$all_generators = id(new PhutilClassMapQuery())
|
||||||
->setAncestorClass('PhabricatorTestDataGenerator')
|
->setAncestorClass('PhabricatorTestDataGenerator')
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
$console->writeOut(
|
$argv = $args->getArg('args');
|
||||||
"%s:\n\t%s\n",
|
$all = 'all';
|
||||||
pht('These are the types of data you can generate'),
|
|
||||||
implode("\n\t", array_keys($supported_types)));
|
|
||||||
|
|
||||||
$prompt = pht('Are you sure you want to generate lots of test data?');
|
if (!$argv) {
|
||||||
|
$names = mpull($all_generators, 'getGeneratorName');
|
||||||
|
sort($names);
|
||||||
|
|
||||||
|
$list = id(new PhutilConsoleList())
|
||||||
|
->setWrap(false)
|
||||||
|
->addItems($names);
|
||||||
|
|
||||||
|
id(new PhutilConsoleBlock())
|
||||||
|
->addParagraph(
|
||||||
|
pht(
|
||||||
|
'Choose which type or types of test data you want to generate, '.
|
||||||
|
'or select "%s".',
|
||||||
|
$all))
|
||||||
|
->addList($list)
|
||||||
|
->draw();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$generators = array();
|
||||||
|
foreach ($argv as $arg_original) {
|
||||||
|
$arg = phutil_utf8_strtolower($arg_original);
|
||||||
|
|
||||||
|
$match = false;
|
||||||
|
foreach ($all_generators as $generator) {
|
||||||
|
$name = phutil_utf8_strtolower($generator->getGeneratorName());
|
||||||
|
|
||||||
|
if ($arg == $all) {
|
||||||
|
$generators[] = $generator;
|
||||||
|
$match = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strpos($name, $arg) !== false) {
|
||||||
|
$generators[] = $generator;
|
||||||
|
$match = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$match) {
|
||||||
|
throw new PhutilArgumentUsageException(
|
||||||
|
pht(
|
||||||
|
'Argument "%s" does not match the name of any generators.',
|
||||||
|
$arg_original));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo tsprintf(
|
||||||
|
"**<bg:blue> %s </bg>** %s\n",
|
||||||
|
pht('GENERATORS'),
|
||||||
|
pht(
|
||||||
|
'Selected generators: %s.',
|
||||||
|
implode(', ', mpull($generators, 'getGeneratorName'))));
|
||||||
|
|
||||||
|
echo tsprintf(
|
||||||
|
"**<bg:yellow> %s </bg>** %s\n",
|
||||||
|
pht('WARNING'),
|
||||||
|
pht(
|
||||||
|
'This command generates synthetic test data, including user '.
|
||||||
|
'accounts. It is intended for use in development environments '.
|
||||||
|
'so you can test features more easily. There is no easy way to '.
|
||||||
|
'delete this data or undo the effects of this command. If you run '.
|
||||||
|
'it in a production environment, it will pollute your data with '.
|
||||||
|
'large amounts of meaningless garbage that you can not get rid of.'));
|
||||||
|
|
||||||
|
$prompt = pht('Are you sure you want to generate piles of garbage?');
|
||||||
if (!phutil_console_confirm($prompt, true)) {
|
if (!phutil_console_confirm($prompt, true)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$argv = $args->getArg('args');
|
echo tsprintf(
|
||||||
if (count($argv) == 0 || (count($argv) == 1 && $argv[0] == 'all')) {
|
"**<bg:green> %s </bg>** %s\n",
|
||||||
$this->infinitelyGenerate($supported_types);
|
pht('LIPSUM'),
|
||||||
} else {
|
pht(
|
||||||
$new_supported_types = array();
|
'Generating synthetic test objects forever. '.
|
||||||
for ($i = 0; $i < count($argv); $i++) {
|
'Use ^C to stop when satisfied.'));
|
||||||
$arg = $argv[$i];
|
|
||||||
if (array_key_exists($arg, $supported_types)) {
|
|
||||||
$new_supported_types[$arg] = $supported_types[$arg];
|
|
||||||
} else {
|
|
||||||
$console->writeErr(
|
|
||||||
"%s\n",
|
|
||||||
pht(
|
|
||||||
'The type %s is not supported by the lipsum generator.',
|
|
||||||
$arg));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$this->infinitelyGenerate($new_supported_types);
|
|
||||||
}
|
|
||||||
|
|
||||||
$console->writeOut(
|
$this->generate($generators);
|
||||||
"%s\n%s:\n%s\n",
|
|
||||||
pht('None of the input types were supported.'),
|
|
||||||
pht('The supported types are'),
|
|
||||||
implode("\n", array_keys($supported_types)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function infinitelyGenerate(array $supported_types) {
|
protected function generate(array $generators) {
|
||||||
$console = PhutilConsole::getConsole();
|
$viewer = $this->getViewer();
|
||||||
|
|
||||||
if (count($supported_types) == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$console->writeOut(
|
|
||||||
"%s: %s\n",
|
|
||||||
pht('GENERATING'),
|
|
||||||
implode(', ', array_keys($supported_types)));
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
$type = $supported_types[array_rand($supported_types)];
|
$generator = $generators[array_rand($generators)];
|
||||||
$admin = $this->getViewer();
|
|
||||||
|
|
||||||
$taskgen = newv($type, array());
|
$object = $generator->generateObject();
|
||||||
$object = $taskgen->generate();
|
$object_phid = $object->getPHID();
|
||||||
$handle = id(new PhabricatorHandleQuery())
|
|
||||||
->setViewer($admin)
|
|
||||||
->withPHIDs(array($object->getPHID()))
|
|
||||||
->executeOne();
|
|
||||||
|
|
||||||
$console->writeOut(
|
$handles = $viewer->loadHandles(array($object_phid));
|
||||||
"%s: %s\n",
|
|
||||||
pht('Generated %s', $handle->getTypeName()),
|
|
||||||
$handle->getFullName());
|
|
||||||
|
|
||||||
usleep(200000);
|
echo tsprintf(
|
||||||
|
"%s\n",
|
||||||
|
pht(
|
||||||
|
'Generated "%s": %s',
|
||||||
|
$handles[$object_phid]->getTypeName(),
|
||||||
|
$handles[$object_phid]->getFullName()));
|
||||||
|
|
||||||
|
sleep(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,11 @@
|
||||||
final class PhabricatorManiphestTaskTestDataGenerator
|
final class PhabricatorManiphestTaskTestDataGenerator
|
||||||
extends PhabricatorTestDataGenerator {
|
extends PhabricatorTestDataGenerator {
|
||||||
|
|
||||||
public function generate() {
|
public function getGeneratorName() {
|
||||||
|
return pht('Maniphest Tasks');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function generateObject() {
|
||||||
$author_phid = $this->loadPhabrictorUserPHID();
|
$author_phid = $this->loadPhabrictorUserPHID();
|
||||||
$author = id(new PhabricatorUser())
|
$author = id(new PhabricatorUser())
|
||||||
->loadOneWhere('phid = %s', $author_phid);
|
->loadOneWhere('phid = %s', $author_phid);
|
||||||
|
|
|
@ -3,13 +3,17 @@
|
||||||
final class PhabricatorPasteTestDataGenerator
|
final class PhabricatorPasteTestDataGenerator
|
||||||
extends PhabricatorTestDataGenerator {
|
extends PhabricatorTestDataGenerator {
|
||||||
|
|
||||||
|
public function getGeneratorName() {
|
||||||
|
return pht('Pastes');
|
||||||
|
}
|
||||||
|
|
||||||
// Better Support for this in the future
|
// Better Support for this in the future
|
||||||
public $supportedLanguages = array(
|
public $supportedLanguages = array(
|
||||||
'Java' => 'java',
|
'Java' => 'java',
|
||||||
'PHP' => 'php',
|
'PHP' => 'php',
|
||||||
);
|
);
|
||||||
|
|
||||||
public function generate() {
|
public function generateObject() {
|
||||||
$author = $this->loadPhabrictorUser();
|
$author = $this->loadPhabrictorUser();
|
||||||
$authorphid = $author->getPHID();
|
$authorphid = $author->getPHID();
|
||||||
$language = $this->generateLanguage();
|
$language = $this->generateLanguage();
|
||||||
|
|
|
@ -3,7 +3,11 @@
|
||||||
final class PhabricatorPeopleTestDataGenerator
|
final class PhabricatorPeopleTestDataGenerator
|
||||||
extends PhabricatorTestDataGenerator {
|
extends PhabricatorTestDataGenerator {
|
||||||
|
|
||||||
public function generate() {
|
public function getGeneratorName() {
|
||||||
|
return pht('User Accounts');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function generateObject() {
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -3,7 +3,11 @@
|
||||||
final class PhabricatorPholioMockTestDataGenerator
|
final class PhabricatorPholioMockTestDataGenerator
|
||||||
extends PhabricatorTestDataGenerator {
|
extends PhabricatorTestDataGenerator {
|
||||||
|
|
||||||
public function generate() {
|
public function getGeneratorName() {
|
||||||
|
return pht('Pholio Mocks');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function generateObject() {
|
||||||
$author_phid = $this->loadPhabrictorUserPHID();
|
$author_phid = $this->loadPhabrictorUserPHID();
|
||||||
$author = id(new PhabricatorUser())
|
$author = id(new PhabricatorUser())
|
||||||
->loadOneWhere('phid = %s', $author_phid);
|
->loadOneWhere('phid = %s', $author_phid);
|
||||||
|
|
|
@ -5,7 +5,11 @@ final class PhabricatorProjectTestDataGenerator
|
||||||
|
|
||||||
private $xactions = array();
|
private $xactions = array();
|
||||||
|
|
||||||
public function generate() {
|
public function getGeneratorName() {
|
||||||
|
return pht('Projects');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function generateObject() {
|
||||||
$title = $this->generateTitle();
|
$title = $this->generateTitle();
|
||||||
$author = $this->loadPhabrictorUser();
|
$author = $this->loadPhabrictorUser();
|
||||||
$author_phid = $author->getPHID();
|
$author_phid = $author->getPHID();
|
||||||
|
|
Loading…
Reference in a new issue