Skip to content

Commit

Permalink
Use last modification time to compare differences
Browse files Browse the repository at this point in the history
  • Loading branch information
Neloop committed May 17, 2018
1 parent 3acdc92 commit 7331bd6
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 26 deletions.
67 changes: 67 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,70 @@ docs/*
!docs/Makefile
!docs/make.bat
!docs/conf.py

### PyCharm+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries

# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml

# Gradle:
.idea/**/gradle.xml
.idea/**/libraries

# CMake
cmake-build-debug/

# Mongo Explorer plugin:
.idea/**/mongoSettings.xml

## File-based project format:
*.iws

## Plugin-specific files:

# IntelliJ
/out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Ruby plugin and RubyMine
/.rakeTasks

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

### PyCharm+all Patch ###
# Ignores the whole .idea folder and all .iml files
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360

.idea/

# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023

*.iml
modules.xml
.idea/misc.xml
*.ipr
28 changes: 7 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Cleaner - OUTDATED DO NOT INSTALL!
# Cleaner

[![License](http://img.shields.io/:license-mit-blue.svg)](http://badges.mit-license.org)
[![Docs](https://img.shields.io/badge/docs-latest-brightgreen.svg)](http://recodex.github.io/cleaner/)
Expand All @@ -17,25 +17,11 @@ multi-platform. It uses only `pyyaml` library for reading configuration file and
`argparse` library for processing command line arguments.

It is a simple script which checks the cache folder, possibly deletes old files
and then ends. This means that the cleaner has to be run repeatedly, for example
using cron, systemd timer or Windows task scheduler. For proper function of the
cleaner a suitable cronning interval has to be used. It is recommended to use
24 hour interval which is sufficient enough for intended usage. The value is set
in the configuration file of the cleaner.

## Enable last access timestamp

**Linux:**

- open `/etc/fstab` as administrator
- filesystem which will be used as `ReCodEx` cache has to have `strictatime` option specified
- more on this subject can be found [here](https://en.wikipedia.org/wiki/Stat_%28system_call%29#Criticism_of_atime)

**Windows:**

- start `cmd` with administrator permissions
- run following command `fsutil behavior set disablelastaccess 0`
- restart computer and last time access timestamps should be functional
(based on last modification times) and then ends. This means that the cleaner has
to be run repeatedly, for example using cron, systemd timer or Windows task
scheduler. For proper function of the cleaner a suitable cron interval has to
be used. It is recommended to use 24 hour interval which is sufficient enough for
intended usage. The value is set in the configuration file of the cleaner.

## How to run it

Expand Down Expand Up @@ -125,7 +111,7 @@ In case of manual execution, `cleaner` should be run using `cron` with some reco

**Windows:**

Cronning on Windows is provided by `Task Scheduler`. This can be done using GUI interface or with command line, command line description follows:
Cron on Windows is provided by `Task Scheduler`. This can be done using GUI interface or with command line, command line description follows:

- start `cmd` as administrator
- find your `recodex-cleaner` installation on your filesystem, `C:\Program Files\ReCodEx\cleaner` will be used as demonstrative
Expand Down
11 changes: 6 additions & 5 deletions cleaner/cleaner.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class Cleaner:
"""
Cleaner class handles cleaning of given cache folder.
Files are cleaned based on last access time, which have to be in interval given in configuration.
Files are cleaned based on last modification time, which have to be in interval given in configuration.
"""

def __init__(self, config):
Expand Down Expand Up @@ -74,15 +74,16 @@ def process_path(root, file, action):
:param root: path to root directory, used as base
:param file: name of file itself, root is used as base and joined with this
:param action: action which will be performed if access timestamp is older than given interval
:param action: action which will be performed if modification timestamp is older than given interval
:return: Nothing
"""

full_path = os.path.join(root, file)
last_access = round(os.stat(full_path).st_atime)
difference = now - last_access
last_modification = round(os.stat(full_path).st_mtime)
difference = now - last_modification

print(full_path)
print(" last access: " + str(last_access))
print(" last modification: " + str(last_modification))
print(" difference: " + str(difference))

if difference > self._file_age:
Expand Down

0 comments on commit 7331bd6

Please sign in to comment.