def conf_path(self, trans=False): if trans: gettext.setpaths( [join(os.sep, "usr", "share", "pyload", "locale"), None]) translation = gettext.translation( "setup", join(self.path, "locale"), languages=[self.config["general"]["language"], "en"], fallback=True) translation.install(True) print _( "Setting new configpath, current configuration will not be transferred!" ) path = self.ask(_("Config path"), abspath("")) try: path = join(pypath, path) if not exists(path): makedirs(path) f = open(join(pypath, "pyload", "config", "configdir"), "wb") f.write(path) f.close() print _( "Config path changed, setup will now close, please restart to go on." ) print _("Press Enter to exit.") raw_input() exit() except Exception, e: print _("Setting config path failed: %s") % str(e)
def ask_lang(self): langs = self.config.getMetaData("general", "language").type.split(";") self.lang = self.ask(u"Choose your Language / Wähle deine Sprache", "en", langs) gettext.setpaths([join(os.sep, "usr", "share", "pyload", "locale"), None]) translation = gettext.translation("setup", join(self.path, "locale"), languages=[self.lang, "en"], fallback=True) translation.install(True) #l10n Input shorthand for yes self.yes = _("y") #l10n Input shorthand for no self.no = _("n")
def set_user(self): gettext.setpaths( [join(os.sep, "usr", "share", "pyload", "locale"), None]) translation = gettext.translation( "setup", join(self.path, "locale"), languages=[self.config["general"]["language"], "en"], fallback=True) translation.install(True) from pyload.database import DatabaseBackend db = DatabaseBackend(None) db.setup() noaction = True try: while True: print _("Select action") print _("1 - Create/Edit user") print _("2 - List users") print _("3 - Remove user") print _("4 - Quit") action = raw_input("[1]/2/3/4: ") if not action in ("1", "2", "3", "4"): continue elif action == "1": print "" username = self.ask(_("Username"), "User") password = self.ask("", "", password=True) db.addUser(username, password) noaction = False elif action == "2": print "" print _("Users") print "-----" users = db.getAllUserData() noaction = False for user in users.itervalues(): print user.name print "-----" print "" elif action == "3": print "" username = self.ask(_("Username"), "") if username: db.removeUser(username) noaction = False elif action == "4": db.syncSave() break finally: if not noaction: db.shutdown()
def set_user(self): gettext.setpaths([join(os.sep, "usr", "share", "pyload", "locale"), None]) translation = gettext.translation("setup", join(self.path, "locale"), languages=[self.config["general"]["language"], "en"], fallback=True) translation.install(True) from pyload.database import DatabaseBackend db = DatabaseBackend(None) db.setup() noaction = True try: while True: print _("Select action") print _("1 - Create/Edit user") print _("2 - List users") print _("3 - Remove user") print _("4 - Quit") action = raw_input("[1]/2/3/4: ") if not action in ("1", "2", "3", "4"): continue elif action == "1": print "" username = self.ask(_("Username"), "User") password = self.ask("", "", password=True) db.addUser(username, password) noaction = False elif action == "2": print "" print _("Users") print "-----" users = db.getAllUserData() noaction = False for user in users.itervalues(): print user.name print "-----" print "" elif action == "3": print "" username = self.ask(_("Username"), "") if username: db.removeUserByName(username) noaction = False elif action == "4": db.syncSave() break finally: if not noaction: db.shutdown()
def load_translation(name, locale, default="en"): """ Load language and return its translation object or None """ import traceback try: gettext.setpaths([os.path.join(os.sep, "usr", "share", "pyload", "locale"), None]) translation = gettext.translation(name, os.path.join(pypath, "locale"), languages=[locale, default], fallback=True) except Exception: traceback.print_exc() return None else: translation.install(True) return translation
def ask_lang(self): langs = self.config.getMetaData("general", "language").type.split(";") self.lang = self.ask(u"Choose your Language / Wähle deine Sprache", "en", langs) gettext.setpaths( [join(os.sep, "usr", "share", "pyload", "locale"), None]) translation = gettext.translation("setup", join(self.path, "locale"), languages=[self.lang, "en"], fallback=True) translation.install(True) #l10n Input shorthand for yes self.yes = _("y") #l10n Input shorthand for no self.no = _("n")
def load_translation(name, locale, default="en"): """ Load language and return its translation object or None """ import traceback try: gettext.setpaths( [os.path.join(os.sep, "usr", "share", "pyload", "locale"), None]) translation = gettext.translation(name, os.path.join(pypath, "locale"), languages=[locale, default], fallback=True) except Exception: traceback.print_exc() return None else: translation.install(True) return translation
def conf_path(self, trans=False): if trans: gettext.setpaths([join(os.sep, "usr", "share", "pyload", "locale"), None]) translation = gettext.translation("setup", join(self.path, "locale"), languages=[self.config["general"]["language"], "en"], fallback=True) translation.install(True) print _("Setting new configpath, current configuration will not be transferred!") path = self.ask(_("Config path"), abspath("")) try: path = join(pypath, path) if not exists(path): makedirs(path) f = open(join(pypath, "pyload", "config", "configdir"), "wb") f.write(path) f.close() print _("Config path changed, setup will now close, please restart to go on.") print _("Press Enter to exit.") raw_input() exit() except Exception, e: print _("Setting config path failed: %s") % str(e)
env.filters['quotepath'] = quotepath env.filters['truncate'] = truncate env.filters['date'] = date env.filters['path_make_relative'] = path_make_relative env.filters['path_make_absolute'] = path_make_absolute env.filters['decode'] = decode env.filters['type'] = lambda x: str(type(x)) env.filters['formatsize'] = formatSize env.filters['getitem'] = lambda x, y: x.__getitem__(y) if PREFIX: env.filters['url'] = lambda x: x else: env.filters['url'] = lambda x: PREFIX + x if x.startswith("/") else x gettext.setpaths([join(os.sep, "usr", "share", "pyload", "locale"), None]) translation = gettext.translation("django", join(PYLOAD_DIR, "locale"), languages=[config.get("general", "language"), "en"],fallback=True) translation.install(True) env.install_gettext_translations(translation) from beaker.middleware import SessionMiddleware session_opts = { 'session.type': 'file', 'session.cookie_expires': False, 'session.data_dir': './tmp', 'session.auto': False } web = StripPathMiddleware(SessionMiddleware(app(), session_opts))
def main(): config = {"addr": "127.0.0.1", "port": "7227", "language": "en"} try: config['language'] = os.environ['LANG'][0:2] except Exception: pass if (not exists(join(pypath, "locale", config['language']))) or config['language'] == "": config['language'] = "en" configFile = ConfigParser.ConfigParser() configFile.read(join(homedir, ".pyload-cli")) if configFile.has_section("cli"): for opt in configFile.items("cli"): config[opt[0]] = opt[1] gettext.setpaths([join(os.sep, "usr", "share", "pyload", "locale"), None]) translation = gettext.translation("Cli", join(pypath, "locale"), languages=[config['language'], "en"], fallback=True) translation.install(unicode=True) interactive = False command = None username = "" password = "" shortOptions = 'iu:p:a:hcl:' longOptions = ['interactive', "username="******"pw=", "address=", "port=", "help", "commands", "language="] try: opts, extraparams = getopt(sys.argv[1:], shortOptions, longOptions) for option, params in opts: if option in ("-i", "--interactive"): interactive = True elif option in ("-u", "--username"): username = params elif option in ("-a", "--address"): config['addr'] = params elif option in ("-p", "--port"): config['port'] = params elif option in ("-l", "--language"): config['language'] = params gettext.setpaths([join(os.sep, "usr", "share", "pyload", "locale"), None]) translation = gettext.translation("Cli", join(pypath, "locale"), languages=[config['language'], "en"], fallback=True) translation.install(unicode=True) elif option in ("-h", "--help"): print_help(config) exit() elif option in ("--pw"): password = params elif option in ("-c", "--comands"): print_commands() exit() except GetoptError: print 'Unknown Argument(s) "%s"' % " ".join(sys.argv[1:]) print_help(config) exit() if len(extraparams) >= 1: command = extraparams client = False if interactive: try: client = ThriftClient(config['addr'], int(config['port']), username, password) except WrongLogin: pass except NoSSL: print _("You need py-openssl to connect to this pyLoad Core.") exit() except NoConnection: config['addr'] = False config['port'] = False if not client: if not config['addr']: config['addr'] = raw_input(_("Address: ")) if not config['port']: config['port'] = raw_input(_("Port: ")) if not username: username = raw_input(_("Username: "******"Password: "******"Login data is wrong.") except NoConnection: print _("Could not establish connection to %(addr)s:%(port)s." % {"addr": config['addr'], "port": config['port']}) else: try: client = ThriftClient(config['addr'], int(config['port']), username, password) except WrongLogin: print _("Login data is wrong.") except NoConnection: print _("Could not establish connection to %(addr)s:%(port)s." % {"addr": config['addr'], "port": config['port']}) except NoSSL: print _("You need py-openssl to connect to this pyLoad core.") if interactive and command: print _("Interactive mode ignored since you passed some commands.") if client: writeConfig(config) cli = Cli(client, command)
env.filters['quotepath'] = quotepath env.filters['truncate'] = truncate env.filters['date'] = date env.filters['path_make_relative'] = path_make_relative env.filters['path_make_absolute'] = path_make_absolute env.filters['decode'] = decode env.filters['type'] = lambda x: str(type(x)) env.filters['formatsize'] = formatSize env.filters['getitem'] = lambda x, y: x.__getitem__(y) if PREFIX: env.filters['url'] = lambda x: x else: env.filters['url'] = lambda x: PREFIX + x if x.startswith("/") else x gettext.setpaths([join(os.sep, "usr", "share", "pyload", "locale"), None]) translation = gettext.translation( "django", join(PYLOAD_DIR, "locale"), languages=[config.get("general", "language"), "en"], fallback=True) translation.install(True) env.install_gettext_translations(translation) from beaker.middleware import SessionMiddleware session_opts = { 'session.type': 'file', 'session.cookie_expires': False, 'session.data_dir': './tmp', 'session.auto': False
def main(): config = {"addr": "127.0.0.1", "port": "7227", "language": "en"} try: config['language'] = os.environ['LANG'][0:2] except Exception: pass if (not exists(join(pypath, "locale", config['language']))) or config['language'] == "": config['language'] = "en" configFile = ConfigParser.ConfigParser() configFile.read(join(homedir, ".pyload-cli")) if configFile.has_section("cli"): for opt in configFile.items("cli"): config[opt[0]] = opt[1] gettext.setpaths([join(os.sep, "usr", "share", "pyload", "locale"), None]) translation = gettext.translation("Cli", join(pypath, "locale"), languages=[config['language'], "en"], fallback=True) translation.install(unicode=True) interactive = False command = None username = "" password = "" shortOptions = 'iu:p:a:hcl:' longOptions = [ 'interactive', "username="******"pw=", "address=", "port=", "help", "commands", "language=" ] try: opts, extraparams = getopt(sys.argv[1:], shortOptions, longOptions) for option, params in opts: if option in ("-i", "--interactive"): interactive = True elif option in ("-u", "--username"): username = params elif option in ("-a", "--address"): config['addr'] = params elif option in ("-p", "--port"): config['port'] = params elif option in ("-l", "--language"): config['language'] = params gettext.setpaths( [join(os.sep, "usr", "share", "pyload", "locale"), None]) translation = gettext.translation( "Cli", join(pypath, "locale"), languages=[config['language'], "en"], fallback=True) translation.install(unicode=True) elif option in ("-h", "--help"): print_help(config) exit() elif option in ("--pw"): password = params elif option in ("-c", "--comands"): print_commands() exit() except GetoptError: print 'Unknown Argument(s) "%s"' % " ".join(sys.argv[1:]) print_help(config) exit() if len(extraparams) >= 1: command = extraparams client = False if interactive: try: client = ThriftClient(config['addr'], int(config['port']), username, password) except WrongLogin: pass except NoSSL: print _("You need py-openssl to connect to this pyLoad Core.") exit() except NoConnection: config['addr'] = False config['port'] = False if not client: if not config['addr']: config['addr'] = raw_input(_("Address: ")) if not config['port']: config['port'] = raw_input(_("Port: ")) if not username: username = raw_input(_("Username: "******"Password: "******"Login data is wrong.") except NoConnection: print _( "Could not establish connection to %(addr)s:%(port)s." % { "addr": config['addr'], "port": config['port'] }) else: try: client = ThriftClient(config['addr'], int(config['port']), username, password) except WrongLogin: print _("Login data is wrong.") except NoConnection: print _("Could not establish connection to %(addr)s:%(port)s." % { "addr": config['addr'], "port": config['port'] }) except NoSSL: print _("You need py-openssl to connect to this pyLoad core.") if interactive and command: print _("Interactive mode ignored since you passed some commands.") if client: writeConfig(config) cli = Cli(client, command)