Merge "Move to argparse"
This commit is contained in:
commit
cec3a7576b
|
@ -15,8 +15,8 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
import optparse
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import bindep.depends
|
import bindep.depends
|
||||||
|
@ -27,32 +27,37 @@ logging.basicConfig(
|
||||||
|
|
||||||
|
|
||||||
def main(depends=None):
|
def main(depends=None):
|
||||||
usage = "Usage: %prog [options] [profile]..."
|
parser = argparse.ArgumentParser()
|
||||||
parser = optparse.OptionParser(
|
parser.add_argument(
|
||||||
usage=usage, version="%%prog %s" % bindep.version)
|
"--brief", "-b", action="store_true", dest="brief",
|
||||||
parser.add_option(
|
|
||||||
"-b", "--brief", action="store_true", dest="brief",
|
|
||||||
help="List only missing packages one per line.")
|
help="List only missing packages one per line.")
|
||||||
parser.add_option(
|
parser.add_argument(
|
||||||
"-f", "--file", action="store", type="string", dest="filename",
|
"--file", "-f", action="store", dest="filename", default="",
|
||||||
default="",
|
|
||||||
help="Package list file (default: bindep.txt or "
|
help="Package list file (default: bindep.txt or "
|
||||||
"other-requirements.txt).")
|
"other-requirements.txt).")
|
||||||
parser.add_option(
|
parser.add_argument(
|
||||||
"--profiles", action="store_true",
|
"--profiles", action="store_true",
|
||||||
help="List the platform and configuration profiles.")
|
help="List the platform and configuration profiles.")
|
||||||
parser.add_option(
|
parser.add_argument(
|
||||||
"-l", "--list_all", dest="list_all", choices=["newline", "csv"],
|
"--list_all", "-l", dest="list_all", action="store",
|
||||||
type="choice", action="store",
|
choices=["newline", "csv"],
|
||||||
help="List all dependencies for this platform and profile."
|
help="List all dependencies for this platform and profile."
|
||||||
" Pass in either 'newline' or 'csv' to specify the format"
|
" Pass in either 'newline' or 'csv' to specify the format"
|
||||||
" of the output.")
|
" of the output.")
|
||||||
opts, args = parser.parse_args()
|
parser.add_argument(
|
||||||
|
'profile', nargs='*', default=["default"],
|
||||||
|
help="Extra profiles to match when checking for packages.")
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'--version', action='version', version="%%(prog)s %s" % bindep.version)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
if depends is None:
|
if depends is None:
|
||||||
depends = bindep.depends.get_depends(opts.filename)
|
depends = bindep.depends.get_depends(args.filename)
|
||||||
if not depends:
|
if not depends:
|
||||||
return 1
|
return 1
|
||||||
if opts.profiles:
|
|
||||||
|
if args.profiles:
|
||||||
logging.info("Platform profiles:")
|
logging.info("Platform profiles:")
|
||||||
for profile in depends.platform_profiles():
|
for profile in depends.platform_profiles():
|
||||||
logging.info("%s", profile)
|
logging.info("%s", profile)
|
||||||
|
@ -60,35 +65,34 @@ def main(depends=None):
|
||||||
logging.info("Configuration profiles:")
|
logging.info("Configuration profiles:")
|
||||||
for profile in depends.profiles():
|
for profile in depends.profiles():
|
||||||
logging.info("%s", profile)
|
logging.info("%s", profile)
|
||||||
else:
|
return 0
|
||||||
if args:
|
|
||||||
profiles = args
|
|
||||||
else:
|
|
||||||
profiles = ["default"]
|
|
||||||
profiles = profiles + depends.platform_profiles()
|
|
||||||
rules = depends.active_rules(profiles)
|
|
||||||
if opts.list_all:
|
|
||||||
depends.list_all_packages(rules, opts.list_all)
|
|
||||||
return 0
|
|
||||||
errors = depends.check_rules(rules)
|
|
||||||
for error in errors:
|
|
||||||
if error[0] == 'missing':
|
|
||||||
if opts.brief:
|
|
||||||
logging.info("%s", "\n".join(error[1]))
|
|
||||||
else:
|
|
||||||
logging.info("Missing packages:")
|
|
||||||
logging.info(" %s", " ".join(error[1]))
|
|
||||||
if error[0] == 'badversion':
|
|
||||||
if not opts.brief:
|
|
||||||
logging.info("Bad versions of installed packages:")
|
|
||||||
for pkg, constraint, version in error[1]:
|
|
||||||
logging.info(
|
|
||||||
" %s version %s does not match %s",
|
|
||||||
pkg, version, constraint)
|
|
||||||
if errors:
|
|
||||||
return 1
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
profiles = args.profile + depends.platform_profiles()
|
||||||
|
rules = depends.active_rules(profiles)
|
||||||
|
|
||||||
|
if args.list_all:
|
||||||
|
depends.list_all_packages(rules, args.list_all)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
errors = depends.check_rules(rules)
|
||||||
|
for error in errors:
|
||||||
|
if error[0] == 'missing':
|
||||||
|
if args.brief:
|
||||||
|
logging.info("%s", "\n".join(error[1]))
|
||||||
|
else:
|
||||||
|
logging.info("Missing packages:")
|
||||||
|
logging.info(" %s", " ".join(error[1]))
|
||||||
|
if error[0] == 'badversion':
|
||||||
|
if not args.brief:
|
||||||
|
logging.info("Bad versions of installed packages:")
|
||||||
|
for pkg, constraint, version in error[1]:
|
||||||
|
logging.info(
|
||||||
|
" %s version %s does not match %s",
|
||||||
|
pkg, version, constraint)
|
||||||
|
if errors:
|
||||||
|
return 1
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
|
|
Loading…
Reference in New Issue