Python nltk.compat.raw_input() Examples

The following are code examples for showing how to use nltk.compat.raw_input(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: razzy-spinner   Author: rafasashi   File: downloader.py    GNU General Public License v3.0 6 votes vote down vote up
def _simple_interactive_download(self, args):
        if args:
            for arg in args:
                try: self._ds.download(arg, prefix='    ')
                except (IOError, ValueError) as e: print(e)
        else:
            while True:
                print()
                print('Download which package (l=list; x=cancel)?')
                user_input = compat.raw_input('  Identifier> ')
                if user_input.lower()=='l':
                    self._ds.list(self._ds.download_dir, header=False,
                                  more_prompt=True, skip_installed=True)
                    continue
                elif user_input.lower() in ('x', 'q', ''):
                    return
                elif user_input:
                    for id in user_input.split():
                        try: self._ds.download(id, prefix='    ')
                        except (IOError, ValueError) as e: print(e)
                    break 
Example 2
Project: OpenBottle   Author: xiaozhuchacha   File: downloader.py    MIT License 6 votes vote down vote up
def _simple_interactive_download(self, args):
        if args:
            for arg in args:
                try: self._ds.download(arg, prefix='    ')
                except (IOError, ValueError) as e: print(e)
        else:
            while True:
                print()
                print('Download which package (l=list; x=cancel)?')
                user_input = compat.raw_input('  Identifier> ')
                if user_input.lower()=='l':
                    self._ds.list(self._ds.download_dir, header=False,
                                  more_prompt=True, skip_installed=True)
                    continue
                elif user_input.lower() in ('x', 'q', ''):
                    return
                elif user_input:
                    for id in user_input.split():
                        try: self._ds.download(id, prefix='    ')
                        except (IOError, ValueError) as e: print(e)
                    break 
Example 3
Project: OpenBottle   Author: xiaozhuchacha   File: downloader.py    MIT License 6 votes vote down vote up
def _simple_interactive_download(self, args):
        if args:
            for arg in args:
                try: self._ds.download(arg, prefix='    ')
                except (IOError, ValueError) as e: print(e)
        else:
            while True:
                print()
                print('Download which package (l=list; x=cancel)?')
                user_input = compat.raw_input('  Identifier> ')
                if user_input.lower()=='l':
                    self._ds.list(self._ds.download_dir, header=False,
                                  more_prompt=True, skip_installed=True)
                    continue
                elif user_input.lower() in ('x', 'q', ''):
                    return
                elif user_input:
                    for id in user_input.split():
                        try: self._ds.download(id, prefix='    ')
                        except (IOError, ValueError) as e: print(e)
                    break 
Example 4
Project: FancyWord   Author: EastonLee   File: downloader.py    GNU General Public License v3.0 6 votes vote down vote up
def _simple_interactive_download(self, args):
        if args:
            for arg in args:
                try: self._ds.download(arg, prefix='    ')
                except (IOError, ValueError) as e: print(e)
        else:
            while True:
                print()
                print('Download which package (l=list; x=cancel)?')
                user_input = compat.raw_input('  Identifier> ')
                if user_input.lower()=='l':
                    self._ds.list(self._ds.download_dir, header=False,
                                  more_prompt=True, skip_installed=True)
                    continue
                elif user_input.lower() in ('x', 'q', ''):
                    return
                elif user_input:
                    for id in user_input.split():
                        try: self._ds.download(id, prefix='    ')
                        except (IOError, ValueError) as e: print(e)
                    break 
Example 5
Project: Text-Mining   Author: AhirtonLopes   File: text_mining.py    MIT License 6 votes vote down vote up
def remove_accents(self, documents):  
        nDocs = len(documents)
        documentsProcessed = []     
        for iDoc in range(0,nDocs):
            tokens = documents[iDoc]
            nTokens = len(tokens)       
            for iToken in range(0,nTokens):
                # print unicode(tokens[iToken])#tokens[iToken].decode('utf-8')
                #uStr = tokens[iToken].decode('utf-8')#unicode(tokens[iToken])
                #print unicode(tokens[iToken])
                #print tokens[iToken]
                #print unicode(tokens[iToken])
                #print tokens[iToken].decode('utf-8')
                #raw_input('----------------------------')
                strNorm = unicodedata.normalize('NFKD', tokens[iToken]) #.decode('utf-8')
                #strNorm = bytes(strNorm,'utf-8').decode('utf-8')
                tokens[iToken] = strNorm.encode('ASCII', 'ignore').decode()            
                #print(tokens[iToken])
                #raw_input('-------------')
            documentsProcessed.append(tokens)
        return documentsProcessed 
Example 6
Project: honours_project   Author: JFriel   File: downloader.py    GNU General Public License v3.0 6 votes vote down vote up
def _simple_interactive_download(self, args):
        if args:
            for arg in args:
                try: self._ds.download(arg, prefix='    ')
                except (IOError, ValueError) as e: print(e)
        else:
            while True:
                print()
                print('Download which package (l=list; x=cancel)?')
                user_input = compat.raw_input('  Identifier> ')
                if user_input.lower()=='l':
                    self._ds.list(self._ds.download_dir, header=False,
                                  more_prompt=True, skip_installed=True)
                    continue
                elif user_input.lower() in ('x', 'q', ''):
                    return
                elif user_input:
                    for id in user_input.split():
                        try: self._ds.download(id, prefix='    ')
                        except (IOError, ValueError) as e: print(e)
                    break 
Example 7
Project: honours_project   Author: JFriel   File: downloader.py    GNU General Public License v3.0 6 votes vote down vote up
def _simple_interactive_download(self, args):
        if args:
            for arg in args:
                try: self._ds.download(arg, prefix='    ')
                except (IOError, ValueError) as e: print(e)
        else:
            while True:
                print()
                print('Download which package (l=list; x=cancel)?')
                user_input = compat.raw_input('  Identifier> ')
                if user_input.lower()=='l':
                    self._ds.list(self._ds.download_dir, header=False,
                                  more_prompt=True, skip_installed=True)
                    continue
                elif user_input.lower() in ('x', 'q', ''):
                    return
                elif user_input:
                    for id in user_input.split():
                        try: self._ds.download(id, prefix='    ')
                        except (IOError, ValueError) as e: print(e)
                    break 
Example 8
Project: serverless-chatbots-workshop   Author: datteswararao   File: downloader.py    Apache License 2.0 6 votes vote down vote up
def _simple_interactive_download(self, args):
        if args:
            for arg in args:
                try: self._ds.download(arg, prefix='    ')
                except (IOError, ValueError) as e: print(e)
        else:
            while True:
                print()
                print('Download which package (l=list; x=cancel)?')
                user_input = compat.raw_input('  Identifier> ')
                if user_input.lower()=='l':
                    self._ds.list(self._ds.download_dir, header=False,
                                  more_prompt=True, skip_installed=True)
                    continue
                elif user_input.lower() in ('x', 'q', ''):
                    return
                elif user_input:
                    for id in user_input.split():
                        try: self._ds.download(id, prefix='    ')
                        except (IOError, ValueError) as e: print(e)
                    break 
Example 9
Project: serverless-chatbots-workshop   Author: datteswararao   File: downloader.py    Apache License 2.0 6 votes vote down vote up
def _simple_interactive_download(self, args):
        if args:
            for arg in args:
                try: self._ds.download(arg, prefix='    ')
                except (IOError, ValueError) as e: print(e)
        else:
            while True:
                print()
                print('Download which package (l=list; x=cancel)?')
                user_input = compat.raw_input('  Identifier> ')
                if user_input.lower()=='l':
                    self._ds.list(self._ds.download_dir, header=False,
                                  more_prompt=True, skip_installed=True)
                    continue
                elif user_input.lower() in ('x', 'q', ''):
                    return
                elif user_input:
                    for id in user_input.split():
                        try: self._ds.download(id, prefix='    ')
                        except (IOError, ValueError) as e: print(e)
                    break 
Example 10
Project: razzy-spinner   Author: rafasashi   File: downloader.py    GNU General Public License v3.0 5 votes vote down vote up
def list(self, download_dir=None, show_packages=True,
             show_collections=True, header=True, more_prompt=False,
             skip_installed=False):
        lines = 0 # for more_prompt
        if download_dir is None:
            download_dir = self._download_dir
            print('Using default data directory (%s)' % download_dir)
        if header:
            print('='*(26+len(self._url)))
            print(' Data server index for <%s>' % self._url)
            print('='*(26+len(self._url)))
            lines += 3 # for more_prompt
        stale = partial = False

        categories = []
        if show_packages: categories.append('packages')
        if show_collections: categories.append('collections')
        for category in categories:
            print('%s:' % category.capitalize())
            lines += 1 # for more_prompt
            for info in sorted(getattr(self, category)(), key=str):
                status = self.status(info, download_dir)
                if status == self.INSTALLED and skip_installed: continue
                if status == self.STALE: stale = True
                if status == self.PARTIAL: partial = True
                prefix = {self.INSTALLED:'*', self.STALE:'-',
                          self.PARTIAL:'P', self.NOT_INSTALLED: ' '}[status]
                name = textwrap.fill('-'*27 + (info.name or info.id),
                                     75, subsequent_indent=27*' ')[27:]
                print('  [%s] %s %s' % (prefix, info.id.ljust(20, '.'), name))
                lines += len(name.split('\n')) # for more_prompt
                if more_prompt and lines > 20:
                    user_input = compat.raw_input("Hit Enter to continue: ")
                    if (user_input.lower() in ('x', 'q')): return
                    lines = 0
            print()
        msg = '([*] marks installed packages'
        if stale: msg += '; [-] marks out-of-date or corrupt packages'
        if partial: msg += '; [P] marks partially installed collections'
        print(textwrap.fill(msg+')', subsequent_indent=' ', width=76)) 
Example 11
Project: razzy-spinner   Author: rafasashi   File: downloader.py    GNU General Public License v3.0 5 votes vote down vote up
def run(self):
        print('NLTK Downloader')
        while True:
            self._simple_interactive_menu(
                'd) Download', 'l) List', ' u) Update', 'c) Config', 'h) Help', 'q) Quit')
            user_input = compat.raw_input('Downloader> ').strip()
            if not user_input: print(); continue
            command = user_input.lower().split()[0]
            args = user_input.split()[1:]
            try:
                if command == 'l':
                    print()
                    self._ds.list(self._ds.download_dir, header=False,
                                  more_prompt=True)
                elif command == 'h':
                    self._simple_interactive_help()
                elif command == 'c':
                    self._simple_interactive_config()
                elif command in ('q', 'x'):
                    return
                elif command == 'd':
                    self._simple_interactive_download(args)
                elif command == 'u':
                    self._simple_interactive_update()
                else:
                    print('Command %r unrecognized' % user_input)
            except compat.HTTPError as e:
                print('Error reading from server: %s'%e)
            except compat.URLError as e:
                print('Error connecting to server: %s'%e.reason)
            # try checking if user_input is a package name, &
            # downloading it?
            print() 
Example 12
Project: razzy-spinner   Author: rafasashi   File: downloader.py    GNU General Public License v3.0 5 votes vote down vote up
def _simple_interactive_update(self):
        while True:
            stale_packages = []
            stale = partial = False
            for info in sorted(getattr(self._ds, 'packages')(), key=str):
                if self._ds.status(info) == self._ds.STALE:
                    stale_packages.append((info.id, info.name))

            print()
            if stale_packages:
                print('Will update following packages (o=ok; x=cancel)')
                for pid, pname in stale_packages:
                    name = textwrap.fill('-'*27 + (pname),
                                     75, subsequent_indent=27*' ')[27:]
                    print('  [ ] %s %s' % (pid.ljust(20, '.'), name))
                print()

                user_input = compat.raw_input('  Identifier> ')
                if user_input.lower()=='o':
                    for pid, pname in stale_packages:
                        try: self._ds.download(pid, prefix='    ')
                        except (IOError, ValueError) as e: print(e)
                    break
                elif user_input.lower() in ('x', 'q', ''):
                    return
            else:
                print('Nothing to update.')
                return 
Example 13
Project: razzy-spinner   Author: rafasashi   File: downloader.py    GNU General Public License v3.0 5 votes vote down vote up
def _simple_interactive_config(self):
        self._show_config()
        while True:
            print()
            self._simple_interactive_menu(
                's) Show Config', 'u) Set Server URL',
                'd) Set Data Dir', 'm) Main Menu')
            user_input = compat.raw_input('Config> ').strip().lower()
            if user_input == 's':
                self._show_config()
            elif user_input == 'd':
                new_dl_dir = compat.raw_input('  New Directory> ').strip()
                if new_dl_dir in ('', 'x', 'q', 'X', 'Q'):
                    print('  Cancelled!')
                elif os.path.isdir(new_dl_dir):
                    self._ds.download_dir = new_dl_dir
                else:
                    print(('Directory %r not found!  Create it first.' %
                           new_dl_dir))
            elif user_input == 'u':
                new_url = compat.raw_input('  New URL> ').strip()
                if new_url in ('', 'x', 'q', 'X', 'Q'):
                    print('  Cancelled!')
                else:
                    if not new_url.startswith('http://'):
                        new_url = 'http://'+new_url
                    try: self._ds.url = new_url
                    except Exception as e:
                        print('Error reading <%r>:\n  %s' % (new_url, e))
            elif user_input == 'm':
                break 
Example 14
Project: OpenBottle   Author: xiaozhuchacha   File: downloader.py    MIT License 5 votes vote down vote up
def list(self, download_dir=None, show_packages=True,
             show_collections=True, header=True, more_prompt=False,
             skip_installed=False):
        lines = 0 # for more_prompt
        if download_dir is None:
            download_dir = self._download_dir
            print('Using default data directory (%s)' % download_dir)
        if header:
            print('='*(26+len(self._url)))
            print(' Data server index for <%s>' % self._url)
            print('='*(26+len(self._url)))
            lines += 3 # for more_prompt
        stale = partial = False

        categories = []
        if show_packages: categories.append('packages')
        if show_collections: categories.append('collections')
        for category in categories:
            print('%s:' % category.capitalize())
            lines += 1 # for more_prompt
            for info in sorted(getattr(self, category)(), key=str):
                status = self.status(info, download_dir)
                if status == self.INSTALLED and skip_installed: continue
                if status == self.STALE: stale = True
                if status == self.PARTIAL: partial = True
                prefix = {self.INSTALLED:'*', self.STALE:'-',
                          self.PARTIAL:'P', self.NOT_INSTALLED: ' '}[status]
                name = textwrap.fill('-'*27 + (info.name or info.id),
                                     75, subsequent_indent=27*' ')[27:]
                print('  [%s] %s %s' % (prefix, info.id.ljust(20, '.'), name))
                lines += len(name.split('\n')) # for more_prompt
                if more_prompt and lines > 20:
                    user_input = compat.raw_input("Hit Enter to continue: ")
                    if (user_input.lower() in ('x', 'q')): return
                    lines = 0
            print()
        msg = '([*] marks installed packages'
        if stale: msg += '; [-] marks out-of-date or corrupt packages'
        if partial: msg += '; [P] marks partially installed collections'
        print(textwrap.fill(msg+')', subsequent_indent=' ', width=76)) 
Example 15
Project: OpenBottle   Author: xiaozhuchacha   File: downloader.py    MIT License 5 votes vote down vote up
def run(self):
        print('NLTK Downloader')
        while True:
            self._simple_interactive_menu(
                'd) Download', 'l) List', ' u) Update', 'c) Config', 'h) Help', 'q) Quit')
            user_input = compat.raw_input('Downloader> ').strip()
            if not user_input: print(); continue
            command = user_input.lower().split()[0]
            args = user_input.split()[1:]
            try:
                if command == 'l':
                    print()
                    self._ds.list(self._ds.download_dir, header=False,
                                  more_prompt=True)
                elif command == 'h':
                    self._simple_interactive_help()
                elif command == 'c':
                    self._simple_interactive_config()
                elif command in ('q', 'x'):
                    return
                elif command == 'd':
                    self._simple_interactive_download(args)
                elif command == 'u':
                    self._simple_interactive_update()
                else:
                    print('Command %r unrecognized' % user_input)
            except compat.HTTPError as e:
                print('Error reading from server: %s'%e)
            except compat.URLError as e:
                print('Error connecting to server: %s'%e.reason)
            # try checking if user_input is a package name, &
            # downloading it?
            print() 
Example 16
Project: OpenBottle   Author: xiaozhuchacha   File: downloader.py    MIT License 5 votes vote down vote up
def _simple_interactive_update(self):
        while True:
            stale_packages = []
            stale = partial = False
            for info in sorted(getattr(self._ds, 'packages')(), key=str):
                if self._ds.status(info) == self._ds.STALE:
                    stale_packages.append((info.id, info.name))

            print()
            if stale_packages:
                print('Will update following packages (o=ok; x=cancel)')
                for pid, pname in stale_packages:
                    name = textwrap.fill('-'*27 + (pname),
                                     75, subsequent_indent=27*' ')[27:]
                    print('  [ ] %s %s' % (pid.ljust(20, '.'), name))
                print()

                user_input = compat.raw_input('  Identifier> ')
                if user_input.lower()=='o':
                    for pid, pname in stale_packages:
                        try: self._ds.download(pid, prefix='    ')
                        except (IOError, ValueError) as e: print(e)
                    break
                elif user_input.lower() in ('x', 'q', ''):
                    return
            else:
                print('Nothing to update.')
                return 
Example 17
Project: OpenBottle   Author: xiaozhuchacha   File: downloader.py    MIT License 5 votes vote down vote up
def _simple_interactive_config(self):
        self._show_config()
        while True:
            print()
            self._simple_interactive_menu(
                's) Show Config', 'u) Set Server URL',
                'd) Set Data Dir', 'm) Main Menu')
            user_input = compat.raw_input('Config> ').strip().lower()
            if user_input == 's':
                self._show_config()
            elif user_input == 'd':
                new_dl_dir = compat.raw_input('  New Directory> ').strip()
                if new_dl_dir in ('', 'x', 'q', 'X', 'Q'):
                    print('  Cancelled!')
                elif os.path.isdir(new_dl_dir):
                    self._ds.download_dir = new_dl_dir
                else:
                    print(('Directory %r not found!  Create it first.' %
                           new_dl_dir))
            elif user_input == 'u':
                new_url = compat.raw_input('  New URL> ').strip()
                if new_url in ('', 'x', 'q', 'X', 'Q'):
                    print('  Cancelled!')
                else:
                    if not new_url.startswith(('http://', 'https://')):
                        new_url = 'http://'+new_url
                    try: self._ds.url = new_url
                    except Exception as e:
                        print('Error reading <%r>:\n  %s' % (new_url, e))
            elif user_input == 'm':
                break 
Example 18
Project: OpenBottle   Author: xiaozhuchacha   File: downloader.py    MIT License 5 votes vote down vote up
def list(self, download_dir=None, show_packages=True,
             show_collections=True, header=True, more_prompt=False,
             skip_installed=False):
        lines = 0 # for more_prompt
        if download_dir is None:
            download_dir = self._download_dir
            print('Using default data directory (%s)' % download_dir)
        if header:
            print('='*(26+len(self._url)))
            print(' Data server index for <%s>' % self._url)
            print('='*(26+len(self._url)))
            lines += 3 # for more_prompt
        stale = partial = False

        categories = []
        if show_packages: categories.append('packages')
        if show_collections: categories.append('collections')
        for category in categories:
            print('%s:' % category.capitalize())
            lines += 1 # for more_prompt
            for info in sorted(getattr(self, category)(), key=str):
                status = self.status(info, download_dir)
                if status == self.INSTALLED and skip_installed: continue
                if status == self.STALE: stale = True
                if status == self.PARTIAL: partial = True
                prefix = {self.INSTALLED:'*', self.STALE:'-',
                          self.PARTIAL:'P', self.NOT_INSTALLED: ' '}[status]
                name = textwrap.fill('-'*27 + (info.name or info.id),
                                     75, subsequent_indent=27*' ')[27:]
                print('  [%s] %s %s' % (prefix, info.id.ljust(20, '.'), name))
                lines += len(name.split('\n')) # for more_prompt
                if more_prompt and lines > 20:
                    user_input = compat.raw_input("Hit Enter to continue: ")
                    if (user_input.lower() in ('x', 'q')): return
                    lines = 0
            print()
        msg = '([*] marks installed packages'
        if stale: msg += '; [-] marks out-of-date or corrupt packages'
        if partial: msg += '; [P] marks partially installed collections'
        print(textwrap.fill(msg+')', subsequent_indent=' ', width=76)) 
Example 19
Project: OpenBottle   Author: xiaozhuchacha   File: downloader.py    MIT License 5 votes vote down vote up
def run(self):
        print('NLTK Downloader')
        while True:
            self._simple_interactive_menu(
                'd) Download', 'l) List', ' u) Update', 'c) Config', 'h) Help', 'q) Quit')
            user_input = compat.raw_input('Downloader> ').strip()
            if not user_input: print(); continue
            command = user_input.lower().split()[0]
            args = user_input.split()[1:]
            try:
                if command == 'l':
                    print()
                    self._ds.list(self._ds.download_dir, header=False,
                                  more_prompt=True)
                elif command == 'h':
                    self._simple_interactive_help()
                elif command == 'c':
                    self._simple_interactive_config()
                elif command in ('q', 'x'):
                    return
                elif command == 'd':
                    self._simple_interactive_download(args)
                elif command == 'u':
                    self._simple_interactive_update()
                else:
                    print('Command %r unrecognized' % user_input)
            except compat.HTTPError as e:
                print('Error reading from server: %s'%e)
            except compat.URLError as e:
                print('Error connecting to server: %s'%e.reason)
            # try checking if user_input is a package name, &
            # downloading it?
            print() 
Example 20
Project: OpenBottle   Author: xiaozhuchacha   File: downloader.py    MIT License 5 votes vote down vote up
def _simple_interactive_update(self):
        while True:
            stale_packages = []
            stale = partial = False
            for info in sorted(getattr(self._ds, 'packages')(), key=str):
                if self._ds.status(info) == self._ds.STALE:
                    stale_packages.append((info.id, info.name))

            print()
            if stale_packages:
                print('Will update following packages (o=ok; x=cancel)')
                for pid, pname in stale_packages:
                    name = textwrap.fill('-'*27 + (pname),
                                     75, subsequent_indent=27*' ')[27:]
                    print('  [ ] %s %s' % (pid.ljust(20, '.'), name))
                print()

                user_input = compat.raw_input('  Identifier> ')
                if user_input.lower()=='o':
                    for pid, pname in stale_packages:
                        try: self._ds.download(pid, prefix='    ')
                        except (IOError, ValueError) as e: print(e)
                    break
                elif user_input.lower() in ('x', 'q', ''):
                    return
            else:
                print('Nothing to update.')
                return 
Example 21
Project: OpenBottle   Author: xiaozhuchacha   File: downloader.py    MIT License 5 votes vote down vote up
def _simple_interactive_config(self):
        self._show_config()
        while True:
            print()
            self._simple_interactive_menu(
                's) Show Config', 'u) Set Server URL',
                'd) Set Data Dir', 'm) Main Menu')
            user_input = compat.raw_input('Config> ').strip().lower()
            if user_input == 's':
                self._show_config()
            elif user_input == 'd':
                new_dl_dir = compat.raw_input('  New Directory> ').strip()
                if new_dl_dir in ('', 'x', 'q', 'X', 'Q'):
                    print('  Cancelled!')
                elif os.path.isdir(new_dl_dir):
                    self._ds.download_dir = new_dl_dir
                else:
                    print(('Directory %r not found!  Create it first.' %
                           new_dl_dir))
            elif user_input == 'u':
                new_url = compat.raw_input('  New URL> ').strip()
                if new_url in ('', 'x', 'q', 'X', 'Q'):
                    print('  Cancelled!')
                else:
                    if not new_url.startswith(('http://', 'https://')):
                        new_url = 'http://'+new_url
                    try: self._ds.url = new_url
                    except Exception as e:
                        print('Error reading <%r>:\n  %s' % (new_url, e))
            elif user_input == 'm':
                break 
Example 22
Project: FancyWord   Author: EastonLee   File: downloader.py    GNU General Public License v3.0 5 votes vote down vote up
def list(self, download_dir=None, show_packages=True,
             show_collections=True, header=True, more_prompt=False,
             skip_installed=False):
        lines = 0 # for more_prompt
        if download_dir is None:
            download_dir = self._download_dir
            print('Using default data directory (%s)' % download_dir)
        if header:
            print('='*(26+len(self._url)))
            print(' Data server index for <%s>' % self._url)
            print('='*(26+len(self._url)))
            lines += 3 # for more_prompt
        stale = partial = False

        categories = []
        if show_packages: categories.append('packages')
        if show_collections: categories.append('collections')
        for category in categories:
            print('%s:' % category.capitalize())
            lines += 1 # for more_prompt
            for info in sorted(getattr(self, category)(), key=str):
                status = self.status(info, download_dir)
                if status == self.INSTALLED and skip_installed: continue
                if status == self.STALE: stale = True
                if status == self.PARTIAL: partial = True
                prefix = {self.INSTALLED:'*', self.STALE:'-',
                          self.PARTIAL:'P', self.NOT_INSTALLED: ' '}[status]
                name = textwrap.fill('-'*27 + (info.name or info.id),
                                     75, subsequent_indent=27*' ')[27:]
                print('  [%s] %s %s' % (prefix, info.id.ljust(20, '.'), name))
                lines += len(name.split('\n')) # for more_prompt
                if more_prompt and lines > 20:
                    user_input = compat.raw_input("Hit Enter to continue: ")
                    if (user_input.lower() in ('x', 'q')): return
                    lines = 0
            print()
        msg = '([*] marks installed packages'
        if stale: msg += '; [-] marks out-of-date or corrupt packages'
        if partial: msg += '; [P] marks partially installed collections'
        print(textwrap.fill(msg+')', subsequent_indent=' ', width=76)) 
Example 23
Project: FancyWord   Author: EastonLee   File: downloader.py    GNU General Public License v3.0 5 votes vote down vote up
def run(self):
        print('NLTK Downloader')
        while True:
            self._simple_interactive_menu(
                'd) Download', 'l) List', ' u) Update', 'c) Config', 'h) Help', 'q) Quit')
            user_input = compat.raw_input('Downloader> ').strip()
            if not user_input: print(); continue
            command = user_input.lower().split()[0]
            args = user_input.split()[1:]
            try:
                if command == 'l':
                    print()
                    self._ds.list(self._ds.download_dir, header=False,
                                  more_prompt=True)
                elif command == 'h':
                    self._simple_interactive_help()
                elif command == 'c':
                    self._simple_interactive_config()
                elif command in ('q', 'x'):
                    return
                elif command == 'd':
                    self._simple_interactive_download(args)
                elif command == 'u':
                    self._simple_interactive_update()
                else:
                    print('Command %r unrecognized' % user_input)
            except compat.HTTPError as e:
                print('Error reading from server: %s'%e)
            except compat.URLError as e:
                print('Error connecting to server: %s'%e.reason)
            # try checking if user_input is a package name, &
            # downloading it?
            print() 
Example 24
Project: FancyWord   Author: EastonLee   File: downloader.py    GNU General Public License v3.0 5 votes vote down vote up
def _simple_interactive_update(self):
        while True:
            stale_packages = []
            stale = partial = False
            for info in sorted(getattr(self._ds, 'packages')(), key=str):
                if self._ds.status(info) == self._ds.STALE:
                    stale_packages.append((info.id, info.name))

            print()
            if stale_packages:
                print('Will update following packages (o=ok; x=cancel)')
                for pid, pname in stale_packages:
                    name = textwrap.fill('-'*27 + (pname),
                                     75, subsequent_indent=27*' ')[27:]
                    print('  [ ] %s %s' % (pid.ljust(20, '.'), name))
                print()

                user_input = compat.raw_input('  Identifier> ')
                if user_input.lower()=='o':
                    for pid, pname in stale_packages:
                        try: self._ds.download(pid, prefix='    ')
                        except (IOError, ValueError) as e: print(e)
                    break
                elif user_input.lower() in ('x', 'q', ''):
                    return
            else:
                print('Nothing to update.')
                return 
Example 25
Project: FancyWord   Author: EastonLee   File: downloader.py    GNU General Public License v3.0 5 votes vote down vote up
def _simple_interactive_config(self):
        self._show_config()
        while True:
            print()
            self._simple_interactive_menu(
                's) Show Config', 'u) Set Server URL',
                'd) Set Data Dir', 'm) Main Menu')
            user_input = compat.raw_input('Config> ').strip().lower()
            if user_input == 's':
                self._show_config()
            elif user_input == 'd':
                new_dl_dir = compat.raw_input('  New Directory> ').strip()
                if new_dl_dir in ('', 'x', 'q', 'X', 'Q'):
                    print('  Cancelled!')
                elif os.path.isdir(new_dl_dir):
                    self._ds.download_dir = new_dl_dir
                else:
                    print(('Directory %r not found!  Create it first.' %
                           new_dl_dir))
            elif user_input == 'u':
                new_url = compat.raw_input('  New URL> ').strip()
                if new_url in ('', 'x', 'q', 'X', 'Q'):
                    print('  Cancelled!')
                else:
                    if not new_url.startswith('http://'):
                        new_url = 'http://'+new_url
                    try: self._ds.url = new_url
                    except Exception as e:
                        print('Error reading <%r>:\n  %s' % (new_url, e))
            elif user_input == 'm':
                break 
Example 26
Project: honours_project   Author: JFriel   File: downloader.py    GNU General Public License v3.0 5 votes vote down vote up
def list(self, download_dir=None, show_packages=True,
             show_collections=True, header=True, more_prompt=False,
             skip_installed=False):
        lines = 0 # for more_prompt
        if download_dir is None:
            download_dir = self._download_dir
            print('Using default data directory (%s)' % download_dir)
        if header:
            print('='*(26+len(self._url)))
            print(' Data server index for <%s>' % self._url)
            print('='*(26+len(self._url)))
            lines += 3 # for more_prompt
        stale = partial = False

        categories = []
        if show_packages: categories.append('packages')
        if show_collections: categories.append('collections')
        for category in categories:
            print('%s:' % category.capitalize())
            lines += 1 # for more_prompt
            for info in sorted(getattr(self, category)(), key=str):
                status = self.status(info, download_dir)
                if status == self.INSTALLED and skip_installed: continue
                if status == self.STALE: stale = True
                if status == self.PARTIAL: partial = True
                prefix = {self.INSTALLED:'*', self.STALE:'-',
                          self.PARTIAL:'P', self.NOT_INSTALLED: ' '}[status]
                name = textwrap.fill('-'*27 + (info.name or info.id),
                                     75, subsequent_indent=27*' ')[27:]
                print('  [%s] %s %s' % (prefix, info.id.ljust(20, '.'), name))
                lines += len(name.split('\n')) # for more_prompt
                if more_prompt and lines > 20:
                    user_input = compat.raw_input("Hit Enter to continue: ")
                    if (user_input.lower() in ('x', 'q')): return
                    lines = 0
            print()
        msg = '([*] marks installed packages'
        if stale: msg += '; [-] marks out-of-date or corrupt packages'
        if partial: msg += '; [P] marks partially installed collections'
        print(textwrap.fill(msg+')', subsequent_indent=' ', width=76)) 
Example 27
Project: honours_project   Author: JFriel   File: downloader.py    GNU General Public License v3.0 5 votes vote down vote up
def run(self):
        print('NLTK Downloader')
        while True:
            self._simple_interactive_menu(
                'd) Download', 'l) List', ' u) Update', 'c) Config', 'h) Help', 'q) Quit')
            user_input = compat.raw_input('Downloader> ').strip()
            if not user_input: print(); continue
            command = user_input.lower().split()[0]
            args = user_input.split()[1:]
            try:
                if command == 'l':
                    print()
                    self._ds.list(self._ds.download_dir, header=False,
                                  more_prompt=True)
                elif command == 'h':
                    self._simple_interactive_help()
                elif command == 'c':
                    self._simple_interactive_config()
                elif command in ('q', 'x'):
                    return
                elif command == 'd':
                    self._simple_interactive_download(args)
                elif command == 'u':
                    self._simple_interactive_update()
                else:
                    print('Command %r unrecognized' % user_input)
            except compat.HTTPError as e:
                print('Error reading from server: %s'%e)
            except compat.URLError as e:
                print('Error connecting to server: %s'%e.reason)
            # try checking if user_input is a package name, &
            # downloading it?
            print() 
Example 28
Project: honours_project   Author: JFriel   File: downloader.py    GNU General Public License v3.0 5 votes vote down vote up
def _simple_interactive_update(self):
        while True:
            stale_packages = []
            stale = partial = False
            for info in sorted(getattr(self._ds, 'packages')(), key=str):
                if self._ds.status(info) == self._ds.STALE:
                    stale_packages.append((info.id, info.name))

            print()
            if stale_packages:
                print('Will update following packages (o=ok; x=cancel)')
                for pid, pname in stale_packages:
                    name = textwrap.fill('-'*27 + (pname),
                                     75, subsequent_indent=27*' ')[27:]
                    print('  [ ] %s %s' % (pid.ljust(20, '.'), name))
                print()

                user_input = compat.raw_input('  Identifier> ')
                if user_input.lower()=='o':
                    for pid, pname in stale_packages:
                        try: self._ds.download(pid, prefix='    ')
                        except (IOError, ValueError) as e: print(e)
                    break
                elif user_input.lower() in ('x', 'q', ''):
                    return
            else:
                print('Nothing to update.')
                return 
Example 29
Project: honours_project   Author: JFriel   File: downloader.py    GNU General Public License v3.0 5 votes vote down vote up
def _simple_interactive_config(self):
        self._show_config()
        while True:
            print()
            self._simple_interactive_menu(
                's) Show Config', 'u) Set Server URL',
                'd) Set Data Dir', 'm) Main Menu')
            user_input = compat.raw_input('Config> ').strip().lower()
            if user_input == 's':
                self._show_config()
            elif user_input == 'd':
                new_dl_dir = compat.raw_input('  New Directory> ').strip()
                if new_dl_dir in ('', 'x', 'q', 'X', 'Q'):
                    print('  Cancelled!')
                elif os.path.isdir(new_dl_dir):
                    self._ds.download_dir = new_dl_dir
                else:
                    print(('Directory %r not found!  Create it first.' %
                           new_dl_dir))
            elif user_input == 'u':
                new_url = compat.raw_input('  New URL> ').strip()
                if new_url in ('', 'x', 'q', 'X', 'Q'):
                    print('  Cancelled!')
                else:
                    if not new_url.startswith(('http://', 'https://')):
                        new_url = 'http://'+new_url
                    try: self._ds.url = new_url
                    except Exception as e:
                        print('Error reading <%r>:\n  %s' % (new_url, e))
            elif user_input == 'm':
                break 
Example 30
Project: honours_project   Author: JFriel   File: downloader.py    GNU General Public License v3.0 5 votes vote down vote up
def list(self, download_dir=None, show_packages=True,
             show_collections=True, header=True, more_prompt=False,
             skip_installed=False):
        lines = 0 # for more_prompt
        if download_dir is None:
            download_dir = self._download_dir
            print('Using default data directory (%s)' % download_dir)
        if header:
            print('='*(26+len(self._url)))
            print(' Data server index for <%s>' % self._url)
            print('='*(26+len(self._url)))
            lines += 3 # for more_prompt
        stale = partial = False

        categories = []
        if show_packages: categories.append('packages')
        if show_collections: categories.append('collections')
        for category in categories:
            print('%s:' % category.capitalize())
            lines += 1 # for more_prompt
            for info in sorted(getattr(self, category)(), key=str):
                status = self.status(info, download_dir)
                if status == self.INSTALLED and skip_installed: continue
                if status == self.STALE: stale = True
                if status == self.PARTIAL: partial = True
                prefix = {self.INSTALLED:'*', self.STALE:'-',
                          self.PARTIAL:'P', self.NOT_INSTALLED: ' '}[status]
                name = textwrap.fill('-'*27 + (info.name or info.id),
                                     75, subsequent_indent=27*' ')[27:]
                print('  [%s] %s %s' % (prefix, info.id.ljust(20, '.'), name))
                lines += len(name.split('\n')) # for more_prompt
                if more_prompt and lines > 20:
                    user_input = compat.raw_input("Hit Enter to continue: ")
                    if (user_input.lower() in ('x', 'q')): return
                    lines = 0
            print()
        msg = '([*] marks installed packages'
        if stale: msg += '; [-] marks out-of-date or corrupt packages'
        if partial: msg += '; [P] marks partially installed collections'
        print(textwrap.fill(msg+')', subsequent_indent=' ', width=76)) 
Example 31
Project: honours_project   Author: JFriel   File: downloader.py    GNU General Public License v3.0 5 votes vote down vote up
def run(self):
        print('NLTK Downloader')
        while True:
            self._simple_interactive_menu(
                'd) Download', 'l) List', ' u) Update', 'c) Config', 'h) Help', 'q) Quit')
            user_input = compat.raw_input('Downloader> ').strip()
            if not user_input: print(); continue
            command = user_input.lower().split()[0]
            args = user_input.split()[1:]
            try:
                if command == 'l':
                    print()
                    self._ds.list(self._ds.download_dir, header=False,
                                  more_prompt=True)
                elif command == 'h':
                    self._simple_interactive_help()
                elif command == 'c':
                    self._simple_interactive_config()
                elif command in ('q', 'x'):
                    return
                elif command == 'd':
                    self._simple_interactive_download(args)
                elif command == 'u':
                    self._simple_interactive_update()
                else:
                    print('Command %r unrecognized' % user_input)
            except compat.HTTPError as e:
                print('Error reading from server: %s'%e)
            except compat.URLError as e:
                print('Error connecting to server: %s'%e.reason)
            # try checking if user_input is a package name, &
            # downloading it?
            print() 
Example 32
Project: honours_project   Author: JFriel   File: downloader.py    GNU General Public License v3.0 5 votes vote down vote up
def _simple_interactive_update(self):
        while True:
            stale_packages = []
            stale = partial = False
            for info in sorted(getattr(self._ds, 'packages')(), key=str):
                if self._ds.status(info) == self._ds.STALE:
                    stale_packages.append((info.id, info.name))

            print()
            if stale_packages:
                print('Will update following packages (o=ok; x=cancel)')
                for pid, pname in stale_packages:
                    name = textwrap.fill('-'*27 + (pname),
                                     75, subsequent_indent=27*' ')[27:]
                    print('  [ ] %s %s' % (pid.ljust(20, '.'), name))
                print()

                user_input = compat.raw_input('  Identifier> ')
                if user_input.lower()=='o':
                    for pid, pname in stale_packages:
                        try: self._ds.download(pid, prefix='    ')
                        except (IOError, ValueError) as e: print(e)
                    break
                elif user_input.lower() in ('x', 'q', ''):
                    return
            else:
                print('Nothing to update.')
                return 
Example 33
Project: honours_project   Author: JFriel   File: downloader.py    GNU General Public License v3.0 5 votes vote down vote up
def _simple_interactive_config(self):
        self._show_config()
        while True:
            print()
            self._simple_interactive_menu(
                's) Show Config', 'u) Set Server URL',
                'd) Set Data Dir', 'm) Main Menu')
            user_input = compat.raw_input('Config> ').strip().lower()
            if user_input == 's':
                self._show_config()
            elif user_input == 'd':
                new_dl_dir = compat.raw_input('  New Directory> ').strip()
                if new_dl_dir in ('', 'x', 'q', 'X', 'Q'):
                    print('  Cancelled!')
                elif os.path.isdir(new_dl_dir):
                    self._ds.download_dir = new_dl_dir
                else:
                    print(('Directory %r not found!  Create it first.' %
                           new_dl_dir))
            elif user_input == 'u':
                new_url = compat.raw_input('  New URL> ').strip()
                if new_url in ('', 'x', 'q', 'X', 'Q'):
                    print('  Cancelled!')
                else:
                    if not new_url.startswith(('http://', 'https://')):
                        new_url = 'http://'+new_url
                    try: self._ds.url = new_url
                    except Exception as e:
                        print('Error reading <%r>:\n  %s' % (new_url, e))
            elif user_input == 'm':
                break 
Example 34
Project: serverless-chatbots-workshop   Author: datteswararao   File: downloader.py    Apache License 2.0 5 votes vote down vote up
def list(self, download_dir=None, show_packages=True,
             show_collections=True, header=True, more_prompt=False,
             skip_installed=False):
        lines = 0 # for more_prompt
        if download_dir is None:
            download_dir = self._download_dir
            print('Using default data directory (%s)' % download_dir)
        if header:
            print('='*(26+len(self._url)))
            print(' Data server index for <%s>' % self._url)
            print('='*(26+len(self._url)))
            lines += 3 # for more_prompt
        stale = partial = False

        categories = []
        if show_packages: categories.append('packages')
        if show_collections: categories.append('collections')
        for category in categories:
            print('%s:' % category.capitalize())
            lines += 1 # for more_prompt
            for info in sorted(getattr(self, category)(), key=str):
                status = self.status(info, download_dir)
                if status == self.INSTALLED and skip_installed: continue
                if status == self.STALE: stale = True
                if status == self.PARTIAL: partial = True
                prefix = {self.INSTALLED:'*', self.STALE:'-',
                          self.PARTIAL:'P', self.NOT_INSTALLED: ' '}[status]
                name = textwrap.fill('-'*27 + (info.name or info.id),
                                     75, subsequent_indent=27*' ')[27:]
                print('  [%s] %s %s' % (prefix, info.id.ljust(20, '.'), name))
                lines += len(name.split('\n')) # for more_prompt
                if more_prompt and lines > 20:
                    user_input = compat.raw_input("Hit Enter to continue: ")
                    if (user_input.lower() in ('x', 'q')): return
                    lines = 0
            print()
        msg = '([*] marks installed packages'
        if stale: msg += '; [-] marks out-of-date or corrupt packages'
        if partial: msg += '; [P] marks partially installed collections'
        print(textwrap.fill(msg+')', subsequent_indent=' ', width=76)) 
Example 35
Project: serverless-chatbots-workshop   Author: datteswararao   File: downloader.py    Apache License 2.0 5 votes vote down vote up
def run(self):
        print('NLTK Downloader')
        while True:
            self._simple_interactive_menu(
                'd) Download', 'l) List', ' u) Update', 'c) Config', 'h) Help', 'q) Quit')
            user_input = compat.raw_input('Downloader> ').strip()
            if not user_input: print(); continue
            command = user_input.lower().split()[0]
            args = user_input.split()[1:]
            try:
                if command == 'l':
                    print()
                    self._ds.list(self._ds.download_dir, header=False,
                                  more_prompt=True)
                elif command == 'h':
                    self._simple_interactive_help()
                elif command == 'c':
                    self._simple_interactive_config()
                elif command in ('q', 'x'):
                    return
                elif command == 'd':
                    self._simple_interactive_download(args)
                elif command == 'u':
                    self._simple_interactive_update()
                else:
                    print('Command %r unrecognized' % user_input)
            except compat.HTTPError as e:
                print('Error reading from server: %s'%e)
            except compat.URLError as e:
                print('Error connecting to server: %s'%e.reason)
            # try checking if user_input is a package name, &
            # downloading it?
            print() 
Example 36
Project: serverless-chatbots-workshop   Author: datteswararao   File: downloader.py    Apache License 2.0 5 votes vote down vote up
def _simple_interactive_update(self):
        while True:
            stale_packages = []
            stale = partial = False
            for info in sorted(getattr(self._ds, 'packages')(), key=str):
                if self._ds.status(info) == self._ds.STALE:
                    stale_packages.append((info.id, info.name))

            print()
            if stale_packages:
                print('Will update following packages (o=ok; x=cancel)')
                for pid, pname in stale_packages:
                    name = textwrap.fill('-'*27 + (pname),
                                     75, subsequent_indent=27*' ')[27:]
                    print('  [ ] %s %s' % (pid.ljust(20, '.'), name))
                print()

                user_input = compat.raw_input('  Identifier> ')
                if user_input.lower()=='o':
                    for pid, pname in stale_packages:
                        try: self._ds.download(pid, prefix='    ')
                        except (IOError, ValueError) as e: print(e)
                    break
                elif user_input.lower() in ('x', 'q', ''):
                    return
            else:
                print('Nothing to update.')
                return 
Example 37
Project: serverless-chatbots-workshop   Author: datteswararao   File: downloader.py    Apache License 2.0 5 votes vote down vote up
def _simple_interactive_config(self):
        self._show_config()
        while True:
            print()
            self._simple_interactive_menu(
                's) Show Config', 'u) Set Server URL',
                'd) Set Data Dir', 'm) Main Menu')
            user_input = compat.raw_input('Config> ').strip().lower()
            if user_input == 's':
                self._show_config()
            elif user_input == 'd':
                new_dl_dir = compat.raw_input('  New Directory> ').strip()
                if new_dl_dir in ('', 'x', 'q', 'X', 'Q'):
                    print('  Cancelled!')
                elif os.path.isdir(new_dl_dir):
                    self._ds.download_dir = new_dl_dir
                else:
                    print(('Directory %r not found!  Create it first.' %
                           new_dl_dir))
            elif user_input == 'u':
                new_url = compat.raw_input('  New URL> ').strip()
                if new_url in ('', 'x', 'q', 'X', 'Q'):
                    print('  Cancelled!')
                else:
                    if not new_url.startswith(('http://', 'https://')):
                        new_url = 'http://'+new_url
                    try: self._ds.url = new_url
                    except Exception as e:
                        print('Error reading <%r>:\n  %s' % (new_url, e))
            elif user_input == 'm':
                break 
Example 38
Project: serverless-chatbots-workshop   Author: datteswararao   File: downloader.py    Apache License 2.0 5 votes vote down vote up
def list(self, download_dir=None, show_packages=True,
             show_collections=True, header=True, more_prompt=False,
             skip_installed=False):
        lines = 0 # for more_prompt
        if download_dir is None:
            download_dir = self._download_dir
            print('Using default data directory (%s)' % download_dir)
        if header:
            print('='*(26+len(self._url)))
            print(' Data server index for <%s>' % self._url)
            print('='*(26+len(self._url)))
            lines += 3 # for more_prompt
        stale = partial = False

        categories = []
        if show_packages: categories.append('packages')
        if show_collections: categories.append('collections')
        for category in categories:
            print('%s:' % category.capitalize())
            lines += 1 # for more_prompt
            for info in sorted(getattr(self, category)(), key=str):
                status = self.status(info, download_dir)
                if status == self.INSTALLED and skip_installed: continue
                if status == self.STALE: stale = True
                if status == self.PARTIAL: partial = True
                prefix = {self.INSTALLED:'*', self.STALE:'-',
                          self.PARTIAL:'P', self.NOT_INSTALLED: ' '}[status]
                name = textwrap.fill('-'*27 + (info.name or info.id),
                                     75, subsequent_indent=27*' ')[27:]
                print('  [%s] %s %s' % (prefix, info.id.ljust(20, '.'), name))
                lines += len(name.split('\n')) # for more_prompt
                if more_prompt and lines > 20:
                    user_input = compat.raw_input("Hit Enter to continue: ")
                    if (user_input.lower() in ('x', 'q')): return
                    lines = 0
            print()
        msg = '([*] marks installed packages'
        if stale: msg += '; [-] marks out-of-date or corrupt packages'
        if partial: msg += '; [P] marks partially installed collections'
        print(textwrap.fill(msg+')', subsequent_indent=' ', width=76)) 
Example 39
Project: serverless-chatbots-workshop   Author: datteswararao   File: downloader.py    Apache License 2.0 5 votes vote down vote up
def run(self):
        print('NLTK Downloader')
        while True:
            self._simple_interactive_menu(
                'd) Download', 'l) List', ' u) Update', 'c) Config', 'h) Help', 'q) Quit')
            user_input = compat.raw_input('Downloader> ').strip()
            if not user_input: print(); continue
            command = user_input.lower().split()[0]
            args = user_input.split()[1:]
            try:
                if command == 'l':
                    print()
                    self._ds.list(self._ds.download_dir, header=False,
                                  more_prompt=True)
                elif command == 'h':
                    self._simple_interactive_help()
                elif command == 'c':
                    self._simple_interactive_config()
                elif command in ('q', 'x'):
                    return
                elif command == 'd':
                    self._simple_interactive_download(args)
                elif command == 'u':
                    self._simple_interactive_update()
                else:
                    print('Command %r unrecognized' % user_input)
            except compat.HTTPError as e:
                print('Error reading from server: %s'%e)
            except compat.URLError as e:
                print('Error connecting to server: %s'%e.reason)
            # try checking if user_input is a package name, &
            # downloading it?
            print() 
Example 40
Project: serverless-chatbots-workshop   Author: datteswararao   File: downloader.py    Apache License 2.0 5 votes vote down vote up
def _simple_interactive_update(self):
        while True:
            stale_packages = []
            stale = partial = False
            for info in sorted(getattr(self._ds, 'packages')(), key=str):
                if self._ds.status(info) == self._ds.STALE:
                    stale_packages.append((info.id, info.name))

            print()
            if stale_packages:
                print('Will update following packages (o=ok; x=cancel)')
                for pid, pname in stale_packages:
                    name = textwrap.fill('-'*27 + (pname),
                                     75, subsequent_indent=27*' ')[27:]
                    print('  [ ] %s %s' % (pid.ljust(20, '.'), name))
                print()

                user_input = compat.raw_input('  Identifier> ')
                if user_input.lower()=='o':
                    for pid, pname in stale_packages:
                        try: self._ds.download(pid, prefix='    ')
                        except (IOError, ValueError) as e: print(e)
                    break
                elif user_input.lower() in ('x', 'q', ''):
                    return
            else:
                print('Nothing to update.')
                return 
Example 41
Project: serverless-chatbots-workshop   Author: datteswararao   File: downloader.py    Apache License 2.0 5 votes vote down vote up
def _simple_interactive_config(self):
        self._show_config()
        while True:
            print()
            self._simple_interactive_menu(
                's) Show Config', 'u) Set Server URL',
                'd) Set Data Dir', 'm) Main Menu')
            user_input = compat.raw_input('Config> ').strip().lower()
            if user_input == 's':
                self._show_config()
            elif user_input == 'd':
                new_dl_dir = compat.raw_input('  New Directory> ').strip()
                if new_dl_dir in ('', 'x', 'q', 'X', 'Q'):
                    print('  Cancelled!')
                elif os.path.isdir(new_dl_dir):
                    self._ds.download_dir = new_dl_dir
                else:
                    print(('Directory %r not found!  Create it first.' %
                           new_dl_dir))
            elif user_input == 'u':
                new_url = compat.raw_input('  New URL> ').strip()
                if new_url in ('', 'x', 'q', 'X', 'Q'):
                    print('  Cancelled!')
                else:
                    if not new_url.startswith(('http://', 'https://')):
                        new_url = 'http://'+new_url
                    try: self._ds.url = new_url
                    except Exception as e:
                        print('Error reading <%r>:\n  %s' % (new_url, e))
            elif user_input == 'm':
                break