()
| 474 | |
| 475 | |
| 476 | def main(): |
| 477 | config = {"addr": "127.0.0.1", "port": "7227", "language": "en"} |
| 478 | try: |
| 479 | config["language"] = os.environ["LANG"][0:2] |
| 480 | except: |
| 481 | pass |
| 482 | |
| 483 | if (not exists(join(pypath, "locale", config["language"]))) or config["language"] == "": |
| 484 | config["language"] = "en" |
| 485 | |
| 486 | configFile = ConfigParser.ConfigParser() |
| 487 | configFile.read(join(homedir, ".pyloadcli")) |
| 488 | |
| 489 | if configFile.has_section("cli"): |
| 490 | for opt in configFile.items("cli"): |
| 491 | config[opt[0]] = opt[1] |
| 492 | |
| 493 | gettext.setpaths([join(os.sep, "usr", "share", "pyload", "locale"), None]) |
| 494 | translation = gettext.translation("pyLoadCli", join(pypath, "locale"), |
| 495 | languages=[config["language"],"en"],fallback=True) |
| 496 | translation.install(unicode=True) |
| 497 | |
| 498 | interactive = False |
| 499 | command = None |
| 500 | username = "" |
| 501 | password = "" |
| 502 | |
| 503 | shortOptions = 'iu:p:a:hcl:' |
| 504 | longOptions = ['interactive', "username=", "pw=", "address=", "port=", "help", "commands", "language="] |
| 505 | |
| 506 | try: |
| 507 | opts, extraparams = getopt(sys.argv[1:], shortOptions, longOptions) |
| 508 | for option, params in opts: |
| 509 | if option in ("-i", "--interactive"): |
| 510 | interactive = True |
| 511 | elif option in ("-u", "--username"): |
| 512 | username = params |
| 513 | elif option in ("-a", "--address"): |
| 514 | config["addr"] = params |
| 515 | elif option in ("-p", "--port"): |
| 516 | config["port"] = params |
| 517 | elif option in ("-l", "--language"): |
| 518 | config["language"] = params |
| 519 | gettext.setpaths([join(os.sep, "usr", "share", "pyload", "locale"), None]) |
| 520 | translation = gettext.translation("pyLoadCli", join(pypath, "locale"), |
| 521 | languages=[config["language"],"en"],fallback=True) |
| 522 | translation.install(unicode=True) |
| 523 | elif option in ("-h", "--help"): |
| 524 | print_help(config) |
| 525 | exit() |
| 526 | elif option in ("--pw"): |
| 527 | password = params |
| 528 | elif option in ("-c", "--comands"): |
| 529 | print_commands() |
| 530 | exit() |
| 531 | |
| 532 | except GetoptError: |
| 533 | print 'Unknown Argument(s) "%s"' % " ".join(sys.argv[1:]) |
no test coverage detected