<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def _lockcmd(subcmd, pkgname=None, **kwargs):
    '''
    Helper function for lock and unlock commands, because their syntax is identical.

    Run the lock/unlock command, and return a list of locked packages
    '''

    jail = kwargs.pop('jail', None)
    chroot = kwargs.pop('chroot', None)
    root = kwargs.pop('root', None)

    locked_pkgs = []

    cmd = _pkg(jail, chroot, root)
    cmd.append(subcmd)
    cmd.append('-y')
    cmd.append('--quiet')
    cmd.append('--show-locked')

    if pkgname:
        cmd.append(pkgname)

    out = __salt__['cmd.run_all'](cmd, output_loglevel='trace', python_shell=False)

    if out['retcode'] != 0:
        raise CommandExecutionError(
            'Problem encountered {0}ing packages'.format(subcmd),
            info={'result': out}
        )

    for line in salt.utils.itertools.split(out['stdout'], '\n'):
        if not line:
            continue
        try:
            pkgname = line.rsplit('-', 1)[0]
        except ValueError:
            continue
        locked_pkgs.append(pkgname)

    log.debug('Locked packages: %s', ', '.join(locked_pkgs))
    return locked_pkgs