def update_tcex_json(self):
        """Update the tcex.json configuration file if exists."""
        if not os.path.isfile('tcex.json'):
            return

        # display warning on missing app_name field
        if self.tcex_json.get('package', {}).get('app_name') is None:
            print('{}The tcex.json file is missing the "app_name" field.'.format(c.Fore.MAGENTA))

        # display warning on missing app_version field
        if self.tcex_json.get('package', {}).get('app_version') is None:
            print('{}The tcex.json file is missing the "app_version" field.'.format(c.Fore.YELLOW))

        # update excludes
        excludes = [
            '.gitignore',
            '.pre-commit-config.yaml',
            'pyproject.toml',
            'setup.cfg',
            'tcex.json',
            '*.install.json',
            'tcex.d',
        ]

        if 'requirements.txt' in self.tcex_json.get('package').get('excludes', []):
            message = (
                '{}The tcex.json file excludes "requirements.txt". This file is required to be App '
                'Builder compliant. Remove entry ([y]/n)? '.format(c.Fore.YELLOW)
            )
            response = raw_input(message) or 'y'  # noqa: F821, pylint: disable=E0602
            if response in ['y', 'yes']:
                self.tcex_json.get('package', {}).get('excludes', []).remove('requirements.txt')

                with open('tcex.json', 'w') as f:
                    json.dump(self.tcex_json, f, indent=2, sort_keys=True)

        missing_exclude = False
        for exclude in excludes:
            if exclude not in self.tcex_json.get('package', {}).get('excludes', []):
                missing_exclude = True
                break

        if missing_exclude:
            message = '{}The tcex.json file is missing excludes items. Update ([y]/n)? '.format(
                c.Fore.YELLOW
            )
            response = raw_input(message) or 'y'  # noqa: F821, pylint: disable=E0602

            if response in ['y', 'yes']:
                # get unique list of excludes
                excludes.extend(self.tcex_json.get('package', {}).get('excludes'))
                self.tcex_json['package']['excludes'] = sorted(list(set(excludes)))

                with open('tcex.json', 'w') as f:
                    json.dump(self.tcex_json, f, indent=2, sort_keys=True)
def update_tcex_json ( self ) : if not os . path . isfile ( 'tcex.json' ) : return if self . tcex_json . get ( 'package' , { } ) . get ( 'app_name' ) is None : print ( '{}The tcex.json file is missing the "app_name" field.' . format ( c . Fore . MAGENTA ) ) if self . tcex_json . get ( 'package' , { } ) . get ( 'app_version' ) is None : print ( '{}The tcex.json file is missing the "app_version" field.' . format ( c . Fore . YELLOW ) ) excludes = [ '.gitignore' , '.pre-commit-config.yaml' , 'pyproject.toml' , 'setup.cfg' , 'tcex.json' , '*.install.json' , 'tcex.d' , ] if 'requirements.txt' in self . tcex_json . get ( 'package' ) . get ( 'excludes' , [ ] ) : message = ( '{}The tcex.json file excludes "requirements.txt". This file is required to be App ' 'Builder compliant. Remove entry ([y]/n)? ' . format ( c . Fore . YELLOW ) ) response = raw_input ( message ) or 'y' if response in [ 'y' , 'yes' ] : self . tcex_json . get ( 'package' , { } ) . get ( 'excludes' , [ ] ) . remove ( 'requirements.txt' ) with open ( 'tcex.json' , 'w' ) as f : json . dump ( self . tcex_json , f , indent = 2 , sort_keys = True ) missing_exclude = False for exclude in excludes : if exclude not in self . tcex_json . get ( 'package' , { } ) . get ( 'excludes' , [ ] ) : missing_exclude = True break if missing_exclude : message = '{}The tcex.json file is missing excludes items. Update ([y]/n)? ' . format ( c . Fore . YELLOW ) response = raw_input ( message ) or 'y' if response in [ 'y' , 'yes' ] : excludes . extend ( self . tcex_json . get ( 'package' , { } ) . get ( 'excludes' ) ) self . tcex_json [ 'package' ] [ 'excludes' ] = sorted ( list ( set ( excludes ) ) ) with open ( 'tcex.json' , 'w' ) as f : json . dump ( self . tcex_json , f , indent = 2 , sort_keys = True )
Update the tcex.json configuration file if exists.