| |
@@ -1,6 +1,7 @@
|
| |
#!/usr/bin/python3
|
| |
import argparse
|
| |
import operator
|
| |
+ import glob
|
| |
import re
|
| |
import sys
|
| |
from subprocess import CalledProcessError, PIPE, Popen, TimeoutExpired
|
| |
@@ -77,6 +78,11 @@
|
| |
raise ProcError(process.args, retcode, stdout=stdout, stderr=stderr)
|
| |
return CompletedProcess(process.args, retcode, stdout, stderr)
|
| |
|
| |
+ def error(message, exception=None):
|
| |
+ print(message, file=sys.stderr)
|
| |
+ if exception is not None:
|
| |
+ print(e, file=sys.stderr)
|
| |
+ sys.exit(1)
|
| |
|
| |
class Spec(object):
|
| |
"""Object to encapsulate a spec file and provide the info we want."""
|
| |
@@ -101,9 +107,7 @@
|
| |
try:
|
| |
proc = run(cmdline)
|
| |
except ProcError as e:
|
| |
- print('Error: rpmspec call failed!')
|
| |
- print(e)
|
| |
- sys.exit(1)
|
| |
+ error('Error: rpmspec call failed!', e)
|
| |
for line in proc.stdout.splitlines():
|
| |
self.parseline(line)
|
| |
|
| |
@@ -186,8 +190,7 @@
|
| |
try:
|
| |
out.append(int(j))
|
| |
except ValueError:
|
| |
- print('Invalid value: {}'.format(j))
|
| |
- sys.exit(1)
|
| |
+ error('Invalid value: {}'.format(j))
|
| |
return out
|
| |
|
| |
parser = argparse.ArgumentParser(
|
| |
@@ -196,7 +199,7 @@
|
| |
epilog="Files:\n/etc/rpmdevrools/curlrc\n optional curl(1) configuration",
|
| |
formatter_class=argparse.RawDescriptionHelpFormatter,
|
| |
add_help=False)
|
| |
- parser.add_argument('spec', help='The specfile to be parsed')
|
| |
+ parser.add_argument('spec', help='The specfile to be parsed', nargs='?')
|
| |
|
| |
mode = parser.add_argument_group('Operating mode')
|
| |
mode1 = mode.add_mutually_exclusive_group()
|
| |
@@ -241,6 +244,14 @@
|
| |
|
| |
opts = parser.parse_args()
|
| |
|
| |
+ if opts.spec is None:
|
| |
+ files = glob.glob('*.spec')
|
| |
+ if not files:
|
| |
+ error("Spec-file was not specified and current directory does not contain any")
|
| |
+ if len(files) > 1:
|
| |
+ error("Spec-file was not specified and current directory contains multiple")
|
| |
+ opts.spec = files[0]
|
| |
+
|
| |
# Can argparse do this for me?
|
| |
if opts.allsources or opts.allpatches:
|
| |
opts.all = False
|
| |
@@ -272,8 +283,7 @@
|
| |
try:
|
| |
run(['rpmspec', '--version'])
|
| |
except CalledProcessError:
|
| |
- print("rpmspec does not appear to be installed.")
|
| |
- sys.exit(1)
|
| |
+ error("rpmspec does not appear to be installed.")
|
| |
|
| |
|
| |
def expand_sourcedir_macro(spec):
|
| |
@@ -285,9 +295,7 @@
|
| |
try:
|
| |
proc = run(cmdline)
|
| |
except ProcError as e:
|
| |
- print('Error: rpm call failed!')
|
| |
- print(e)
|
| |
- sys.exit(1)
|
| |
+ error('Error: rpm call failed!')
|
| |
return proc.stdout.strip()
|
| |
|
| |
|
| |