-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patholdie
More file actions
executable file
·40 lines (32 loc) · 1.26 KB
/
Copy patholdie
File metadata and controls
executable file
·40 lines (32 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#! /usr/bin/env python3
import stat
import os
import subprocess
import datetime
# bytes to unicode, for convenience
def b2u(l):
return map(lambda x: x.decode('utf-8'), l)
# holds 'pkgname': latest_access_time
latest_pkg_access = {}
# iterate per package
for pkg in b2u(subprocess.check_output(["pacman", "-Qq"]).strip().split(b'\n')):
access_times = []
# iterate per file in that package
for pkg_file in b2u(subprocess.check_output(["pacman", "-Qql", pkg]).strip().split(b'\n')):
try:
file_stat = os.stat(pkg_file)
except OSError as e:
#print(e)
# symlinks or non existing files..
continue
if stat.S_ISREG(file_stat.st_mode):
access_times.append(file_stat[stat.ST_ATIME])
# needed check because xorg-font-utils has 0 files...
if len(access_times):
latest_pkg_access[pkg] = max(access_times)
# get the length of the longest pkgname used later for pretty formatting
max_name_len = max(map(len, latest_pkg_access.keys()))
# show pkgs with the oldest "latest access" time first
for pkg in sorted(latest_pkg_access, key=latest_pkg_access.get):
date = datetime.datetime.fromtimestamp(latest_pkg_access[pkg])
print('{0:{width}}'.format(pkg, width=max_name_len), date)