<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def action(args):
 """Roll back commands on a refpkg. *args* should be an argparse object with fields refpkg (giving the path to the refpkg to operate on) and n (giving the number of operations to roll back). """

    log.info('loading reference package')

    r = refpkg.Refpkg(args.refpkg, create=False)

    # First check if we can do n rollbacks
    q = r.contents
    for i in range(args.n):
        if q['rollback'] is None:
            log.error('Cannot rollback {} changes; '
                      'refpkg only records {} changes.'.format(args.n, i))
            return 1
        else:
            q = q['rollback']

    for i in range(args.n):
        r.rollback()

    return 0