Skip to content

Commit bf9cb9d

Browse files
tulinkryVladimir Kotal
authored andcommitted
Print to the stream related to the exit code
Python scripts can then gather the output according to the exit code. fixes #2379
1 parent eb782d7 commit bf9cb9d

File tree

4 files changed

+64
-63
lines changed

4 files changed

+64
-63
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/ConfigMerge.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.io.File;
2828
import java.io.IOException;
2929
import java.io.OutputStream;
30+
import java.io.PrintStream;
3031
import java.lang.reflect.Field;
3132
import java.lang.reflect.Method;
3233
import java.lang.reflect.Modifier;
@@ -104,7 +105,7 @@ public static void main(String[] argv) {
104105
getopt.parse();
105106
} catch (ParseException ex) {
106107
System.err.println(name + ": " + ex.getMessage());
107-
b_usage();
108+
b_usage(System.err);
108109
System.exit(1);
109110
}
110111

@@ -115,20 +116,20 @@ public static void main(String[] argv) {
115116
switch (cmd) {
116117
case '?':
117118
case 'h':
118-
a_usage();
119+
a_usage(System.out);
119120
System.exit(0);
120121
break;
121122
default:
122123
System.err.println("Internal Error - Not implemented option: " + (char) cmd);
123-
b_usage();
124+
b_usage(System.err);
124125
System.exit(1);
125126
break;
126127
}
127128
}
128129

129130
int optind = getopt.getOptind();
130131
if (optind < 0 || argv.length - optind != 2) {
131-
a_usage();
132+
a_usage(System.err);
132133
System.exit(1);
133134
}
134135

@@ -160,18 +161,18 @@ public static void main(String[] argv) {
160161
cfgNew.encodeObject(os);
161162
}
162163

