labpack/platforms/heroku.py
def access(self, app_subdomain):

        ''' a method to validate user can access app '''

        title = '%s.access' % self.__class__.__name__
    
    # validate input
        input_fields = {
            'app_subdomain': app_subdomain
        }
        for key, value in input_fields.items():
            object_title = '%s(%s=%s)' % (title, key, str(value))
            self.fields.validate(value, '.%s' % key, object_title)
        
    # verbosity
        self.printer('Checking access to "%s" subdomain ... ' % app_subdomain, flush=True)

    # confirm existence of subdomain
        for app in self.apps:
            if app['name'] == app_subdomain:
                self.subdomain = app_subdomain
                break
    
    # refresh app list and search again
        if not self.subdomain:
            import json
            response = self._handle_command('heroku apps --json', handle_error=True)
            self.apps = json.loads(response)

            for app in self.apps:
                if app['name'] == app_subdomain:
                    self.subdomain = app_subdomain
                    break
    
    # check reason for failure
        if not self.subdomain:
            sys_command = 'heroku ps -a %s' % app_subdomain
            heroku_response = self._handle_command(sys_command, handle_error=True)
            if heroku_response.find('find that app') > -1:
                self.printer('ERROR')
                raise Exception('%s does not exist. Try: heroku create -a %s' % (app_subdomain, app_subdomain))
            elif heroku_response.find('have access to the app') > -1:
                self.printer('ERROR')
                raise Exception('%s belongs to another account.' % app_subdomain)
            else:
                self.printer('ERROR')
                raise Exception('Some unknown issue prevents you from accessing %s' % app_subdomain)

        self.printer('done.')
        
        return self
 a method to validate user can access app 
a method to validate user can access app
a method to validate user can access app
def access(self, app_subdomain):
        title = '%s.access' % self.__class__.__name__
        input_fields = {
            'app_subdomain': app_subdomain
        }
        for key, value in input_fields.items():
            object_title = '%s(%s=%s)' % (title, key, str(value))
            self.fields.validate(value, '.%s' % key, object_title)
        self.printer('Checking access to "%s" subdomain ... ' % app_subdomain, flush=True)
        for app in self.apps:
            if app['name'] == app_subdomain:
                self.subdomain = app_subdomain
                break
        if not self.subdomain:
            import json
            response = self._handle_command('heroku apps --json', handle_error=True)
            self.apps = json.loads(response)
            for app in self.apps:
                if app['name'] == app_subdomain:
                    self.subdomain = app_subdomain
                    break
        if not self.subdomain:
            sys_command = 'heroku ps -a %s' % app_subdomain
            heroku_response = self._handle_command(sys_command, handle_error=True)
            if heroku_response.find('find that app') > -1:
                self.printer('ERROR')
                raise Exception('%s does not exist. Try: heroku create -a %s' % (app_subdomain, app_subdomain))
            elif heroku_response.find('have access to the app') > -1:
                self.printer('ERROR')
                raise Exception('%s belongs to another account.' % app_subdomain)
            else:
                self.printer('ERROR')
                raise Exception('Some unknown issue prevents you from accessing %s' % app_subdomain)
        self.printer('done.')
        return self
def access ( self , app_subdomain ) : title = '%s.access' % self . __class__ . __name__ input_fields = { 'app_subdomain' : app_subdomain } for key , value in input_fields . items ( ) : object_title = '%s(%s=%s)' % ( title , key , str ( value ) ) self . fields . validate ( value , '.%s' % key , object_title ) self . printer ( 'Checking access to "%s" subdomain ... ' % app_subdomain , flush = True ) for app in self . apps : if app [ 'name' ] == app_subdomain : self . subdomain = app_subdomain break if not self . subdomain : import json response = self . _handle_command ( 'heroku apps --json' , handle_error = True ) self . apps = json . loads ( response ) for app in self . apps : if app [ 'name' ] == app_subdomain : self . subdomain = app_subdomain break if not self . subdomain : sys_command = 'heroku ps -a %s' % app_subdomain heroku_response = self . _handle_command ( sys_command , handle_error = True ) if heroku_response . find ( 'find that app' ) > - 1 : self . printer ( 'ERROR' ) raise Exception ( '%s does not exist. Try: heroku create -a %s' % ( app_subdomain , app_subdomain ) ) elif heroku_response . find ( 'have access to the app' ) > - 1 : self . printer ( 'ERROR' ) raise Exception ( '%s belongs to another account.' % app_subdomain ) else : self . printer ( 'ERROR' ) raise Exception ( 'Some unknown issue prevents you from accessing %s' % app_subdomain ) self . printer ( 'done.' ) return self
a method to validate user can access app
a method to validate user can access app
''' a method to validate user can access app ''' # validate input
 # verbosity
 # confirm existence of subdomain
 # refresh app list and search again
 # check reason for failure

self
app_subdomain