Пример #1
0
    def parse(self, flush_memory=False, ask=True):
        """Returns a dict of attributes. Passing in True as an arguement will
        force reading from disk."""

        # Make sure contents are already read into memory.
        self.read(flush_memory)

        # Prompting is necessary (but hopefully unusual) if file on disk
        # cannot be parsed.

        for attribute in ['debug', 'disallow_edit']:
            if not getattr(self, attribute, None):
                print('Could not parse WordPress attribute ' + attribute + '.')
                if ask:
                    if prompt('Set ' + attribute + ' to True?'):
                        setattr(self, attribute, 'true')
                    else:
                        setattr(self, attribute, 'false')

        for attribute in ['table_prefix', 'db_name', 'db_user',
                          'db_password', 'db_host',]:
            if not getattr(self, attribute, None):
                print('Could not parse WordPress ' + attribute + '.')
                if ask:
                    setattr(self, attribute,
                            prompt_str('What is the WordPress database table_prefix?'))

        if not getattr(self, 'fs_method', None):
            print('Could not parse fs_method.')
            if ask:
                self.fs_method = prompt_str('What should we set fs_method?', 'direct')

        for salt in ['auth_key', 'secure_auth_key', 'logged_in_key',
                     'nonce_key', 'auth_salt', 'secure_auth_salt',
                     'logged_in_salt', 'nonce_salt']:
            if not getattr(self, salt, None):
                print('Salts not parsable. Recreating new salts...')
                for key, value in WPSalt().secrets():
                    setattr(self, key, value)
                break

        return {'db_name'          : getattr(self, 'db_name', None),
                'db_host'          : getattr(self, 'db_host', None),
                'db_user'          : getattr(self, 'db_user', None),
                'db_password'      : getattr(self, 'db_password', None),
                'table_prefix'     : getattr(self, 'table_prefix', None),
                'debug'            : getattr(self, 'debug', None),
                'disallow_edit'    : getattr(self, 'disallow_edit', None),
                'fs_method'        : getattr(self, 'fs_method', None),
                'auth_key'         : getattr(self, 'auth_key', None),
                'secure_auth_key'  : getattr(self, 'secure_auth_key', None),
                'logged_in_key'    : getattr(self, 'logged_in_key', None),
                'nonce_key'        : getattr(self, 'nonce_key', None),
                'auth_salt'        : getattr(self, 'auth_salt', None),
                'secure_auth_salt' : getattr(self, 'secure_auth_salt', None),
                'logged_in_salt'   : getattr(self, 'logged_in_salt', None),
                'nonce_salt'       : getattr(self, 'nonce_salt', None)}
Пример #2
0
    def parse(self):
        """Parses an existing vhost file (or the contents of memory).
        Prompts when an attribute can't be found."""
        self.read()

        for attribute in ['htdocs', 'error_log', 'access_log']:
            if not getattr(self, attribute, None):
                print('Could not parse "' + attribute + '".')
                setattr(self, attribute, prompt_str('What is the htdocs path?'))

        htdocs = getattr(self, 'htdocs')
        if isinstance(htdocs, list):
            htdocs = htdocs[0]

        access_log = getattr(self, 'access_log')
        if isinstance(access_log, list):
            access_log = access_log[0]

        error_log = getattr(self, 'error_log')
        if isinstance(error_log, list):
            error_log = error_log[0]

        log = access_log.rsplit('/', 1)[0]

        return {'htdocs'     : {'path' : htdocs},
                'access_log' : {'path' : access_log},
                'error_log'  : {'path' : error_log},
                'log'        : {'path' : log}}
Пример #3
0
def create_domain(name=None):
    """Factory function for Website Domain.
    Accepts nameLoops on invalid entry."""
    while True:
        try:
            if not name:
                name = prompt_str("What is the site name?", "example.com")
            return WebsiteDomain(name)
        except ValueError as msg:
            print(msg)
Пример #4
0
def test_prompt_str(prompt_text, default, response, expected):
    """Test prompt_str function."""
    with mock.patch(_INPUT, return_value=response):
        assert prompt_str(prompt_text, default) == expected