Beispiel #1
0
def rm(q):
    "Remove skid-mark associated with cached file."

    cached = q.strip()
    cached = re.sub('^file://', '', cached)   # remove "file://" prefix

    if cached.startswith(config.CACHE):
        # remove cached file
        os.system('rm -f %s' % cached)
        # remove corresponding '.d' directory and its contents
        os.system('rm -rf %s.d' % cached)
        # remove file from whoosh index.
        index.delete(cached)

    else:
        from skid.index import search
        results = [dict(x) for x in search(q)]
        if len(results) == 0:
            # Should only happen if user hasn't done run skid-update since
            # adding the paper being deleted.
            print('No matches. Make sure skid is up-to-date by running `skid update`.')
        elif len(results) == 1:
            [hit] = results
            print()
            print(hit['title'])
            print(colors.green % "Are you sure you'd like to delete this document [Y/n]?", end=' ')
            if input().strip().lower() in ('y','yes',''):
                if rm_cached(hit['cached']):
                    print(colors.yellow % 'Successfully deleted.')
        else:
            assert False, 'Multiple (%s) results found for query %r. ' \
                'Refine query and try again.' \
                % (len(results), q)
Beispiel #2
0
def rm_cached(cached):
    "Remove skid-mark associated with cached file."

    cached = cached.strip()
    cached = re.sub('^file://', '', cached)   # remove "file://" prefix

    assert cached.startswith(config.CACHE), \
        "This doesn't look like of skid's cached files."

    os.system('rm -f %s' % cached)     # remove cached file
    os.system('rm -rf %s.d' % cached)  # remove .d directory and all it's contents

    # remove file from whoosh index.
    return index.delete(cached)