def main():
    with clint_core.indent(4):
        print('\n')
        title = (' ' * 24) + ('<' * 3) + (' CLI CALCULATOR ') + ('>' * 3)
        clint_ui.puts(clint_ui.colored.cyan(title))
        print('\n\n')
        line_no = 0
        global calculation_history
        calculation_history = []
        while True:
            line_no += 1
            try:
                formula = input('<' + str(line_no) + '> ')
                if formula == '..' or formula.lower() == 'exit':
                    break

                if (formula.lower() == 'help') or (formula == '?'):
                    #use input() to stall the program while displaying help
                    input(const.HELP_TEXT)
                    line_data = {
                        'line': line_no,
                        'operation': 'help',
                        'operation_result': calc,
                        'err': False
                    }
                    calculation_history.append(line_data)
                else:
                    calc = evaluate(formula)
                    clint_ui.puts(clint_ui.colored.yellow('= ' + str(calc)))
                    line_data = {
                        'line': line_no,
                        'operation': 'calc',
                        'operation_result': calc,
                        'err': False
                    }
                    calculation_history.append(line_data)
            except Exception as err:
                line_data = {
                    'line': line_no,
                    'operation': 'calc',
                    'operation_result': 0,
                    'err': True
                }
                calculation_history.append(line_data)
                clint_core.puts_err(
                    clint_ui.colored.red('Error: {}'.format(err)))
