# Buggy code
def generate_package(self):
    build_file_subs = dict(
        changelog_version="{}-{}".format(self.chromium_version, self.release_revision),
        changelog_datetime=self._get_dpkg_changelog_datetime(),
        build_output=str(self.build_output),
    )
    self.logger.info("Building Debian package...")
    # TODO: Copy _dpkg_dir over each other in build/ similar to resource reading
    distutils.dir_util.copy_tree(str(self._dpkg_dir), str(self._sandbox_dpkg_dir))
    for old_path in self._sandbox_dpkg_dir.glob("*.in"):
        new_path = self._sandbox_dpkg_dir / old_path.stem
        old_path.replace(new_path)
        with new_path.open("r+") as new_file:
            content = self.BuildFileStringTemplate(new_file.read()).substitute(
                **build_file_subs
            )
            new_file.seek(0)
            new_file.write(content)
            new_file.truncate()
    result = self._run_subprocess(
        ["dpkg-buildpackage", "-b", "-uc"], cwd=str(self._sandbox_dir)
    )
    if not result.returncode == 0:
        raise BuilderException(
            "dpkg-buildpackage returned non-zero exit code: {}".format(
                result.returncode
            )
        )


# Traceback (NameError)
Now at patch ../patches/ungoogled-chromium/remove-get-help-button.patch
2016-09-29 16:58:58,672 - INFO: Running gyp command...
2016-09-29 16:58:58,673 - DEBUG: Appending resources/common/gyp_flags
2016-09-29 16:58:58,673 - DEBUG: Appending resources/linux_static/gyp_flags
2016-09-29 16:58:58,673 - DEBUG: GYP command: build/gyp_chromium --depth=. --check -Denable_rlz=0 -Duse_official_google_api_keys=0 -Dproprietary_codecs=1 -Dfieldtrial_testing_like_official_build=1 -Denable_hangout_services_extension=0 -Ddisable_newlib=1 -Denable_webrtc=0 -Dremoting=0 -Ddefault_apps_list_linux_dest=[] -Ddisable_nacl=1 -Dtracing_like_official_build=1 -Ddisable_fatal_linker_warnings=1 -Denable_prod_wallet_service=0 -Denable_google_now=0 -Denable_automation=0 -Denable_one_click_signin=0 -Dremove_webcore_debug_symbols=1 -Ddisable_pnacl=1 -Dbuildtype=Official -Dwerror= -Denable_hotwording=0 -Denable_pre_sync_backup=0 -Dffmpeg_branding=Chrome -Dfastbuild=2 -Dlinux_strip_binary=1 -Denable_hidpi=1 -Denable_wifi_bootstrapping=0 -Denable_remoting_host=0 -Ddefault_apps_list=[] -Dsafe_browsing=0
Traceback (most recent call last):
File "build/gyp_chromium", line 12, in <module>
execfile(__file__ + '.py')
NameError: name 'execfile' is not defined
2016-09-29 16:58:58,694 - ERROR: GYP command returned non-zero exit code: 1

# Fixed code
def generate_package(self):
    build_file_subs = dict(
        changelog_version="{}-{}".format(self.chromium_version, self.release_revision),
        changelog_datetime=self._get_dpkg_changelog_datetime(),
        build_output=str(self.build_output),
        distribution_version=self._distro_version,
    )
    self.logger.info("Building Debian package...")
    # TODO: Copy _dpkg_dir over each other in build/ similar to resource reading
    distutils.dir_util.copy_tree(str(self._dpkg_dir), str(self._sandbox_dpkg_dir))
    for old_path in self._sandbox_dpkg_dir.glob("*.in"):
        new_path = self._sandbox_dpkg_dir / old_path.stem
        old_path.replace(new_path)
        with new_path.open("r+") as new_file:
            content = self.BuildFileStringTemplate(new_file.read()).substitute(
                **build_file_subs
            )
            new_file.seek(0)
            new_file.write(content)
            new_file.truncate()
    result = self._run_subprocess(
        ["dpkg-buildpackage", "-b", "-uc"], cwd=str(self._sandbox_dir)
    )
    if not result.returncode == 0:
        raise BuilderException(
            "dpkg-buildpackage returned non-zero exit code: {}".format(
                result.returncode
            )
        )