Install one individual package

def _install_indv_pkg(self, pkg_name, pkg_file):
        '''
        Install one individual package
        '''
        self.ui.status('... installing {0}'.format(pkg_name))
        formula_tar = tarfile.open(pkg_file, 'r:bz2')
        formula_ref = formula_tar.extractfile('{0}/FORMULA'.format(pkg_name))
        formula_def = salt.utils.yaml.safe_load(formula_ref)

        for field in ('version', 'release', 'summary', 'description'):
            if field not in formula_def:
                raise SPMPackageError('Invalid package: the {0} was not found'.format(field))

        pkg_files = formula_tar.getmembers()

        # First pass: check for files that already exist
        existing_files = self._pkgfiles_fun('check_existing', pkg_name, pkg_files, formula_def)

        if existing_files and not self.opts['force']:
            raise SPMPackageError('Not installing {0} due to existing files:\n\n{1}'.format(
                pkg_name, '\n'.join(existing_files))
            )

        # We've decided to install
        self._pkgdb_fun('register_pkg', pkg_name, formula_def, self.db_conn)

        # Run the pre_local_state script, if present
        if 'pre_local_state' in formula_def:
            high_data = self._render(formula_def['pre_local_state'], formula_def)
            ret = self.caller.cmd('state.high', data=high_data)
        if 'pre_tgt_state' in formula_def:
            log.debug('Executing pre_tgt_state script')
            high_data = self._render(formula_def['pre_tgt_state']['data'], formula_def)
            tgt = formula_def['pre_tgt_state']['tgt']
            ret = self.client.run_job(
                tgt=formula_def['pre_tgt_state']['tgt'],
                fun='state.high',
                tgt_type=formula_def['pre_tgt_state'].get('tgt_type', 'glob'),
                timout=self.opts['timeout'],
                data=high_data,
            )

        # No defaults for this in config.py; default to the current running
        # user and group
        if salt.utils.platform.is_windows():
            uname = gname = salt.utils.win_functions.get_current_user()
            uname_sid = salt.utils.win_functions.get_sid_from_name(uname)
            uid = self.opts.get('spm_uid', uname_sid)
            gid = self.opts.get('spm_gid', uname_sid)
        else:
            uid = self.opts.get('spm_uid', os.getuid())
            gid = self.opts.get('spm_gid', os.getgid())
            uname = pwd.getpwuid(uid)[0]
            gname = grp.getgrgid(gid)[0]

        # Second pass: install the files
        for member in pkg_files:
            member.uid = uid
            member.gid = gid
            member.uname = uname
            member.gname = gname

            out_path = self._pkgfiles_fun('install_file',
                                          pkg_name,
                                          formula_tar,
                                          member,
                                          formula_def,
                                          self.files_conn)
            if out_path is not False:
                if member.isdir():
                    digest = ''
                else:
                    self._verbose('Installing file {0} to {1}'.format(member.name, out_path), log.trace)
                    file_hash = hashlib.sha1()
                    digest = self._pkgfiles_fun('hash_file',
                                                os.path.join(out_path, member.name),
                                                file_hash,
                                                self.files_conn)
                self._pkgdb_fun('register_file',
                                pkg_name,
                                member,
                                out_path,
                                digest,
                                self.db_conn)

        # Run the post_local_state script, if present
        if 'post_local_state' in formula_def:
            log.debug('Executing post_local_state script')
            high_data = self._render(formula_def['post_local_state'], formula_def)
            self.caller.cmd('state.high', data=high_data)
        if 'post_tgt_state' in formula_def:
            log.debug('Executing post_tgt_state script')
            high_data = self._render(formula_def['post_tgt_state']['data'], formula_def)
            tgt = formula_def['post_tgt_state']['tgt']
            ret = self.client.run_job(
                tgt=formula_def['post_tgt_state']['tgt'],
                fun='state.high',
                tgt_type=formula_def['post_tgt_state'].get('tgt_type', 'glob'),
                timout=self.opts['timeout'],
                data=high_data,
            )

        formula_tar.close()