Skip to main content

Python wrapper over `atd` to schedule deletion of files.

Project description

A pythonic wrapper over atd to schedule deletion of files/directories.

Source code: https://github.com/lonetwin/expyre

Install using pip pip install expyre or download from https://pypi.python.org/pypi/expyre

What is expyre ?

expyre is a python module that provides a command line as well as a contextmanager which enables you to schedule files/directories for deletion at some point in the future. It does this by relying on the atd(8) service for the scheduling of jobs.

Since usually examples are better than a long README

Command line usage

# - schedule a file for deletion 2 days from now
$ expyre -p path/to/file0 @now + 2days
[212] /home/steve/src/venvs/expyre/path/to/file0 will expire at 2016-05-16 19:10

# - schedule a file for deletion a minute befor new year 2018
$ expyre --unless-modified -p path/to/file1 @23:59 2017-12-31
[213] /home/steve/src/venvs/expyre/path/to/file1 will expire at 2017-12-31 23:59

# - list the current expiry schedule
$ expyre -l
/home/steve/src/venvs/expyre/path/to/file1 scheduled to expire at 2017-01-01 19:07 unless modified after 19:07 2016-05-14
/home/steve/src/venvs/expyre/path/to/file0 scheduled to expire at 2016-05-16 19:10

# - remove a file from the expiry schedule
$ expyre -r /home/steve/src/venvs/expyre/path/to/file0
Successfully removed these paths from expiry list:
/home/steve/src/venvs/expyre/path/to/file0

Python usage

from datetime import datetime, timedelta
from expyre.helpers import *

# - as a contextmanager
filename = '/path/to/file'
with open_expiring(filename, 'w', at='now + 3days', unless_accessed=True) as fd:
    # - create a file with a scheduled deletion time exactly 3 days from
    # time of creation unless it has been accessed before the deletion time.
    ...

# - schedule a file for deletion providing time as a string
expire_path('./path/to/file0', 'now + 2days')
JobSpec(job_id='216', path='/home/steve/src/venvs/expyre/path/to/file0', timestamp=datetime.datetime(2016, 5, 16, 19, 20), conditions='unless accessed after 19:20 2016-05-14 or unless modified after 19:20 2016-05-14')

# - schedule a file for deletion providing time as a datetime object
expire_path('./path/to/file1', (datetime.now() + timedelta(days=3)), unless_modified=True)
JobSpec(job_id='217', path='/home/steve/src/venvs/expyre/path/to/file1', timestamp=datetime.datetime(2016, 5, 17, 19, 20), conditions='unless accessed after 19:20 2016-05-14 or unless modified after 19:20 2016-05-14')

# - Get the expiry schedule as a dict
get_scheduled_jobs()
{'/home/steve/src/venvs/expyre/path/to/file0': JobSpec(job_id='216', path='/home/steve/src/venvs/expyre/path/to/file0', timestamp=datetime.datetime(2016, 5, 16, 19, 20), conditions='unless accessed after 19:20 2016-05-14 or unless modified after 19:20 2016-05-14'),
 '/home/steve/src/venvs/expyre/path/to/file1': JobSpec(job_id='217', path='/home/steve/src/venvs/expyre/path/to/file1', timestamp=datetime.datetime(2016, 5, 17, 19, 20), conditions='unless accessed after 19:20 2016-05-14 or unless modified after 19:20 2016-05-14')}

# - remove a file from the expiry schedule
remove_from_schedule(['/home/steve/src/venvs/expyre/path/to/file0'])
(['/home/steve/src/venvs/expyre/path/to/file0'], [])

A few things to note

  • This has only be tested on my local dev box (Fedora 23 with python 2.7). So YMMV. Please do some cursory testing before relying on this tool.

  • Since (afaict), atd(8) has only minute level precision, the same limitation applies to expyre.

  • Directories will be deleted with a rm -rf option ! So, you need to be careful when scheduling those for deletion.

  • The --unless_accessed and --unless_modified options to directories imply the access time and modification time for the directory, not the files under them.

  • Please, please, please do report bugs or send in suggestions for improvements if you can. This would be greatly appreciated.

  • Patches and code reviews would be even more appreciated.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

expyre-0.1.1.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

expyre-0.1.1-py2.py3-none-any.whl (9.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file expyre-0.1.1.tar.gz.

File metadata

  • Download URL: expyre-0.1.1.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for expyre-0.1.1.tar.gz
Algorithm Hash digest
SHA256 29753600ec32deddef36b6a1c8d4b1164fb5f08fdfde8ac0b753c05c04ddebe5
MD5 5cb478049c018e22a10e1d013376a471
BLAKE2b-256 95f35127ef9c574a55560c6acdee468b0297aa779f56ac57b8b9103a9792f037

See more details on using hashes here.

File details

Details for the file expyre-0.1.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for expyre-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 38ce4c4468e02212594d297c350c0c3ca25fabf443adb76c587d60cdf5e32938
MD5 af035a182769da9225ae08952e6ef249
BLAKE2b-256 cdf581d5d11dc96e597a9da4abb057aea9261c8b967cbf48632bb2d59ad80efc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page