Exemplo n.º 2
0
def fetch(url):

    response = requests.get(url)
    url = urlparse(response.url)  # Follow redirects

    if response.status_code not in range(200, 299):
        sys.exit("Bad response {}".format(response.status_code))

    # If Content-Type header is not found we assume MP3
    content_type = response.headers.get('content-type', 'audio/mpeg')
    if not content_type.startswith("audio/"):
        puts_err("Bad content-type")

    extension = mimetypes.guess_extension(content_type)
    content_disposition = parse_requests_response(response)
    filename = content_disposition.filename_sanitized(extension.lstrip('.'))

    expected_ittimes = None
    content_length = response.headers.get('content-length')
    iter_content = response.iter_content(CHUNK_SIZE)

    puts(colored.blue(u"Downloading {}\n".format(filename)))

    # Display progress bar if content-length is set
    if content_length is not None:
        expected_ittimes = int(content_length) / CHUNK_SIZE
        iter_content = progress.bar(iter_content, expected_size=expected_ittimes)

    with tempfile.NamedTemporaryFile(prefix='song-', suffix=extension, delete=False) \
             as fp:
        for chunk in iter_content:
            fp.write(chunk)

    proc = subprocess.Popen(['osascript', '-'],
        stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
    out, err = proc.communicate(add_to_itunes.format(path=fp.name))

    if proc.returncode:
        puts_err("Couldn't add to iTunes ({})".format(err))
        sys.exit(proc.returncode)

    match = re.match(_itunes_stdout_re, out)
    if match is not None:
        song, playlist, source = match.groups()
        puts(colored.cyan("Added {} to iTunes!".format(song)))
Exemplo n.º 3
0
    def packages(self, category_name=None):
        """
        Commands

        n = next page
        p = prev page
        q = quit

        """
        self.view = "menu-view"
        category = "All"

        # MENU VIEW
        self.menu_view = {
            'highlighted_item': 1,
            'options': {
                'Packages': 'main-view',
                'Categories': 'category-choice-view',
                'Virtual Environments': 'virtual-env-view',
                'Help': 'help-view',
                'Update': 'update-view',
                'About': 'about-view',
            }
        }

        self.session = Session()
        #self.session = session

        categories = self.session.query(Category).order_by(
            Category.title).all()
        self.category_choice_view = {
            'categories': categories,
            'paginator': Paginator(objects=categories, pagination=10),
            'current_page': 1,
            'highlighted_item': 1,
            'ordering': 'name',
        }

        self.category_choice_view['category_paginator'] = Paginator(
            objects=categories, pagination=10)
        self.category_choice_view['current_page'] = 1
        self.category_choice_view['highlighted_item'] = 1
        self.category_choice_view['info'] = {}

        if category_name:
            category = self.session.query(Category).filter(
                Category.slug == category_name)
            if not category:
                category = "All"
                puts_err("Could not find specified category.")

                self.view = 'category-choice-view'

        packages_query = self.session.query(Package).order_by(
            Package.pypi_downloads.desc())
        packages = packages_query.all()

        puts("")

        self.main_view = {}
        self.main_view['paginator'] = Paginator(packages, pagination=10)
        self.main_view['paginator'].base_query = self.session.query(Package)
        self.main_view['current_page'] = 1
        self.main_view['highlighted_item'] = 1
        self.main_view['info'] = {
            'Category': category_name or 'All',
            'Package count': self.session.query(Package).count(),
        }
        self.main_view['ordering'] = 'downloads'

        self._render()

        while True:
            key = listen_for_cli_command()

            if key == 'q':
                quit()

            if self.view == "menu-view":
                # MAIN MENU
                if ord(key) == 80:
                    # UP key
                    if not self.menu_view['highlighted_item'] >= len(
                            self.menu_view['options']):
                        self.menu_view['highlighted_item'] += 1

                    self._render_main_menu()

                elif ord(key) == 72:
                    # DOWN key
                    if not self.menu_view['highlighted_item'] <= 1:
                        self.menu_view['highlighted_item'] -= 1

                    self._render_main_menu()

                elif ord(key) == 13:
                    # ENTER key
                    index = self.menu_view['highlighted_item'] - 1
                    self.view = self.menu_view['options'].values()[index]
                    print "going to %s..." % self.view

                    self._render()

            elif self.view == "virtual-env-list-view":
                pass

            elif self.view == 'main-view':
                if key == 'n' or ord(key) == 77:
                    # N = Next page
                    if self.main_view['current_page'] >= self.main_view[
                            'paginator'].num_pages:
                        puts_err("You are already at the last page")
                        continue

                    self.main_view['current_page'] += 1
                    self._render_package_list(
                        self.main_view['paginator'],
                        self.main_view['current_page'], self.main_view['info'],
                        self.main_view['highlighted_item'])

                elif key == 'p' or ord(key) == 75:
                    # P = Previous page
                    if self.main_view['current_page'] <= 1:
                        puts_err("You are already at the first page")
                        continue

                    self.main_view['current_page'] -= 1
                    self._render_package_list(
                        self.main_view['paginator'],
                        self.main_view['current_page'], self.main_view['info'],
                        self.main_view['highlighted_item'])

                elif key == 'u':
                    # SORT BY USING
                    self.main_view['ordering'] = 'people using library'
                    self.main_view['paginator'].objects = self.main_view[
                        'paginator'].base_query.order_by(
                            Package.usage_count.desc()).all()
                    self.main_view['current_page'] = 1
                    self._render_package_list(
                        self.main_view['paginator'],
                        self.main_view['current_page'], self.main_view['info'],
                        self.main_view['highlighted_item'])

                elif key == 'c':
                    self.view = "category-choice-view"
                    self._render_category_choice_view(
                        self.category_choice_view['category_paginator'],
                        self.category_choice_view['current_page'],
                        self.main_view['info'],
                        self.category_choice_view['highlighted_item'])

                elif key == 'g':
                    # UPDATE
                    self.view = 'update-view'
                    self.update()
                    self._render_package_list(
                        self.main_view['paginator'],
                        self.main_view['current_page'], self.main_view['info'],
                        self.main_view['highlighted_item'])
                    self.view = 'main-view'

                elif key == 'w':
                    # SORT BY WATCHING
                    self.main_view['ordering'] = 'people wathcing repository'
                    self.main_view['paginator'].objects = self.main_view[
                        'paginator'].base_query.order_by(
                            Package.repo_watchers.desc()).all()
                    self.main_view['current_page'] = 1
                    self._render_package_list(
                        self.main_view['paginator'],
                        self.main_view['current_page'], self.main_view['info'],
                        self.main_view['highlighted_item'])

                elif key == 'd':
                    # SORT by Downloads
                    self.main_view['ordering'] = 'PYPI downloads'
                    self.main_view['paginator'].objects = self.main_view[
                        'paginator'].base_query.order_by(
                            Package.pypi_downloads.desc()).all()
                    self.main_view['current_page'] = 1
                    self._render_package_list(
                        self.main_view['paginator'],
                        self.main_view['current_page'], self.main_view['info'],
                        self.main_view['highlighted_item'])

                elif ord(key) == 13:
                    # Pressed ENTER onto package
                    self.view = 'package-view'
                    package = self.main_view['paginator'].current_page()[
                        self.main_view['highlighted_item'] - 1]
                    self._render_package_info(package)

                    rtd_bootstrap = ReadTheDocsBootstrap(proxy=self.proxy)
                    docs = rtd_bootstrap.check_if_docs_exist(
                        package.pypi_package_name or package.repo_name)
                    if docs:
                        self._render_package_info(package, docs=docs)

                elif ord(key) == 72:
                    # pressed UP
                    if not self.main_view['highlighted_item'] <= 1:
                        self.main_view['highlighted_item'] -= 1
                    self._render_package_list(
                        self.main_view['paginator'],
                        self.main_view['current_page'], self.main_view['info'],
                        self.main_view['highlighted_item'])

                elif ord(key) == 80:
                    # pressed DOWN
                    if not self.main_view['highlighted_item'] >= 10:
                        self.main_view['highlighted_item'] += 1
                    self._render_package_list(
                        self.main_view['paginator'],
                        self.main_view['current_page'], self.main_view['info'],
                        self.main_view['highlighted_item'])

                elif ord(key) == 8:
                    # BACKSPACE key
                    self.view = 'menu-view'
                    self._render()

            elif self.view == 'package-view':

                if key == 'i':
                    #INSTALL
                    self.view = "install-view"

                    self._clear_screen()

                    puts(colored.magenta("Installing..."))
                    puts()

                    package = self.main_view['paginator'].current_page()[
                        self.main_view['highlighted_item'] - 1]
                    result = self.install(
                        package_names=[package.install_string])
                    if not result:
                        package.update_installed_info()
                        self.session.commit()

                    self.main_view['paginator'].refresh_objects()

                    puts()
                    puts(colored.magenta("Press ENTER to continue..."))
                    s = raw_input()

                    self.view = 'package-view'
                    self._render()
                    #self._render_package_info(package)

                elif key == 'u':
                    # UNINSTALL
                    self.view = "install-view"

                    self._clear_screen()

                    puts(colored.magenta("Uninstalling..."))
                    puts()

                    package = self.main_view['paginator'].current_page()[
                        self.main_view['highlighted_item'] - 1]
                    result = self.uninstall(package_names=[
                        package.pypi_package_name or package.repo_name
                    ])
                    if result:
                        puts(result)

                    if not result:
                        package.installed = False
                        self.session.commit()

                    self.main_view['paginator'].refresh_objects()

                    puts()
                    puts(colored.magenta("Press ENTER to continue..."))
                    s = raw_input()

                    self.view = 'package-view'
                    self._render_package_info(package)

                elif ord(key) == 8:
                    # BACKSPACE
                    self.view = 'main-view'
                    self._render_package_list(
                        self.main_view['paginator'],
                        self.main_view['current_page'], self.main_view['info'],
                        self.main_view['highlighted_item'])

                elif key == 'p':
                    # PYPI webpage
                    package = self.main_view['paginator'].current_page()[
                        self.main_view['highlighted_item'] - 1]
                    webbrowser.open(package.pypi_url)

                elif key == 'r':
                    # REPO page
                    package = self.main_view['paginator'].current_page()[
                        self.main_view['highlighted_item'] - 1]
                    webbrowser.open(package.repo_url)

            elif self.view == 'installed-view':
                pass

            elif self.view == 'category-choice-view':
                if key == 'n' or ord(key) == 77:
                    # N = Next page
                    if self.category_choice_view[
                            'current_page'] >= self.category_choice_view[
                                'category_paginator'].num_pages:
                        puts_err("You are already at the last page")
                        continue

                    self.category_choice_view['current_page'] += 1
                    self._render()
                    #self._render_category_choice_view(self.category_choice_view['category_paginator'], self.category_choice_view['current_page'], self.main_view['info'], self.category_choice_view['highlighted_item'])

                elif key == 'p' or ord(key) == 75:
                    # P = Previous page
                    if self.category_choice_view['current_page'] <= 1:
                        puts_err("You are already at the first page")
                        continue

                    self.category_choice_view['current_page'] -= 1
                    self._render()
                    #self._render_category_choice_view(self.category_choice_view['category_paginator'], self.category_choice_view['current_page'], self.main_view['info'], self.category_choice_view['highlighted_item'])

                elif ord(key) == 13:
                    # Pressed ENTER onto package

                    category = self.category_choice_view[
                        'category_paginator'].current_page()[
                            self.category_choice_view['highlighted_item'] - 1]

                    packages_base_query = self.session.query(Package).filter(
                        Package.categories.any(id=category.id))
                    self.main_view['paginator'] = Paginator(
                        objects=packages_base_query.order_by(
                            Package.pypi_downloads.desc()).all())
                    self.main_view[
                        'paginator'].base_query = packages_base_query

                    self.main_view['current_page'] = 1
                    self.main_view['highlighted_item'] = 1
                    self.main_view['info'] = {
                        'Category': category and category.title or 'All',
                        'Package count': len(category.packages),
                    }

                    self.view = 'main-view'
                    self._render()
                    #self._render_package_list(self.main_view['paginator'], self.main_view['current_page'], self.main_view['info'], self.main_view['highlighted_item'])

                elif ord(key) == 72:
                    # pressed UP
                    if not self.category_choice_view['highlighted_item'] <= 1:
                        self.category_choice_view['highlighted_item'] -= 1
                    self._render()
                    #self._render_category_choice_view(self.category_choice_view['category_paginator'], self.category_choice_view['current_page'], self.main_view['info'], self.category_choice_view['highlighted_item'])

                elif ord(key) == 80:
                    # pressed DOWN
                    if not self.category_choice_view['highlighted_item'] >= 10:
                        self.category_choice_view['highlighted_item'] += 1
                    self._render()
                    #self._render_category_choice_view(self.category_choice_view['category_paginator'], self.category_choice_view['current_page'], self.main_view['info'], self.category_choice_view['highlighted_item'])

                elif ord(key) == 8:
                    # BACKSPACE key
                    self.view = 'menu-view'
                    self._render()

                elif key == 'k':
                    # ORDERING by Package count
                    self.category_choice_view['ordering'] = 'package count'
                    #self.category_choice_view['paginator'] = self.category_choice_view['paginator'].base_query.order_by(Category.package.desc()).all()

                    self.main_view['paginator'].objects = self.main_view[
                        'paginator'].base_query.order_by(
                            Package.usage_count.desc()).all()
                    self.main_view['current_page'] = 1
                    self._render_package_list(
                        self.main_view['paginator'],
                        self.main_view['current_page'], self.main_view['info'],
                        self.main_view['highlighted_item'])

            elif self.view in ['about-view', 'help-view']:

                if ord(key) == 8:
                    self.view = "menu-view"
                    self._render()
    def packages(self, category_name=None):
        """
        Commands

        n = next page
        p = prev page
        q = quit

        """
        self.view = "menu-view"
        category = "All"

        # MENU VIEW
        self.menu_view = {
            'highlighted_item': 1,
            'options': {
                'Packages': 'main-view',
                'Categories': 'category-choice-view',
                'Virtual Environments': 'virtual-env-view',
                'Help': 'help-view',
                'Update': 'update-view',
                'About': 'about-view',
            }
        }

        self.session = Session()
        #self.session = session

        categories = self.session.query(Category).order_by(Category.title).all()
        self.category_choice_view = {
            'categories': categories,
            'paginator' : Paginator(objects=categories, pagination=10),
            'current_page' : 1,
            'highlighted_item' : 1,
            'ordering': 'name',
        }

        self.category_choice_view['category_paginator'] = Paginator(objects=categories, pagination=10)
        self.category_choice_view['current_page'] = 1
        self.category_choice_view['highlighted_item'] = 1
        self.category_choice_view['info'] = {}

        if category_name:
            category = self.session.query(Category).filter(Category.slug == category_name)
            if not category:
                category = "All"
                puts_err("Could not find specified category.")

                self.view = 'category-choice-view'


        packages_query = self.session.query(Package).order_by(Package.pypi_downloads.desc())
        packages = packages_query.all()

        puts("")


        self.main_view = {}
        self.main_view['paginator'] = Paginator(packages, pagination=10)
        self.main_view['paginator'].base_query = self.session.query(Package)
        self.main_view['current_page'] = 1
        self.main_view['highlighted_item'] = 1
        self.main_view['info'] = {
            'Category': category_name or 'All',
            'Package count': self.session.query(Package).count(),
            }
        self.main_view['ordering'] = 'downloads'

        self._render()

        while True:
            key = listen_for_cli_command()

            if key == 'q':
                quit()


            if self.view == "menu-view":
                # MAIN MENU
                if ord(key) == 80:
                    # UP key
                    if not self.menu_view['highlighted_item'] >= len(self.menu_view['options']):
                        self.menu_view['highlighted_item'] += 1

                    self._render_main_menu()

                elif ord(key) == 72:
                    # DOWN key
                    if not self.menu_view['highlighted_item'] <= 1:
                        self.menu_view['highlighted_item'] -= 1

                    self._render_main_menu()

                elif ord(key) == 13:
                    # ENTER key
                    index = self.menu_view['highlighted_item']-1
                    self.view = self.menu_view['options'].values()[index]
                    print "going to %s..." %self.view

                    self._render()

            elif self.view == "virtual-env-list-view":
                pass



            elif self.view == 'main-view':
                if   key == 'n' or ord(key) == 77:
                    # N = Next page
                    if self.main_view['current_page'] >= self.main_view['paginator'].num_pages:
                        puts_err("You are already at the last page")
                        continue

                    self.main_view['current_page'] += 1
                    self._render_package_list(self.main_view['paginator'], self.main_view['current_page'], self.main_view['info'], self.main_view['highlighted_item'])

                elif key == 'p' or ord(key) == 75:
                    # P = Previous page
                    if self.main_view['current_page'] <= 1:
                        puts_err("You are already at the first page")
                        continue

                    self.main_view['current_page'] -= 1
                    self._render_package_list(self.main_view['paginator'], self.main_view['current_page'], self.main_view['info'], self.main_view['highlighted_item'])

                elif key == 'u':
                    # SORT BY USING
                    self.main_view['ordering'] = 'people using library'
                    self.main_view['paginator'].objects = self.main_view['paginator'].base_query.order_by(Package.usage_count.desc()).all()
                    self.main_view['current_page'] = 1
                    self._render_package_list(self.main_view['paginator'], self.main_view['current_page'], self.main_view['info'], self.main_view['highlighted_item'])

                elif key == 'c':
                    self.view = "category-choice-view"
                    self._render_category_choice_view(self.category_choice_view['category_paginator'], self.category_choice_view['current_page'], self.main_view['info'], self.category_choice_view['highlighted_item'])


                elif key == 'g':
                    # UPDATE
                    self.view = 'update-view'
                    self.update()
                    self._render_package_list(self.main_view['paginator'], self.main_view['current_page'], self.main_view['info'], self.main_view['highlighted_item'])
                    self.view = 'main-view'

                elif key == 'w':
                    # SORT BY WATCHING
                    self.main_view['ordering'] = 'people wathcing repository'
                    self.main_view['paginator'].objects = self.main_view['paginator'].base_query.order_by(Package.repo_watchers.desc()).all()
                    self.main_view['current_page'] = 1
                    self._render_package_list(self.main_view['paginator'], self.main_view['current_page'], self.main_view['info'], self.main_view['highlighted_item'])

                elif key == 'd':
                    # SORT by Downloads
                    self.main_view['ordering'] = 'PYPI downloads'
                    self.main_view['paginator'].objects = self.main_view['paginator'].base_query.order_by(Package.pypi_downloads.desc()).all()
                    self.main_view['current_page'] = 1
                    self._render_package_list(self.main_view['paginator'], self.main_view['current_page'], self.main_view['info'], self.main_view['highlighted_item'])

                elif ord(key) == 13:
                    # Pressed ENTER onto package
                    self.view = 'package-view'
                    package = self.main_view['paginator'].current_page()[self.main_view['highlighted_item']-1]
                    self._render_package_info(package)

                    rtd_bootstrap = ReadTheDocsBootstrap(proxy=self.proxy)
                    docs = rtd_bootstrap.check_if_docs_exist(package.pypi_package_name or package.repo_name)
                    if docs:
                        self._render_package_info(package, docs=docs)


                elif ord(key) == 72:
                    # pressed UP
                    if not self.main_view['highlighted_item'] <= 1:
                        self.main_view['highlighted_item'] -= 1
                    self._render_package_list(self.main_view['paginator'], self.main_view['current_page'], self.main_view['info'], self.main_view['highlighted_item'])

                elif ord(key) == 80:
                    # pressed DOWN
                    if not self.main_view['highlighted_item'] >= 10:
                        self.main_view['highlighted_item'] += 1
                    self._render_package_list(self.main_view['paginator'], self.main_view['current_page'], self.main_view['info'], self.main_view['highlighted_item'])

                elif ord(key) == 8:
                    # BACKSPACE key
                    self.view = 'menu-view'
                    self._render()

            elif self.view == 'package-view':

                if key == 'i':
                    #INSTALL
                    self.view = "install-view"

                    self._clear_screen()

                    puts(colored.magenta("Installing..."))
                    puts()

                    package = self.main_view['paginator'].current_page()[self.main_view['highlighted_item']-1]
                    result = self.install(package_names=[package.install_string])
                    if not result:
                        package.update_installed_info()
                        self.session.commit()

                    self.main_view['paginator'].refresh_objects()

                    puts()
                    puts(colored.magenta("Press ENTER to continue..."))
                    s = raw_input()

                    self.view = 'package-view'
                    self._render()
                    #self._render_package_info(package)


                elif key == 'u':
                    # UNINSTALL
                    self.view = "install-view"

                    self._clear_screen()

                    puts(colored.magenta("Uninstalling..."))
                    puts()

                    package = self.main_view['paginator'].current_page()[self.main_view['highlighted_item']-1]
                    result = self.uninstall(package_names=[package.pypi_package_name or package.repo_name])
                    if result:
                        puts(result)

                    if not result:
                        package.installed = False
                        self.session.commit()

                    self.main_view['paginator'].refresh_objects()

                    puts()
                    puts(colored.magenta("Press ENTER to continue..."))
                    s = raw_input()

                    self.view = 'package-view'
                    self._render_package_info(package)

                elif ord(key) == 8:
                    # BACKSPACE
                    self.view = 'main-view'
                    self._render_package_list(self.main_view['paginator'], self.main_view['current_page'], self.main_view['info'], self.main_view['highlighted_item'])

                elif key == 'p':
                    # PYPI webpage
                    package = self.main_view['paginator'].current_page()[self.main_view['highlighted_item']-1]
                    webbrowser.open(package.pypi_url)

                elif key == 'r':
                    # REPO page
                    package = self.main_view['paginator'].current_page()[self.main_view['highlighted_item']-1]
                    webbrowser.open(package.repo_url)

            elif self.view == 'installed-view':
                pass

            elif self.view == 'category-choice-view':
                if   key == 'n' or ord(key) == 77:
                    # N = Next page
                    if self.category_choice_view['current_page'] >= self.category_choice_view['category_paginator'].num_pages:
                        puts_err("You are already at the last page")
                        continue

                    self.category_choice_view['current_page'] += 1
                    self._render()
                    #self._render_category_choice_view(self.category_choice_view['category_paginator'], self.category_choice_view['current_page'], self.main_view['info'], self.category_choice_view['highlighted_item'])

                elif key == 'p' or ord(key) == 75:
                    # P = Previous page
                    if self.category_choice_view['current_page'] <= 1:
                        puts_err("You are already at the first page")
                        continue

                    self.category_choice_view['current_page'] -= 1
                    self._render()
                    #self._render_category_choice_view(self.category_choice_view['category_paginator'], self.category_choice_view['current_page'], self.main_view['info'], self.category_choice_view['highlighted_item'])

                elif ord(key) == 13:
                    # Pressed ENTER onto package

                    category = self.category_choice_view['category_paginator'].current_page()[self.category_choice_view['highlighted_item']-1]

                    packages_base_query = self.session.query(Package).filter(Package.categories.any(id=category.id))
                    self.main_view['paginator'] = Paginator(objects=packages_base_query.order_by(Package.pypi_downloads.desc()).all())
                    self.main_view['paginator'].base_query = packages_base_query

                    self.main_view['current_page'] = 1
                    self.main_view['highlighted_item'] = 1
                    self.main_view['info'] = {
                        'Category': category and category.title or 'All',
                        'Package count': len(category.packages),
                    }

                    self.view = 'main-view'
                    self._render()
                    #self._render_package_list(self.main_view['paginator'], self.main_view['current_page'], self.main_view['info'], self.main_view['highlighted_item'])


                elif ord(key) == 72:
                    # pressed UP
                    if not self.category_choice_view['highlighted_item'] <= 1:
                        self.category_choice_view['highlighted_item'] -= 1
                    self._render()
                    #self._render_category_choice_view(self.category_choice_view['category_paginator'], self.category_choice_view['current_page'], self.main_view['info'], self.category_choice_view['highlighted_item'])

                elif ord(key) == 80:
                    # pressed DOWN
                    if not self.category_choice_view['highlighted_item'] >= 10:
                        self.category_choice_view['highlighted_item'] += 1
                    self._render()
                    #self._render_category_choice_view(self.category_choice_view['category_paginator'], self.category_choice_view['current_page'], self.main_view['info'], self.category_choice_view['highlighted_item'])

                elif ord(key) == 8:
                    # BACKSPACE key
                    self.view = 'menu-view'
                    self._render()

                elif key == 'k':
                    # ORDERING by Package count
                    self.category_choice_view['ordering'] = 'package count'
                    #self.category_choice_view['paginator'] = self.category_choice_view['paginator'].base_query.order_by(Category.package.desc()).all()

                    self.main_view['paginator'].objects = self.main_view['paginator'].base_query.order_by(Package.usage_count.desc()).all()
                    self.main_view['current_page'] = 1
                    self._render_package_list(self.main_view['paginator'], self.main_view['current_page'], self.main_view['info'], self.main_view['highlighted_item'])

            elif self.view in ['about-view', 'help-view']:

                if ord(key) == 8:
                    self.view = "menu-view"
                    self._render()