示例#1
0
def main(**kwargs):
    """Update info in AWS_ROUTE53 and AWS_IP redis-helper collections"""
    if kwargs['all'] is True:
        for profile in get_profiles():
            route53 = Route53(profile)
            route53.update_collection()
    else:
        route53 = Route53(kwargs['profile'])
        route53.update_collection()
    if kwargs['non_interactive'] is not True:
        ih.start_ipython(route53=AWS_ROUTE53, ip=AWS_IP)
示例#2
0
def main(**kwargs):
    """Update info in AWS_S3 redis-helper collection"""
    if kwargs['all'] is True:
        for profile in get_profiles():
            s3 = S3(profile)
            s3.update_collection()
    else:
        s3 = S3(kwargs['profile'])
        s3.update_collection()
    if kwargs['non_interactive'] is not True:
        ih.start_ipython(s3=AWS_S3, s3_last_file=AWS_S3_LAST_FILE)
示例#3
0
def main(**kwargs):
    """Update info in AWS_EC2 and AWS_IP redis-helper collections"""
    if kwargs['all'] is True:
        for profile in get_profiles():
            ec2 = EC2(profile)
            ec2.update_collection()
    else:
        ec2 = EC2(kwargs['profile'])
        ec2.update_collection()
    if kwargs['non_interactive'] is not True:
        ih.start_ipython(ec2=AWS_EC2, ip=AWS_IP)
示例#4
0
def main():
    """Interactively select a Collection model and start ipython shell"""
    import redis_helper as rh
    import input_helper as ih

    if rh.REDIS is None:
        connected, _ = rh.connect_to_server()
        if not connected:
            raise Exception('Unable to connect to {}'.format(rh.REDIS_URL))
    selected = rh.Collection.select_models(named=True)
    if selected:
        ih.start_ipython(warn=True, rh=rh, ih=ih, **selected)
示例#5
0
def soup_explore(url_or_file, session=None):
    """Given a url or file, get a soup object from it and start ipython session

    - url_or_file: a string
    - session: a session object
    """
    soup = ph.get_soup(url_or_file, session)
    if not soup:
        ph.logger.error('No soup found for {}'.format(url_or_file))
    else:
        print('\nExplore the "soup" object\n\n')
        ih.start_ipython(warn=True, ph=ph, soup=soup)
    return soup
示例#6
0
def main(**kwargs):
    """Get info about EC2 instances"""
    ec2 = EC2(kwargs['profile'])
    ec2.show_instance_info(cache=True)
    if kwargs['non_interactive'] is not True:
        ih.start_ipython(ec2=ec2)
示例#7
0
    def __call__(self):
        print(self._startup_message)
        self._char_hist = []
        self._cmd_hist = []
        while True:
            click.secho(self._prompt, nl=False, fg='cyan', bold=True)
            try:
                ch = click.getchar()
                self._char_hist.append(ch)
            except (EOFError, KeyboardInterrupt):
                break
            else:
                if ch in ['\x03', '\x04']:
                    break

            if ch == '?':
                try:
                    if self._char_hist[-2] == '?':
                        self.docstrings()
                        self.shortcuts()
                    else:
                        print('?\n', self._class_doc())
                        print(self._startup_message)
                except IndexError:
                    print('?\n', self._class_doc())
                    print(self._startup_message)
            elif ch == '-':
                try:
                    if self._pre_input_hook:
                        pre_input_data = self._pre_input_hook()
                    else:
                        pre_input_data = {}
                    user_input = ih.user_input_fancy('', '- ')
                    if self._post_input_hook:
                        post_input_data = self._post_input_hook()
                    else:
                        post_input_data = {}
                    if self._input_hook:
                        bh.call_func(
                            self._input_hook,
                            **user_input,
                            **pre_input_data,
                            **post_input_data,
                            logger=logger
                        )
                    else:
                        self._collection.add(
                            cmd='-',
                            user_input=user_input['text'],
                            status='ok',
                            **pre_input_data,
                            **post_input_data
                        )
                except click.exceptions.Abort:
                    print()
                    continue
            elif ch == ':':
                try:
                    user_input = click.prompt(text='', prompt_suffix=':', default='', show_default=False)
                except click.exceptions.Abort:
                    print()
                    continue
                else:
                    if not user_input:
                        print()
                        continue
                cmd = user_input.split()[0]
                args = user_input.split()[1:]
                self._cmd_hist.append(cmd)

                if cmd == 'pdb':
                    import pdb; pdb.set_trace()
                    continue

                if cmd == 'ipython':
                    ih.start_ipython(warn=True, self=self)
                    continue

                try:
                    cmd_func = getattr(self, cmd)
                except AttributeError:
                    self._collection.add(cmd=cmd, status='error', error_type='invalid command')
                    logger.error('invalid command: {}'.format(cmd))
                    result = self._wishlist.find(
                        'cmd:{}'.format(cmd),
                        admin_fmt=True,
                        item_format='[NOT FULFILLED YET] {message} ({_ts})'
                    )
                    if result:
                        print(result[0])
                    else:
                        message = ih.user_input('what do you wish this command did')
                        if message:
                            self._wishlist.add(cmd=cmd, message=message)
                    continue

                info = bh.call_func(cmd_func, *args, logger=logger)
                info['cmd'] = cmd
                if cmd in self._DONT_LOG_CMDS:
                    info = {}

                if info:
                    self._collection.add(**info)
            elif ch in self._chfunc_dict:
                print(ch)
                bh.call_func(self._chfunc_dict[ch][0], logger=logger)
                if ch in self._break_chars:
                    break
            elif ch in self._break_chars:
                print(ch)
                break
            else:
                try:
                    print(repr(ch), ord(ch))
                except TypeError:
                    # ord() expected a character, but string of length 2 found
                    #   - happens if you press 'Esc' before another key
                    print(repr(ch))
                result = self._wishlist.find(
                    'ch:{}'.format(ch),
                    admin_fmt=True,
                    item_format='[NOT FULFILLED YET] {message} ({_ts})'
                )
                if result:
                    print(result[0])
                else:
                    try:
                        if ch == self._char_hist[-2]:
                            message = ih.user_input('what do you wish this key press did')
                            if message:
                                self._wishlist.add(ch=ch, message=message)
                    except IndexError:
                        pass
示例#8
0
def main(**kwargs):
    """Get info about Route53 resources"""
    route53 = Route53(kwargs['profile'])
    route53.show_resource_info(cache=True)
    if kwargs['non_interactive'] is not True:
        ih.start_ipython(route53=route53)