163-
private static final void a_usage() {
164-
System.err.println("Usage:");
165-
System.err.println(name + " [-h] <config_file_base> <config_file_new>");
166-
System.err.println();
167-
System.err.println("OPTIONS:");
168-
System.err.println("Help");
169-
System.err.println("-? print this help message");
170-
System.err.println("-h print this help message");
171-
System.err.println();
164+
private static final void a_usage(PrintStream out) {
165+
out.println("Usage:");
166+
out.println(name + " [-h] <config_file_base> <config_file_new>");
167+
out.println();
168+
out.println("OPTIONS:");
169+
out.println("Help");
170+
out.println("-? print this help message");
171+
out.println("-h print this help message");
172+
out.println();
172173
}
173174

174-
private static final void b_usage() {
175-
System.err.println("Maybe try to run " + name + " -h");
175+
private static final void b_usage(PrintStream out) {
176+
out.println("Maybe try to run " + name + " -h");
176177
}
177178
}

opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/Groups.java

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static void main(String[] argv) {
7171
getopt.parse();
7272
} catch (ParseException ex) {
7373
System.err.println("Groups: " + ex.getMessage());
74-
usage();
74+
usage(System.err);
7575
System.exit(1);
7676
}
7777

@@ -88,7 +88,7 @@ public static void main(String[] argv) {
8888
empty = true;
8989
break;
9090
case 'h':
91-
usage();
91+
usage(System.out);
9292
System.exit(0);
9393
break;
9494
case 'i':
@@ -121,12 +121,12 @@ public static void main(String[] argv) {
121121
grouppattern = getopt.getOptarg();
122122
break;
123123
case '?':
124-
usage();
124+
usage(System.out);
125125
System.exit(0);
126126
break;
127127
default:
128128
System.err.println("Internal Error - Not implemented option: " + (char) cmd);
129-
usage();
129+
usage(System.err);
130130
System.exit(1);
131131
break;
132132
}
@@ -145,15 +145,15 @@ public static void main(String[] argv) {
145145
// perform matching
146146
if (parent != null || groupname != null || grouppattern != null) {
147147
System.err.println("Match option should be used without parent|groupname|groupregex options");
148-
usage();
148+
usage(System.err);
149149
System.exit(1);
150150
}
151151
matchGroups(System.out, cfg.getGroups(), match);
152152
} else if (empty) {
153153
// just list the groups
154154
if (parent != null || groupname != null || grouppattern != null) {
155155
System.err.println("Match option should be used without parent|groupname|groupregex options");
156-
usage();
156+
usage(System.err);
157157
System.exit(1);
158158
}
159159
out = prepareOutput(outFile);
@@ -162,12 +162,12 @@ public static void main(String[] argv) {
162162
// perform delete
163163
if (parent != null || grouppattern != null) {
164164
System.err.println("Delete option should be used without parent|groupregex options");
165-
usage();
165+
usage(System.err);
166166
System.exit(1);
167167
}
168168
if (groupname == null) {
169169
System.err.println("You must specify the group name");
170-
usage();
170+
usage(System.err);
171171
System.exit(1);
172172
}
173173
deleteGroup(cfg.getGroups(), groupname);
@@ -188,13 +188,13 @@ public static void main(String[] argv) {
188188
// just list the groups
189189
if (groupname != null) {
190190
System.err.println("List option should be used without groupname options");
191-
usage();
191+
usage(System.err);
192192
System.exit(1);
193193
}
194194
printOut(list, cfg, out);
195195
} else {
196196
System.err.println("Wrong combination of options. See usage.");
197-
usage();
197+
usage(System.err);
198198
System.exit(2);
199199
}
200200
}
@@ -416,40 +416,40 @@ public boolean call(Group g) {
416416
});
417417
}
418418

419-
private static final void usage() {
420-
System.err.println("Usage:");
421-
System.err.println("Groups.java" + " [OPTIONS]");
422-
System.err.println();
423-
System.err.println("OPTIONS:");
424-
System.err.println("Help");
425-
System.err.println("-? print this help message");
426-
System.err.println("-h print this help message");
427-
System.err.println("-v verbose/debug mode");
428-
System.err.println();
429-
System.err.println("Input/Output");
430-
System.err.println("-i /path/to/file input file|default is empty configuration");
431-
System.err.println("-o /path/to/file output file|default is stdout");
432-
System.err.println();
433-
System.err.println("Listing");
434-
System.err.println("-m <project name> performs matching based on given project name");
435-
System.err.println("-l lists all available groups in input file");
436-
System.err.println("-e creates an empty configuration or");
437-
System.err.println(" directly outputs the input file (if given)");
438-
System.err.println();
439-
System.err.println("Modification");
440-
System.err.println("-n <group name> specify group name which should be inserted|updated (requires either -r or -d option)");
441-
System.err.println("-r <group regex> specify group regex pattern (requires -n option)");
442-
System.err.println("-p <parent group> optional parameter for the parent group name (requires -n option)");
443-
System.err.println("-d delete specified group (requires -n option)");
444-
System.err.println();
445-
System.err.println("NOTE: using modification options with -l forces the program to list all\n"
419+
private static final void usage(PrintStream out) {
420+
out.println("Usage:");
421+
out.println("Groups.java" + " [OPTIONS]");
422+
out.println();
423+
out.println("OPTIONS:");
424+
out.println("Help");
425+
out.println("-? print this help message");
426+
out.println("-h print this help message");
427+
out.println("-v verbose/debug mode");
428+
out.println();
429+
out.println("Input/Output");
430+
out.println("-i /path/to/file input file|default is empty configuration");
431+
out.println("-o /path/to/file output file|default is stdout");
432+
out.println();
433+
out.println("Listing");
434+
out.println("-m <project name> performs matching based on given project name");
435+
out.println("-l lists all available groups in input file");
436+
out.println("-e creates an empty configuration or");
437+
out.println(" directly outputs the input file (if given)");
438+
out.println();
439+
out.println("Modification");
440+
out.println("-n <group name> specify group name which should be inserted|updated (requires either -r or -d option)");
441+
out.println("-r <group regex> specify group regex pattern (requires -n option)");
442+
out.println("-p <parent group> optional parameter for the parent group name (requires -n option)");
443+
out.println("-d delete specified group (requires -n option)");
444+
out.println();
445+
out.println("NOTE: using modification options with -l forces the program to list all\n"
446446
+ "available groups after the modification. Output to a file can still be used.");
447-
System.err.println();
448-
System.err.println("Examples");
449-
System.err.println("-i ~/c.xml -l # => list groups");
450-
System.err.println("-n Abcd -r \"abcd.*\" -o ~/c.xml # => add group and print to ~/c.xml");
451-
System.err.println("-i ~/c.xml -m abcdefg # => prints groups which would match this project description");
452-
System.err.println("-i ~/c.xml -d -n Abcd # => deletes group Abcd");
453-
System.err.println("-n Bcde -r \".*bcde.*\" -l # => add group and lists the result");
447+
out.println();
448+
out.println("Examples");
449+
out.println("-i ~/c.xml -l # => list groups");
450+
out.println("-n Abcd -r \"abcd.*\" -o ~/c.xml # => add group and print to ~/c.xml");
451+
out.println("-i ~/c.xml -m abcdefg # => prints groups which would match this project description");
452+
out.println("-i ~/c.xml -d -n Abcd # => deletes group Abcd");
453+
out.println("-n Bcde -r \".*bcde.*\" -l # => add group and lists the result");
454454
}
455455
}

opengrok-tools/src/main/python/opengrok_tools/config_merge.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ def main():
5757
logger.error(cmd.geterroutput())
5858
logger.error("command failed (return code {})".format(ret))
5959
sys.exit(1)
60-
61-
print(cmd.getoutputstr())
60+
else:
61+
print(cmd.getoutputstr())
6262

6363

6464
if __name__ == '__main__':

opengrok-tools/src/main/python/opengrok_tools/groups.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ def main():
4848
logger = logging.getLogger(os.path.basename(sys.argv[0]))
4949

5050
cmd = Java(args.options, classpath=args.jar, java=args.java,
51-
java_opts=args.java_opts,
51+
java_opts=args.java_opts, redirect_stderr=False,
5252
main_class='org.opengrok.indexer.configuration.Groups',
5353
logger=logger)
5454
cmd.execute()
5555
ret = cmd.getretcode()
5656
if ret is None or ret != 0:
57-
logger.error(cmd.getoutputstr())
57+
logger.error(cmd.geterroutput())
5858
logger.error("command failed (return code {})".format(ret))
5959
sys.exit(1)
6060
else:

0 commit comments

Comments
 (0)