Fixes and enhancements...

- If an IB file is deleted, the corresponding cib is no longer deleted.
- In watch mode, the first time through no conversion is done if an IB file has a corresponding cib file with a later mtime.
- In watch mode, an add does not convert if there is a corresponding cib file with a later mtime.
- When catching exceptions, deal correctly with both CPException and strings.
This commit is contained in:
Aparajita Fishman
2011-04-06 04:34:56 -04:00
parent af6d38fd16
commit 73746e00b0
2 changed files with 61 additions and 44 deletions
+51 -35
View File
@@ -60,7 +60,7 @@ function main(args)
}
catch (anException)
{
CPLog.fatal([anException reason]);
CPLog.fatal(exceptionReason(anException));
OS.exit(1);
}
}
@@ -125,7 +125,7 @@ function convert(options, inputFile)
}
catch (anException)
{
CPLog.fatal([anException reason]);
CPLog.fatal(exceptionReason(anException));
return false;
}
}
@@ -133,49 +133,72 @@ function convert(options, inputFile)
function watch(options)
{
var verbosity = options.quiet ? -1 : options.verbosity,
directory = options.args[0];
watchDir = options.args[0];
if (!directory)
directory = FILE.canonical(FILE.isDirectory("Resources") ? "Resources" : ".");
if (!watchDir)
watchDir = FILE.canonical(FILE.isDirectory("Resources") ? "Resources" : ".");
else
{
directory = FILE.canonical(directory);
watchDir = FILE.canonical(watchDir);
if (FILE.basename(directory) !== "Resources")
if (FILE.basename(watchDir) !== "Resources")
{
var path = FILE.join(directory, "Resources");
var path = FILE.join(watchDir, "Resources");
if (FILE.isDirectory(path))
directory = path;
watchDir = path;
}
}
if (!FILE.isDirectory(directory))
fail("Cannot find the directory: " + directory);
if (!FILE.isDirectory(watchDir))
fail("Cannot find the directory: " + watchDir);
// Turn on info messages
setLogLevel(1);
CPLog.info("Watching: " + CPLogColorize(directory, "debug"));
var nibs = new FileList(FILE.join(watchDir, "*.[nx]ib")).items(),
count = nibs.length;
// First time through only IB files with no corresponding cib
// or a cib with an earlier mtime are converted.
while (count--)
{
var nib = nibs[count],
cib = nib.substr(0, nib.length - 4) + ".cib";
if (FILE.exists(cib) && (FILE.mtime(nib) - FILE.mtime(cib)) < 0)
nibInfo[nib] = FILE.mtime(nib);
}
CPLog.info("Watching: " + CPLogColorize(watchDir, "debug"));
CPLog.info("Press Control-C to stop...");
while (true)
{
var modifiedNibs = getModifiedNibs(directory);
var modifiedNibs = getModifiedNibs(watchDir);
for (var i = 0; i < modifiedNibs.length; ++i)
{
var action = modifiedNibs[i][0],
path = modifiedNibs[i][1],
label = action === "add" ? "Added:" : "Modified:",
nib = modifiedNibs[i][1],
label = action === "add" ? "Added" : "Modified",
level = action === "add" ? "info" : "debug";
CPLog.info(">> %s %s", CPLogColorize(label, level), path);
CPLog.info(">> %s: %s", CPLogColorize(label, level), nib);
// Don't convert an add if there is an existing cib with a later mtime
if (action === "add")
{
var cib = nib.substr(0, nib.length - 4) + ".cib";
if (FILE.exists(cib) && (FILE.mtime(nib) - FILE.mtime(cib)) < 0)
continue;
}
// Let the converter log however the user configured it
setLogLevel(verbosity);
var success = convert(options, path);
var success = convert(options, nib);
setLogLevel(1);
@@ -627,25 +650,8 @@ function getModifiedNibs(path)
}
for (var nib in nibInfo)
{
if (nibInfo.hasOwnProperty(nib))
{
CPLog.info(">> %s %s", CPLogColorize("Deleted:", "warn"), nib);
var cib = nib.substr(0, nib.length - 3) + "cib";
if (FILE.exists(cib))
{
if (FILE.isWritable(cib))
{
FILE.remove(cib);
CPLog.warn("Deleted: " + cib);
}
else
CPLog.info("%s could not remove the file: %s", CPLogColorize("Warning:", "warn"), cib);
}
}
}
CPLog.info(">> %s: %s", CPLogColorize("Deleted", "warn"), nib);
nibInfo = newNibInfo;
@@ -699,6 +705,16 @@ function printVersion()
stream.print("<No version info available>");
}
function exceptionReason(exception)
{
if (typeof(exception) === "string")
return exception;
else if (exception.isa && [exception respondsToSelector:@selector(reason)])
return [exception reason];
else
return "An unknown error occurred";
}
function fail(message)
{
[CPException raise:ConverterConversionException reason:message];
+10 -9
View File
@@ -62,7 +62,8 @@ will respond to:
.Bl -tag -hang
.It add, modify
When a new xib/nib file is detected or an existing xib/nib file is modified, it is converted into
a cib file with the same base name.
a cib file with the same base name if there is no corresponding cib file with a later
modification time.
.It delete
When a xib/nib file is deleted, the corresponding cib file is deleted as well.
.El
@@ -129,14 +130,14 @@ this is assumed.
.\"-----------------------------------------------------------------------------------------
.Ss "Themes"
.\"-----------------------------------------------------------------------------------------
To do its conversions accurately,
To do its conversions accurately,
.Nm
needs to access the themes you use. If you are using the standard Aristo theme, there is
nothing extra to do.
.Pp
If you are using a custom default theme, usually you specify this using a
If you are using a custom default theme, usually you specify this using a
.Ar CPDefaultTheme
item in your application's Info.plist. In this case
item in your application's Info.plist. In this case
.Nm
will read the theme name from the Info.plist. If you set the default theme programmatically
and not in the Info.plist, then you should use the
@@ -149,7 +150,7 @@ If you are loading additional themes in your code using:
.Pp
then you should inform
.Nm
about it by passing the theme names as
about it by passing the theme names as
.Fl \-theme Ar name
options, one for each theme that you load.
.Pp
@@ -168,7 +169,7 @@ is displayed.
.It Fl R Pa path
NOTE: This option is for the most part no longer necessary.
.Pp
Specifies the path (relative or absolute) to a directory from which images
Specifies the path (relative or absolute) to a directory from which images
and custom themes are retrieved. Formerly
it was necessary to use this when your xib/nib contained references to images, but now
.Nm
@@ -193,9 +194,9 @@ use this option, as
uses the Info.plist in the application directory, which is inferred from
the input file.
.It Fl \-quiet
Tells
Tells
.Nm
to output nothing. This is useful if you are using
to output nothing. This is useful if you are using
.Nm
in a shell script and are only interested in the return value.
.It Fl \-version
@@ -205,7 +206,7 @@ and immediately exits.
.Nm
in a shell script and are only interested in the return value.
.It Fl h, \-help
Displays
Displays
.Nm
usage and options.
.It Fl F