Skip to content

Commit

Permalink
Autoformat source code
Browse files Browse the repository at this point in the history
  • Loading branch information
ximion committed May 29, 2023
1 parent 966ac1f commit 86d2010
Show file tree
Hide file tree
Showing 41 changed files with 3,491 additions and 3,166 deletions.
10 changes: 10 additions & 0 deletions autoformat.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -e

BASEDIR=$(dirname "$0")
cd $BASEDIR

export DC=ldc2
dub fetch dfmt

exec dub run --compiler=ldc2 dfmt -- -i -c . src/
92 changes: 48 additions & 44 deletions src/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import asgen.config;
import asgen.engine;
import asgen.defines : ASGEN_VERSION;


// dfmt off
private immutable helpText =
"Usage:
appstream-generator <subcommand> [OPTION...] - AppStream Generator.
Expand Down Expand Up @@ -59,6 +59,7 @@ Application Options:
version (unittest) {
void main () {}
} else {
// dfmt on

private void createXdgRuntimeDir ()
{
Expand All @@ -73,22 +74,22 @@ private void createXdgRuntimeDir ()
import std.conv : octal;

immutable xdgRuntimeDir = environment.get("XDG_RUNTIME_DIR");
if (xdgRuntimeDir.empty || !xdgRuntimeDir.startsWith ("/"))
if (xdgRuntimeDir.empty || !xdgRuntimeDir.startsWith("/"))
return; // nothing to do here
if (xdgRuntimeDir.exists)
return; // directory already exists

try {
mkdirRecurse (xdgRuntimeDir);
mkdirRecurse(xdgRuntimeDir);
xdgRuntimeDir.setAttributes(octal!700);
} catch (Exception e) {
logDebug ("Unable to create XDG runtime dir: %s", e.msg);
logDebug("Unable to create XDG runtime dir: %s", e.msg);
return;
}
logDebug ("Created missing XDG runtime dir: %s", xdgRuntimeDir);
logDebug("Created missing XDG runtime dir: %s", xdgRuntimeDir);
}

void main(string[] args)
void main (string[] args)
{
string command;
bool verbose;
Expand All @@ -100,6 +101,7 @@ void main(string[] args)
string configFname;

// parse command-line options
// dfmt off
try {
getopt (args,
"help|h", &showHelp,
Expand All @@ -113,117 +115,119 @@ void main(string[] args)
writeln ("Unable to parse parameters: ", e.msg);
exit (1);
}
// dfmt on

if (showHelp) {
writeln (helpText);
writeln(helpText);
return;
}

if (showVersion) {
writeln ("Generator version: ", ASGEN_VERSION);
writeln("Generator version: ", ASGEN_VERSION);
return;
}

if (args.length < 2) {
writeln ("No subcommand specified!");
writeln("No subcommand specified!");
return;
}

// globally enable verbose mode, if requested
if (verbose)
asgen.logging.setVerbose (true);
asgen.logging.setVerbose(true);

auto conf = Config.get ();
auto conf = Config.get();
if (configFname.empty) {
// if we don't have an explicit config file set, and also no
// workspace, take the current directory
if (wdir.empty)
wdir = getcwd ();
configFname = buildPath (wdir, "asgen-config.json");
wdir = getcwd();
configFname = buildPath(wdir, "asgen-config.json");
}

try {
conf.loadFromFile (configFname, wdir, exportDir);
conf.loadFromFile(configFname, wdir, exportDir);
} catch (Exception e) {
writefln ("Unable to load configuration: %s", e.msg);
exit (4);
writefln("Unable to load configuration: %s", e.msg);
exit(4);
}
scope (exit) {
// ensure we clean up when the generator is done
import std.file : rmdirRecurse, exists;

if (conf.getTmpDir.exists)
rmdirRecurse (conf.getTmpDir ());
rmdirRecurse (conf.getTmpDir());
}

// ensure runtime dir exists, in case we are installed with Snappy
createXdgRuntimeDir ();
createXdgRuntimeDir();

auto engine = new Engine ();
auto engine = new Engine();
engine.forced = forceAction;

void ensureSuiteAndOrSectionParameterSet ()
{
if (args.length < 3) {
writeln ("Invalid number of parameters: You need to specify at least a suite name.");
exit (1);
writeln("Invalid number of parameters: You need to specify at least a suite name.");
exit(1);
}
if (args.length > 4) {
writeln ("Invalid number of parameters: You need to specify a suite name and (optionally) a section name.");
exit (1);
writeln("Invalid number of parameters: You need to specify a suite name and (optionally) a section name.");
exit(1);
}
}

command = args[1];
switch (command) {
case "run":
case "process":
ensureSuiteAndOrSectionParameterSet ();
ensureSuiteAndOrSectionParameterSet();
if (args.length == 3)
engine.run (args[2]);
engine.run(args[2]);
else
engine.run (args[2], args[3]);
engine.run(args[2], args[3]);
break;
case "process-file":
if (args.length < 5) {
writeln ("Invalid number of parameters: You need to specify a suite name, a section name and at least one file to process.");
exit (1);
writeln("Invalid number of parameters: You need to specify a suite name, a section name and at least one file to process.");
exit(1);
}
engine.processFile (args[2], args[3], args[4..$]);
engine.processFile(args[2], args[3], args[4 .. $]);
break;
case "publish":
ensureSuiteAndOrSectionParameterSet ();
ensureSuiteAndOrSectionParameterSet();
if (args.length == 3)
engine.publish (args[2]);
engine.publish(args[2]);
else
engine.publish (args[2], args[3]);
engine.publish(args[2], args[3]);
break;
case "cleanup":
engine.runCleanup ();
engine.runCleanup();
break;
case "remove-found":
if (args.length != 3) {
writeln ("Invalid number of parameters: You need to specify a suite name.");
exit (1);
writeln("Invalid number of parameters: You need to specify a suite name.");
exit(1);
}
engine.removeHintsComponents (args[2]);
engine.removeHintsComponents(args[2]);
break;
case "forget":
if (args.length != 3) {
writeln ("Invalid number of parameters: You need to specify a package-id (partial IDs are allowed).");
exit (1);
writeln("Invalid number of parameters: You need to specify a package-id (partial IDs are allowed).");
exit(1);
}
engine.forgetPackage (args[2]);
engine.forgetPackage(args[2]);
break;
case "info":
if (args.length != 3) {
writeln ("Invalid number of parameters: You need to specify a package-id.");
exit (1);
writeln("Invalid number of parameters: You need to specify a package-id.");
exit(1);
}
engine.printPackageInfo (args[2]);
engine.printPackageInfo(args[2]);
break;
default:
writeln (format ("The command '%s' is unknown.", command));
exit (1);
writeln(format("The command '%s' is unknown.", command));
exit(1);
}
}

Expand Down
53 changes: 31 additions & 22 deletions src/asgen/backends/alpinelinux/apkindexutils.d
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ struct ApkIndexBlock {
string pkgversion;
string pkgdesc;

@property string archiveName () {
return format ("%s-%s.apk", this.pkgname, this.pkgversion);
@property string archiveName ()
{
return format("%s-%s.apk", this.pkgname, this.pkgversion);
}
}

Expand All @@ -44,23 +45,29 @@ struct ApkIndexBlockRange {
this.getNextBlock();
}

@property ApkIndexBlock front () const {
@property ApkIndexBlock front () const
{
return this.currentBlock;
}

@property bool empty () {
@property bool empty ()
{
return this.m_empty;
}

void popFront ()
{
this.getNextBlock ();
this.getNextBlock();
}

@property ApkIndexBlockRange save () { return this; }
@property ApkIndexBlockRange save ()
{
return this;
}

private:
void getNextBlock () {
void getNextBlock ()
{
string[] completePair;
uint iterations = 0;

Expand All @@ -70,25 +77,27 @@ private:
if (currentLine == "") {
// next block for next package started
break;
} if (currentLine.canFind (":")) {
}
if (currentLine.canFind(":")) {
if (completePair.empty) {
completePair = [currentLine];
continue;
}

auto pair = completePair.join (" ").split (":");
this.setCurrentBlock (pair[0], pair[1]);
auto pair = completePair.join(" ").split(":");
this.setCurrentBlock(pair[0], pair[1]);
completePair = [currentLine];
} else {
completePair ~= currentLine.strip ();
completePair ~= currentLine.strip();
}
}

this.lineDelta += iterations;
this.m_empty = this.lineDelta == this.lines.length;
}

void setCurrentBlock (string key, string value) {
void setCurrentBlock (string key, string value)
{
switch (key) {
case "A":
this.currentBlock.arch = value;
Expand Down Expand Up @@ -117,34 +126,34 @@ private:
uint lineDelta;
}

static assert (isForwardRange!ApkIndexBlockRange);
static assert(isForwardRange!ApkIndexBlockRange);

/**
* Download apkindex if required. Returns the path to the local copy of the APKINDEX.
*/
immutable (string) downloadIfNecessary (const string prefix,
const string destPrefix,
const string srcFileName,
const string destFileName)
immutable(string) downloadIfNecessary (const string prefix,
const string destPrefix,
const string srcFileName,
const string destFileName)
{
auto downloader = Downloader.get;

immutable filePath = buildPath (prefix, srcFileName);
immutable destFilePath = buildPath (destPrefix, destFileName);
immutable filePath = buildPath(prefix, srcFileName);
immutable destFilePath = buildPath(destPrefix, destFileName);

if (filePath.isRemote) {
try {
downloader.downloadFile (filePath, destFilePath);
downloader.downloadFile(filePath, destFilePath);

return destFilePath;
} catch (DownloadException e) {
logDebug ("Unable to download: %s", e.msg);
logDebug("Unable to download: %s", e.msg);
}
} else {
if (filePath.exists)
return filePath;
}

/* all extensions failed, so we failed */
throw new Exception ("Could not obtain any file matching %s".format (buildPath (prefix, srcFileName)));
throw new Exception("Could not obtain any file matching %s".format(buildPath(prefix, srcFileName)));
}
Loading

0 comments on commit 86d2010

Please sign in to comment.