Top Level Namespace
Defined Under Namespace
Modules: OnceOnly
Constant Summary collapse
- USAGE =
Once-only Run applications once with the same inputs
- Author
-
Pjotr Prins
- Copyright
-
2013
<<EOB once-only runs a command once only when inputs don't change! Usage: -d path change to directory before executing --copy copy files to hash dir first --pbs [opts] convert to PBS command with optional options --skip|--out file skip making a checksum of the named file (multiple allowed) --skip-exe skip making a checksum of the executable command/script --skip-cli skip making a checksum of full command line --skip-regex regex skip making checksumes of filenames that match the regex (multiple allowed) --skip-glob regex skip making checksumes of filenames that match the glob (multiple allowed) --include|--in file include input filename for making the checksums (file should exist) --precalc file use precalculated Hash values (extension .md5) -v increase verbosity -q run quietly --debug give debug information --dry-run do not execute command --ignore-lock ignore locked files (they expire normally after 5 hours) --force force execute command Examples: Basic use once-only /bin/cat README.md With PBS once-only --pbs /bin/cat README.md Using redirects echo "/bin/cat README.md > tmp.out" | ./bin/once-only --skip tmp.out See the README for more examples! EOB
- VERSION_FILENAME =
File.join(gempath,'VERSION')
Instance Method Summary collapse
Instance Method Details
#exit_error(errval = 1, msg = nil) ⇒ Object
65 66 67 68 69 |
# File 'bin/once-only', line 65 def exit_error errval = 1, msg = nil $stderr.print msg if msg $stderr.print "\n**ERROR** once-only returned error #{errval}\n" exit errval end |
#parse_args(args) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'bin/once-only', line 71 def parse_args(args) = { :precalc => [], :skip => [], :skip_regex => [], :skip_glob => [], :include => [] } consume = lambda { |args| if not args[0] # check stdin cmd = $stdin.gets exit_error(1,"Empty command on STDIN") if cmd == nil $stderr.print "Command (STDIN): ",cmd,"\n" [:stdin] = true return cmd.split(/\s/) end return args if File.exist?(args[0]) # reached the executable command case args[0] when '-d' [:dir] = File.(args[1]) consume.call(args[2..-1]) when '--pbs' if args[1] and args[1] =~ /\s+/ # optional PBS argument with spacing [:pbs] = args[1] consume.call(args[2..-1]) else [:pbs] = "''" consume.call(args[1..-1]) end when '--skip', '--out' [:skip] << args[1] consume.call(args[2..-1]) when '--skip-exe' [:skip_exe] = true consume.call(args[1..-1]) when '--skip-cli' [:skip_cli] = true consume.call(args[1..-1]) when '--skip-regex' [:skip_regex] << args[1] consume.call(args[2..-1]) when '--skip-glob' [:skip_glob] << args[1] consume.call(args[2..-1]) when '--include', '--in', '-in' [:include] << args[1] consume.call(args[2..-1]) when '--copy' [:copy] = true consume.call(args[1..-1]) when '--precalc' p args [:precalc] << args[1] consume.call(args[2..-1]) when '-h', '--help' print USAGE exit 1 when '--debug' [:debug] = true consume.call(args[1..-1]) when '-v' [:verbose] = true consume.call(args[1..-1]) when '-q' [:quiet] = true consume.call(args[1..-1]) when '--dry-run' [:dry_run] = true consume.call(args[1..-1]) when '--ignore-lock' [:ignore_lock] = true consume.call(args[1..-1]) when '--force' [:force] = true consume.call(args[1..-1]) else $stderr.print "**ERROR** Can not parse arguments",args exit_error(1) end } return consume.call(args), end |