diff --git a/.gitignore b/.gitignore index 871b876..287e38d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,9 @@ __pycache__/ # Ignore virtualenv env/ + +# Ignore Visual Studio Code configurations +.vscode/ + +# Ignore vim temp files +*.swp diff --git a/.travis.yml b/.travis.yml index aa36889..8e5c50d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,8 +37,8 @@ matrix: dist: trusty env: - PACKAGE=updateYapiScripts -before_script: python install.py --lang=en --softlink=no -script: python yapi.py install $PACKAGE +before_script: python3 install.py --lang=en --softlink=no +script: python3 yapi.py install $PACKAGE notifications: slack: yapiworkspace:Rh3wlsbST5hm2JtSi3l3BpZO diff --git a/README.md b/README.md index ee39fe7..464d365 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,6 @@ To install one of the packages: To recreate the cache: yapi cache - **** diff --git a/config/config.ini b/config/config.ini index 01e96c2..52d5953 100644 --- a/config/config.ini +++ b/config/config.ini @@ -1,25 +1,30 @@ -[COMMON] -yapi_dir = -platform = -file_extension = .sh -language = en +# This field contains the default infos of YAPI +[DEFAULT] +# Directory where YAPI is installed +yapi_dir = ~/git/YAPI +# Language use in menu +language = english +# Directory where the package of languages are language_dir = ${yapi_dir}/config/languages -[INSTALL] -soft_link = /usr/local/bin -want_soft_link = +# This field contains the infos about the installation of YAPI +[Install] +# This value will be updated when YAPI will be installed +# This rappresent the path to soft link of YAPI +soft_link = +# This value will be updated when YAPI will be installed +# This rappresent the path to the desktop entry of YAPI +desktop_entry = +# The files write in this field rappresent the useless file for the final user remove_files = .git, .gitignore, .travis.yml -[REMOTE] -raw_location = https://raw.githubusercontent.com/YetAnotherPackageInstaller/ -origin_location = https://github.com/YetAnotherPackageInstaller/YAPI -branch = master -zip = ${REMOTE:origin_location}/archive/${REMOTE:branch}.zip - -[PACKAGES] -packages_path = ${COMMON:yapi_dir}/scripts -ignore = test.sh, updateYapiScripts.sh -installed = - -[CACHE] +# This field contains default infos of packages +[Package] +# This is the path of where packages are stored +path = ${DEFAULT:yapi_dir}/packages +# The value of this rappresent the default path where put the soft link of packages +# Possible value: ignore, /usr/local/bin, /usr/bin, ~/.local/bin +soft_link = ignore +# To keep files or downloaded resources of packages +# Possible value: True, False keep_cache = True diff --git a/config/languages/en.ini b/config/languages/english.ini similarity index 97% rename from config/languages/en.ini rename to config/languages/english.ini index 909210e..6ee8cbc 100644 --- a/config/languages/en.ini +++ b/config/languages/english.ini @@ -1,5 +1,5 @@ [DEFAULT] -description = English +description = English language [COMMON] 0_cache_not_found = No cache file found diff --git a/config/languages/it.ini b/config/languages/italiano.ini similarity index 97% rename from config/languages/it.ini rename to config/languages/italiano.ini index 51965a1..ab9bb6e 100644 --- a/config/languages/it.ini +++ b/config/languages/italiano.ini @@ -1,5 +1,5 @@ [DEFAULT] -description = Italian +description = Lingua italiana [COMMON] 0_cache_not_found = Nessun file di cache trovato diff --git a/modules/cache/cache_manager.py b/modules/cache/cache_manager.py deleted file mode 100644 index 6a7d7b8..0000000 --- a/modules/cache/cache_manager.py +++ /dev/null @@ -1,130 +0,0 @@ - -def load_packages_from_file(binary_file): - """Load packages list from cache. - - Arguments: - binary_file -- cache file of packages - """ - import pickle - with open(binary_file, "rb") as binary_packages: - packages_loaded = pickle.load(binary_packages) - print("[LOG] {} Package load from {}".format( - len(packages_loaded), binary_file)) - return packages_loaded - - -def get_package_info(info): - """Get package description and url from info. - - Arguments: - info -- The line to parse - """ - description = "" - url = "" - info = info.strip("\n").strip("# ") - precedent_character = "" - get_url = False - for character in info: - if not get_url and precedent_character == "-": - get_url = character == " " - if get_url: - continue - description += character - elif get_url: - url += character - else: - description += character - precedent_character = character - if not url: - url = "no url" - del precedent_character, get_url - return description[:-2], url - - -def load_packages_from_directory(directory, ignore_file=[]): - """Load packages from scripts. - - Arguments: - directory -- load cache of this directory - *ignore_file -- string name of files to ignore - """ - from modules.configuration.config_extractor import get_configuration - import glob - import os - config = get_configuration() - packages_loaded = dict() - os.chdir(directory) - counter_packages = 1 - for file in glob.glob("*" + config["COMMON"]["file_extension"]): - package_name = file.split(".")[0] - package_description = "" - with open(file, "r") as open_file: - package_info = str(open_file.readline()) - if package_info[0] == "#": - package_description, package_url = get_package_info( - package_info) - else: - package_description = package_url = package_name - if file in ignore_file: - print("File {} ignored".format(file)) - else: - packages_loaded[counter_packages] = [ - package_name, - package_description, - package_url, - str(directory + "/" + file) - ] - counter_packages += 1 - os.chdir(config["COMMON"]["yapi_dir"]) - return packages_loaded - - -def make_bin_from_packages(packages_list, file_name="packages.bin"): - """Create binary file from list. - - Arguments: - packages_list -- dictionary of packages to cache - *ignore_file -- string name of files to ignore - """ - import pickle - with open(file_name, "wb") as file: - pickle.dump(packages_list, file, protocol=0) - print("[LOG] {} Packages store into {}".format( - len(packages_list), file_name)) - - -def get_packages(directory, ignore_file=[]): - """Get packages. - - Arguments: - directory -- directory where packages are - *test -- specification of file using in test - """ - import os - from_file = directory.split(sep="/")[-1].strip("/") + ".bin" - if os.path.exists(from_file): - return load_packages_from_file(from_file) - else: - if os.path.exists(directory): - packages = load_packages_from_directory(directory, ignore_file) - make_bin_from_packages(packages, from_file) - return packages - else: - print("[LOG] {} directory not found".format(directory)) - return {} - - -def delete_cache(directory): - """Delete binary packages cache. - - Arguments: - directory -- delete the cache of this directory - """ - import os - try: - cache_file = directory.split(sep="/")[-1].strip("/") - os.chdir(directory.rstrip("/" + cache_file + "/")) - os.remove(cache_file + ".bin") - return True - except Exception: - return False diff --git a/modules/interfaces/console_interface.py b/modules/interfaces/console_interface.py deleted file mode 100644 index b61a426..0000000 --- a/modules/interfaces/console_interface.py +++ /dev/null @@ -1,59 +0,0 @@ - - -def run(packages): - """Run the console installer. - - Arguments: - packages -- list of packages to print - """ - from modules.languages.language_pack_manager import get_language_pack - from modules.utility.script_runner import runScript - language_pack = get_language_pack() - yes_answer = language_pack["ANSWER"]["yes_answer"] - no_answer = language_pack["ANSWER"]["no_answer"] - right_answer = yes_answer + no_answer - continue_to_ask = True - while continue_to_ask: - print("-" * 79) - print(language_pack["CONSOLE"]["0_choose_package"]) - for package_counter in packages: - print("{:>2}) {} - {}".format( - package_counter, - packages[package_counter][0].capitalize(), - packages[package_counter][1])) - choose = -1 - while choose not in range(package_counter + 1): - choose = input(language_pack["CONSOLE"] - ["1_install_question"] + " ") - try: - choose = int(choose) - if choose not in range(package_counter + 1): - print(str(language_pack["CONSOLE"]["2_end_numers"]) - .format(package_counter)) - except ValueError: - if choose == "exit": - print(language_pack["CONSOLE"]["8_end_installation"]) - exit() - print(str(language_pack["CONSOLE"]["3_input_format_error"]) - .format(package_counter)) - choose = -1 - package_to_install = choose - while str(choose) not in right_answer: - choose = input(str(language_pack["CONSOLE"] - ["4_confirmation_question"] + " ") - .format(packages[package_to_install][0])) - if choose in yes_answer: - print(language_pack["CONSOLE"]["5_installation_start"]) - print(runScript(packages[package_to_install][3])) - else: - print(language_pack["CONSOLE"]["6_reject_installation"]) - choose = "" - while choose not in right_answer: - choose = input(language_pack["CONSOLE"] - ["7_restart_installation"] + " ") - if choose in yes_answer: - continue - else: - print(language_pack["CONSOLE"]["8_end_installation"]) - exit() - print("-" * 79) diff --git a/modules/interfaces/user_interface.py b/modules/interfaces/user_interface.py deleted file mode 100644 index ab2e522..0000000 --- a/modules/interfaces/user_interface.py +++ /dev/null @@ -1,54 +0,0 @@ -from modules.cache.cache_manager import get_packages # Cache Manager -from modules.utility.script_runner import runScript # Script Runner -try: - import toga # GUI Library - from toga.style.pack import * # GUI Components -except ImportError: - pass - -where_is_scripts = "scripts/" - - -def build(app): - def installHandle(widget): - packageToInstall = packageInput.value - resultInput.value = runScript( - where_is_scripts + packageToInstall + ".sh") - - packages = get_packages(where_is_scripts, "test.sh", - "updateYapiScripts.sh") - box = toga.Box() - listBox = toga.Box() - listLabel = toga.Label('Packages Available: ') - packageBox = toga.Box() - packageLabel = toga.Label('Package To Install:') - packageInput = toga.TextInput() - submitBox = toga.Box() - install = toga.Button('Install Package', on_press=installHandle) - resultBox = toga.Box() - resultInput = toga.TextInput(readonly=True) - - listBox.add(listLabel) - packageBox.add(packageLabel) - packageBox.add(packageInput) - submitBox.add(install) - resultBox.add(resultInput) - box.add(listBox) - box.add(packageBox) - box.add(submitBox) - box.add(resultBox) - - box.style.update(direction=COLUMN, padding_top=10) - listBox.style.update(direction=ROW, padding=5) - packageBox.style.update(direction=ROW, padding=5) - submitBox.style.update(direction=ROW, padding=5) - return box - - -def start(): - return toga.App('Yet Another Package Manager', - 'org.YAPI.yapi', startup=build).main_loop() - - -def main(): - start().main_loop() diff --git a/packages/test.yp b/packages/test.yp new file mode 100644 index 0000000..a036e51 --- /dev/null +++ b/packages/test.yp @@ -0,0 +1,19 @@ +[DEFAULT] +name = Test +description = Description of package +url = https://github.com/YetAnotherPackageInstaller/YAPI +class = ignore + +[Common] +dekstop_entry = ignore +installed = ignore +cache = ignore +path = + +[Script] +download = echo "Download section test" +before_install = echo "Before install section test" +install = echo "Install section test" +after_install = echo "After install section test" +unistall = echo "Unistall section test" +desktop_entry = echo "Desktop_entry section test" diff --git a/packages/yapi.yp b/packages/yapi.yp new file mode 100644 index 0000000..794e11c --- /dev/null +++ b/packages/yapi.yp @@ -0,0 +1,38 @@ +[DEFAULT] +name = YAPI +description = Yet Another Package Installer +url = https://yetanotherpackageinstaller.github.io/ +class = installer + +[Common] +dekstop_entry = ~/.local/share/applications/${name}.desktop +installed = False +cache = ignore +path = ~/${DEFAULT:name} +soft_link = ~/.local/bin/${DEFAULT:name} + +[Script] +download = git clone https://github.com/YetAnotherPackageInstaller/YAPI ${DEFAULT:name} +before_install = + ${download} + cd ${Common:path} +install = + python3 -m pip install -r requirements.txt + python3 install.py --lang=en +after_install = + sudo rm -r ${Common:path}/.git + sudo ln -s ${Common:path}/yapi.sh ${Common:soft_link} +unistall = + sudo rm -r ${Common:path} + rm ${Common:desktop_entry} + sudo rm ${Common:soft_link} +desktop_entry = + [Desktop Entry] + Type=Application + Name=YAPI + Comment=Yet Another Package Installer + Icon=${Common:path}/resources/yapi.png + Exec= x-terminal-emulator -e sh ${path}/yapi.sh + Terminal=true + Categories=package;installer + StartupWMClass=Yapi diff --git a/platform.ini b/platform.ini deleted file mode 100644 index 7900d9b..0000000 --- a/platform.ini +++ /dev/null @@ -1,8 +0,0 @@ -[COMMON] -main_url = https://github.com/YetAnotherPackageInstaller - -[DARWIN] -location = ${COMMON:main_url}/packages-darwin - -[DEBIAN] -location = ${COMMON:main_url}/packages-linux-debian diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index e69de29..0000000 diff --git a/resources/yapi.png b/resources/yapi.png new file mode 100644 index 0000000..369a6f7 Binary files /dev/null and b/resources/yapi.png differ diff --git a/yapi.py b/yapi.py old mode 100755 new mode 100644 index 58dcc36..b8bed7b --- a/yapi.py +++ b/yapi.py @@ -1,66 +1,138 @@ -# YAPI - Yet Another Package Installer - -from modules.cache.cache_manager import get_packages, delete_cache +import subprocess +import glob +from configparser import ConfigParser from modules.configuration.config_extractor import get_configuration -from modules.languages.language_pack_manager import get_language_pack -from modules.utility.script_runner import runScript # Script Runner -import sys # Make System Calls +import os +import sys + +if __name__== '__main__': + len_command = len(sys.argv) -config = get_configuration() + if len_command == 1: -packages_path = config["PACKAGES"]["packages_path"] + try: + config = get_configuration() + print("-"*79) + print("Configuration") + print("Language: {}".format(config["COMMON"]["language"])) + print("Yapi directory: {}".format(config["COMMON"]["yapi_dir"])) + print("Keep cache: {}".format(config["CACHE"]["keep_cache"])) + print("-"*79) + except: + print("Config not able to be imported. Run \'python3 yapi.py config\' to fix the error") + exit() -language_pack = get_language_pack() + while True: + # Start of the user console menu + print("What do you want to do?") + print("1 - Install packages") + print("2 - Change configuration") + print("0 - Exit") + choose = (int)(input(" -> ")) + print("-"*79) + if choose == 0: + print("Bye, Bye") + exit() + elif choose == 1: + yapi_script = ConfigParser() + directory = (str)(config["PACKAGES"]["packages_path"]) -def print_commands_allowed(): - """Print on console all the commands allowed to run with YAPI.""" - help = language_pack["HELP"] - options = language_pack["COMMANDS"] - print(language_pack["COMMON"]["2_argument_choose"]) - for option in options: - print("\t - {} \n\t\t python3 yapi.py {} {} " - .format(help[option], option, options[option])) + # Start Method Get packages + # this print need to be the init of output string + os.chdir(directory) + names_script = list() + categories = dict() + for file in glob.glob("*"+".yp"): + yapi_script.read(file) + class_script = yapi_script["DEFAULT"]["class"] + if class_script not in categories.keys(): + categories[class_script] = list() + if class_script != "ignore": + names_script.append((str)(file)) + categories[class_script].append(len(names_script)) + else: + categories[class_script].append((str)(file)) + # print(names_script) + # print(categories) + # this method return 2 object: the list of the names and + # the list of the categories. + # return names_script, categories + # End method get packages + # Categories + print("Choose one of this categories") + print("0 - Return to main") + num_category = list() + num_category.append("Return to main menu") + for category in categories.keys(): + if category != "ignore": + num_category.append(category) + print("{} - {}".format(len(num_category)-1, category)) + choose = input(" -> ") + if (int)(choose) <= len(num_category): + if (int)(choose) == 0: + print("Return to menu...") + else: + print("-"*79) -def argumentError(arg): - """Print on console a message of Argument error. + # Packages + print("This is the packages of category {}".format( + num_category[(int)(choose)])) + print("0 - Return to menu") + for num_name in categories[num_category[(int)(choose)]]: + print("{} - {}".format(num_name, + names_script[num_name-1])) + choose = input(" -> ") + if (int)(choose) != 0: + yapi_script.read(names_script[(int)(choose)-1]) - Arguments: - arg -- this is the argument to print that is not allowed - """ - print(language_pack["COMMON"] - ["1_argument_not_allowed"].format(arg.upper())) - print_commands_allowed() + # package infos + print("-"*79) + print("Infos about {}".format( + yapi_script["DEFAULT"]["name"].capitalize())) + print("Description: {}".format( + yapi_script["DEFAULT"]["description"])) + print("Link reference: {}".format( + yapi_script["DEFAULT"]["url"])) + print("Is install: {}".format( + yapi_script["Common"]["installed"])) + print("What do you want to do?") + print("0 - return to packages chooose") + print("1 - install") + print("2 - go to link") + choose = input(" -> ") + # install package + if (int)(choose) == 1: + print("-"*79) + output = subprocess.call( + yapi_script["Script"]["install"], shell=True, stderr=subprocess.STDOUT) + if output == 0: + print("ok") + else: + print("not ok") -if len(sys.argv) == 1: - from modules.interfaces.user_interface import main - result = main() -elif len(sys.argv) == 2: - if (sys.argv[1] == "console"): - from modules.interfaces.console_interface import run - packages = get_packages( - packages_path, str(config["PACKAGES"]["ignore"]).split(sep=", ")) - run(packages) - elif (sys.argv[1] == "update"): - runScript( - packages_path + "/updateYapiScripts" + - config["COMMON"]["file_extension"]) - elif (sys.argv[1] == "cache"): - try: - result = delete_cache(packages_path) - get_packages( - packages_path, - str(config["PACKAGES"]["ignore"]).split(sep=", ")) - except Exception: - print(language_pack["COMMON"]["0_cache_not_found"]) - elif (sys.argv[1] == "help"): - print_commands_allowed() - else: - argumentError(sys.argv[1]) -elif len(sys.argv) == 3: - if sys.argv[1] == "install": - runScript( - packages_path + "/" + sys.argv[2] + - config["COMMON"]["file_extension"]) + # url + elif (int)(choose) == 2: + print("You are now redirected to {}".format( + yapi_script["DEFAULT"]["url"])) + # this need to return to the menu of package + print("-"*79) + elif choose == 2: + print("not yet implemented") + print("-"*79) + # End of the user console menu + elif len_command >= 2: + command = sys.argv[1] + if(command == "help") or (command == "h"): + print("print the usage and list command of YAPI") + elif (command == "list") or (command == "ls"): + print("print the list of package class with number of relative packages") + print("if the command is list something so print only the packages of something class") + elif (command == "update") or (command == "up"): + print("search on github for new version of YAPI") + elif (command == "install") or (command == "in"): + print("install the package requested") + elif (command == "uninstall") or (command == "un"): + print("uninstall the package requested") diff --git a/yapi.sh b/yapi.sh index 103d02b..866d9bd 100755 --- a/yapi.sh +++ b/yapi.sh @@ -1 +1 @@ -python3 yapi.py $1 $2 +python3 yapi_new.py $1 $2 diff --git a/yapi_new/config b/yapi_new/config new file mode 100644 index 0000000..f7b3323 --- /dev/null +++ b/yapi_new/config @@ -0,0 +1,3 @@ +[DEFAULT] +language_use = en + diff --git a/yapi_new/languages/en b/yapi_new/languages/en new file mode 100644 index 0000000..1f28013 --- /dev/null +++ b/yapi_new/languages/en @@ -0,0 +1,41 @@ +[DEFAULT] +name = English +hello = Hello this is YAPI new version +bye = Bye + +conf0_title_language = There is no language configuration + +conf1_title_language = Select the language + +conf2_title_language = You choose {} language + +main0_main = What do you want to do? + +main0_title_install = Install/update packages +main0_answers_install = install, update, install packages, update packages + +main1_title_install = Install or update packages +main1_categorize_install = Category +main1_categorize_answers_install = category +main1_list_install = List +main1_list_answers_install = list + +main2_title_install = Select one package +main2_title_category = Choose a category + +main3_start_install = Start installation of {}... +main3_end_install = Installation of package {} done + +main0_title_configuration = Change configuration +main0_answers_configuration = configuration, config, change, change config, change configuration, 1 + +main1_title_configuration = What configuration do you want to change? + +title_exit = Exit +title_exit_answers = exit, quit, q +title_back = Back +title_back_answers = back + + +main1_title_undestand = Sorry I don't understand + diff --git a/yapi_new/languages/it b/yapi_new/languages/it new file mode 100644 index 0000000..8945557 --- /dev/null +++ b/yapi_new/languages/it @@ -0,0 +1,24 @@ +[DEFAULT] +name = Italiano +hello = Salve questa è la nuova versione di YAPI + +conf0_title_language = Non c'è nessuna configurazione della lingua +conf1_title_language = Seleziona la lingua +conf2_title_language = Hai scelto la lingua {} + +main0_main = Cosa vuoi fare? + +main0_title_install = Installa/aggiorna pacchetti +main0_answers_install = installa, aggiorna, installa pacchetti, aggiorna pacchetti +main1_title_install = Installa o aggiorna pacchetti + +main0_title_configuration = Cambia configurazione +main0_answers_configuration = configurazione, config, cambia, cambia config, cambia configurazione +main1_title_configuration = Cosa vuoi cambiare? + +main0_title_exit = Esci +main0_answers_exit = esci, esc, q +main1_title_exit = Ciao + +main1_title_undestand = Sorry I don't understand + diff --git a/yapi_new/packages/test.yp b/yapi_new/packages/test.yp new file mode 100644 index 0000000..73016da --- /dev/null +++ b/yapi_new/packages/test.yp @@ -0,0 +1,3 @@ +[DEFAULT] +name = test +class = test diff --git a/yapi_new/packages/test2.yp b/yapi_new/packages/test2.yp new file mode 100644 index 0000000..49c8ee7 --- /dev/null +++ b/yapi_new/packages/test2.yp @@ -0,0 +1,3 @@ +[DEFAULT] +name = test2 +class = test, yapi diff --git a/yapi_new/packages/yapi.yp b/yapi_new/packages/yapi.yp new file mode 100644 index 0000000..233b67a --- /dev/null +++ b/yapi_new/packages/yapi.yp @@ -0,0 +1,3 @@ +[DEFAULT] +name = yapi +class = yapi diff --git a/yapi_new/yapi_new.py b/yapi_new/yapi_new.py new file mode 100644 index 0000000..3519ea8 --- /dev/null +++ b/yapi_new/yapi_new.py @@ -0,0 +1,252 @@ +from configparser import ConfigParser +import glob + +_packages_path = 'packages/' +_lang_path = 'languages/' + +_lenght_separator = 50 +_separator = '-' + +_get_default = lambda config, key: config['DEFAULT'][key] +_print_separator = lambda separetor=_separator, lenght=_lenght_separator: print(separetor * lenght) + +def _remove_whitespaces(string): + while ', ' in string: + string = string.replace(', ', ',') + return string + +def _category_chosing(lang, packages_path=_packages_path): + title_category = _get_default(lang, 'main2_title_category') + _print_separator(lenght=len(title_category)) + print(title_category) + _print_separator(lenght=len(title_category)) + del title_category + + info_packages = {} + + for file in glob.glob(packages_path + '*'): + packages_temp = ConfigParser() + packages_temp.read(file) + for category in _remove_whitespaces(_get_default(packages_temp, 'class')).split(','): + if category not in info_packages.keys(): + info_packages[category] = [] + info_packages[category].append(_get_default(packages_temp, 'name')) + del packages_temp + + print('Choose one of this category') + + for classes in info_packages: + print(' - {} ({}) '.format(classes, len(info_packages[classes]))) + print(' - ' + _get_default(lang, 'title_back')) + back_request = _remove_whitespaces(_get_default(lang, 'title_back_answers')).split(',') + print(' - ' + _get_default(lang, 'title_exit')) + exit_request = _remove_whitespaces(_get_default(lang, 'title_exit_answers')).split(',') + + choose = (str)(input('-----> ')).lower() + if choose in back_request: + return 1 + if choose in exit_request: + return 2 + elif choose in info_packages: + print('You choose the category {}'.format(choose)) + else: + print(_get_default(lang, 'main1_title_undestand')) + +def _install_procedure(lang, packages_path=_packages_path): + while True: + + title_install = _get_default(lang,'main2_title_install') + _print_separator(lenght=len(title_install)) + print(title_install) + _print_separator(lenght=len(title_install)) + del title_install + + exit_request = _remove_whitespaces(_get_default(lang, 'title_exit_answers')).split(',') + back_request = _remove_whitespaces(_get_default(lang, 'title_back_answers')).split(',') + + files_list = [] + for file in glob.glob(packages_path + '*'): + packages_temp = ConfigParser() + packages_temp.read(file) + file_name = _get_default(packages_temp, 'name') + print(' - ' + file_name) + files_list.append(file_name) + del packages_temp + print(' - ' + _get_default(lang, 'title_back')) + print(' - ' + _get_default(lang, 'title_exit')) + + choose = (str)(input('-----> ')).lower() + + if choose in files_list: + start_install =_get_default(lang,'main3_start_install').format(choose.capitalize()) + end_install = _get_default(lang,'main3_end_install').format(choose.capitalize()) + max_string = max(len(start_install),len(end_install)) + _print_separator(lenght=max_string) + print(start_install) + print(end_install) + _print_separator(lenght=max_string) + del start_install, end_install, max_string + elif choose in back_request: + break + elif choose in exit_request: + print(_get_default(lang, 'bye')) + exit() + else: + title_undestand = _get_default(lang, 'main1_title_undestand') + _print_separator(lenght=len(title_undestand)) + print(title_undestand) + _print_separator(lenght=len(title_undestand)) + del title_undestand + +def _config_language(lang, lang_path): + lang_list = [] + + for file in glob.glob(lang_path +'*'): + lang_file = (str)(file) + lang_temp = ConfigParser() + lang_temp.read(lang_file) + lang_name = _get_default(lang_temp,'name') + lang_list.append([lang_file.replace(lang_path,'').lower(),lang_name]) + del lang_temp, lang_file, lang_name + + not_choose = True + while not_choose: + print(_get_default(lang,'conf1_title_language')) + + for language in lang_list: + print(' - {} ({})'.format(language[1].capitalize(), language[0])) + + choose = (str)(input('-----> ')).lower() + + for language in lang_list: + if choose in language[0].lower() or choose in language[1].lower(): + lang_temp = ConfigParser() + config.set('DEFAULT', 'language_use', language[0]) + with open(config_path, 'w') as configfile: + config.write(configfile) + not_choose = False + print(_get_default(lang,'conf2_title_language').format(language[1].capitalize())) + lang.read(lang_path + language[0]) + +if __name__ == '__main__': + + lang = ConfigParser() + lang.read(_lang_path + 'en') + + config_path = 'config' + config = ConfigParser() + config.read(config_path) + + if _get_default(config,'language_use') is '': + title_conf_language = _get_default(lang,'conf0_title_language') + _print_separator(lenght=len(title_conf_language)) + print(title_conf_language) + _print_separator(lenght=len(title_conf_language)) + del title_conf_language + _config_language(lang,_lang_path) + else: + lang.read(_lang_path+_get_default(config, 'language_use')) + + hello = _get_default(lang,'hello') + _print_separator(lenght=len(hello)) + print(hello) + _print_separator(lenght=len(hello)) + del hello + + while True: + + print(_get_default(lang,'main0_main')) + + print(' - ' + _get_default(lang,'main0_title_install')) + install_update_request = _remove_whitespaces(_get_default(lang,'main0_answers_install')).split(',') + + print(' - ' + _get_default(lang, 'main0_title_configuration')) + change_config_request = _remove_whitespaces(_get_default(lang, 'main0_answers_configuration')).split(',') + + print(' - ' + _get_default(lang, 'title_exit')) + exit_request = _remove_whitespaces(_get_default(lang, 'title_exit_answers')).split(',') + + choose = (str)(input('-----> ')).lower() + + if choose in exit_request: + print(_get_default(lang, 'bye')) + exit() + elif choose in install_update_request: + while True: + title_install = _get_default(lang, 'main1_title_install') + + _print_separator(lenght=len(title_install)) + print(title_install) + _print_separator(lenght=len(title_install)) + del title_install + + print(' - ' + _get_default(lang,'main1_list_install')) + list_install = _remove_whitespaces(_get_default(lang,'main1_list_answers_install')).split(',') + + print(' - ' + _get_default(lang,'main1_categorize_install')) + category_install = _remove_whitespaces(_get_default(lang,'main1_categorize_answers_install')).split(',') + + print(' - ' + _get_default(lang, 'title_back')) + back_request = _remove_whitespaces(_get_default(lang, 'title_back_answers')).split(',') + + print(' - ' + _get_default(lang, 'title_exit')) + exit_request = _remove_whitespaces(_get_default(lang, 'title_exit_answers')).split(',') + + choose = (str)(input('-----> ')).lower() + + if choose in exit_request: + print(_get_default(lang, 'bye')) + exit() + if choose in back_request: + break + elif choose in list_install: + _install_procedure(lang) + elif choose in category_install: + category_result = _category_chosing(lang, _packages_path) + if category_result == 1: + break + elif category_result == 2: + print(_get_default(lang, 'bye')) + exit() + del category_result + else: + print(_get_default(lang, 'main1_title_undestand')) + + elif choose in change_config_request: + title_configuration = _get_default(lang, 'main1_title_configuration') + _print_separator(lenght=len(title_configuration)) + print(title_configuration) + _print_separator(lenght=len(title_configuration)) + del title_configuration + + while True: + for items in config.items(): + for item in items[1]: + print(' - ' + item) + print(' - ' + _get_default(lang, 'title_exit')) + print(' - ' + _get_default(lang, 'title_back')) + exit_request = _remove_whitespaces(_get_default(lang, 'title_exit_answers')).split(',') + back_request = _remove_whitespaces(_get_default(lang, 'title_back_answers')).split(',') + + choose = (str)(input('-----> ')).lower() + + if choose == 'language_use': + _config_language(lang,_lang_path) + break + elif choose in back_request: + break + elif choose in exit_request: + print(_get_default(lang, 'bye')) + exit() + else: + title_understand = _get_default(lang, 'main1_title_undestand') + _print_separator(lenght=len(title_understand)) + print(title_understand) + _print_separator(lenght=len(title_understand)) + del title_understand + else: + print(_get_default(lang, 'main1_title_undestand')) + + _print_separator() + +