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
|
||||
# limitations under the License.
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
import optparse
|
||||
import sys
|
||||
|
||||
import bindep.depends
|
||||
|
@ -27,32 +27,37 @@ logging.basicConfig(
|
|||
|
||||
|
||||
def main(depends=None):
|
||||
usage = "Usage: %prog [options] [profile]..."
|
||||
parser = optparse.OptionParser(
|
||||
usage=usage, version="%%prog %s" % bindep.version)
|
||||
parser.add_option(
|
||||
"-b", "--brief", action="store_true", dest="brief",
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
"--brief", "-b", action="store_true", dest="brief",
|
||||
help="List only missing packages one per line.")
|
||||
parser.add_option(
|
||||
"-f", "--file", action="store", type="string", dest="filename",
|
||||
default="",
|
||||
parser.add_argument(
|
||||
"--file", "-f", action="store", dest="filename", default="",
|
||||
help="Package list file (default: bindep.txt or "
|
||||
"other-requirements.txt).")
|
||||
parser.add_option(
|
||||
"other-requirements.txt).")
|
||||
parser.add_argument(
|
||||
"--profiles", action="store_true",
|
||||
help="List the platform and configuration profiles.")
|
||||
parser.add_option(
|
||||
"-l", "--list_all", dest="list_all", choices=["newline", "csv"],
|
||||
type="choice", action="store",
|
||||
parser.add_argument(
|
||||
"--list_all", "-l", dest="list_all", action="store",
|
||||
choices=["newline", "csv"],
|
||||
help="List all dependencies for this platform and profile."
|
||||
" Pass in either 'newline' or 'csv' to specify the format"
|
||||
" 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:
|
||||
depends = bindep.depends.get_depends(opts.filename)
|
||||
depends = bindep.depends.get_depends(args.filename)
|
||||
if not depends:
|
||||
return 1
|
||||
if opts.profiles:
|
||||
|
||||
if args.profiles:
|
||||
logging.info("Platform profiles:")
|
||||
for profile in depends.platform_profiles():
|
||||
logging.info("%s", profile)
|
||||
|
@ -60,35 +65,34 @@ def main(depends=None):
|
|||
logging.info("Configuration profiles:")
|
||||
for profile in depends.profiles():
|
||||
logging.info("%s", profile)
|
||||
else:
|
||||
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
|
||||
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__':
|
||||
sys.exit(main())
|
||||
|
|
Loading…
Reference in New Issue