Esempio n. 1
0
class Command(BaseCommand):
    name = 'list_projects'
    help = 'Creates a list of applications and projects that contain a certain word in their name'\
        ' (Proof of Concept only!)'

    def configure(self):
        self.api = APIBase(self.config)
        self.config.opts.add('search_string', "The string to search the name of projects against. Use empty to list all",
                             default='')

    def handle(self):
        search_str = self.config['search_string']

        bu_list = self.api.get_business_units()
        for bu in bu_list:
            bu_output = False
            app_list = self.api.get_applications(business_unit=bu['id'])
            for app in app_list:
                app_output = False
                prj_list = self.api.get_projects(app['id'])
                for prj in prj_list:
                    if search_str in prj['name']:
                        if not bu_output:
                            bu_output = True
                            print 'BU %s: %s' % (bu['id'], bu['name'])
                        if not app_output:
                            app_output = True
                            print '  App %s: %s' % (app['id'], app['name'])
                        print '    Prj %s: %s' % (prj['id'], prj['name'])
        return True