Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs: pure dfs implementation #272

Closed
lcpz opened this issue Jan 22, 2017 · 12 comments
Closed

fs: pure dfs implementation #272

lcpz opened this issue Jan 22, 2017 · 12 comments

Comments

@lcpz
Copy link
Owner

lcpz commented Jan 22, 2017

Remove scripts/ definitely and switch to a pure Lua implementation.

@lcpz lcpz added this to the release 1.0 milestone Jan 24, 2017
@aajjbb
Copy link
Contributor

aajjbb commented Jan 27, 2017

By 'pure Lua' implementation you mean "No parsing df" ?

@lcpz
Copy link
Owner Author

lcpz commented Jan 27, 2017

No parsing at all, but using Lua and Awesome APIs.

I was thinking about a wibox to toggle, filled with progress bars.

@psychon
Copy link

psychon commented Feb 4, 2017

I'm not yet sure how to get a list of mount points, but at least this is how you can get some disk usage:

gio = require("lgi").Gio
file = gio.File.new_for_path(".")
size, free, used = gio.FILE_ATTRIBUTE_FILESYSTEM_SIZE, gio.FILE_ATTRIBUTE_FILESYSTEM_FREE, gio.FILE_ATTRIBUTE_FILESYSTEM_USED
query = size..","..free..","..used
info = file:query_filesystem_info(query)
print(info:get_attribute_uint64(size), info:get_attribute_uint64(free), info:get_attribute_uint64(used))

@psychon
Copy link

psychon commented Feb 4, 2017

I can only offer the following, but it does not list all mount points, only some (yes, I know that this queries free but does not use it):

local Gio = require("lgi").Gio
local volume_monitor = Gio.VolumeMonitor.get()
local query_size = Gio.FILE_ATTRIBUTE_FILESYSTEM_SIZE
local query_free = Gio.FILE_ATTRIBUTE_FILESYSTEM_FREE
local query_used = Gio.FILE_ATTRIBUTE_FILESYSTEM_USED
local query = query_size .. "," .. query_free .. "," .. query_used

for _, mount in ipairs(volume_monitor:get_mounts()) do
	local root = mount:get_root()
	local info = root:query_filesystem_info(query)
	local size = info:get_attribute_uint64(query_size)
	local free = info:get_attribute_uint64(query_free)
	local used = info:get_attribute_uint64(query_used)
	local percentage = 100 * used / size
	print(string.format("%s '%s' has %.3f%% used", root:get_path(), mount:get_name(), percentage))
end

Output:

/ 'Filesystem root' has 21.000% used
/boot/efi 'efi' has 0.025% used
/mnt/space 'space' has 7.938% used

@unode
Copy link
Contributor

unode commented Feb 19, 2017

Do we have any progress on this?

Currently I'm experiencing problems with the notification pop-up.
Running the dfs script manually works fine but the pop-up only shows:

                                                       Used     Free    Total

@lcpz
Copy link
Owner Author

lcpz commented Feb 20, 2017

@unode Nothing has changed in dfs since #270.

@unode
Copy link
Contributor

unode commented Feb 20, 2017

@copycat-killer this started happening after upgrading to awesome 4.0. Don't know why yet. I'll open another issue on it.

klaernie added a commit to klaernie/lain that referenced this issue Apr 27, 2017
The `sh` on e.g. Debian is `dash`, but the script requires bash features by using `+=`. Until lcpz#272 is complete I think this is the best way to ensure that dfs works by default (excluding the gawk requirement).
@otommod
Copy link

otommod commented Jan 8, 2018

There's also this API

local Gio = require("lgi").Gio
for _, m in ipairs(Gio.unix_mounts_get()) do
    print(Gio.unix_mount_get_mount_path(m))
end

which seems to return everything df -a does, e.g. for me

/sys
/proc
/dev
/sys/kernel/security
/dev/shm
/dev/pts
/run
/sys/fs/cgroup
/sys/fs/cgroup/unified
/sys/fs/cgroup/systemd
/sys/fs/pstore
/sys/fs/cgroup/net_cls,net_prio
/sys/fs/cgroup/cpu,cpuacct
/sys/fs/cgroup/cpuset
/sys/fs/cgroup/blkio
/sys/fs/cgroup/perf_event
/sys/fs/cgroup/devices
/sys/fs/cgroup/pids
/sys/fs/cgroup/rdma
/sys/fs/cgroup/freezer
/sys/fs/cgroup/memory
/
/dev/mqueue
/proc/sys/fs/binfmt_misc
/tmp
/sys/kernel/config
/dev/hugepages
/sys/kernel/debug
/boot
/home
/run/user/1000
/run/user/1000/gvfs
/sys/fs/fuse/connections
/proc/sys/fs/binfmt_misc

Contrast that to #272 (comment) which outputs nothing for me for some reason.

@psychon
Copy link

psychon commented Jan 8, 2018

@otommod Thanks for finding that. Here is it incorporated into the script from my last comment:

local Gio = require("lgi").Gio
local query_size = Gio.FILE_ATTRIBUTE_FILESYSTEM_SIZE
local query_free = Gio.FILE_ATTRIBUTE_FILESYSTEM_FREE
local query_used = Gio.FILE_ATTRIBUTE_FILESYSTEM_USED
local query = query_size .. "," .. query_free .. "," .. query_used

for _, mount in ipairs(Gio.unix_mounts_get()) do
	local path = Gio.unix_mount_get_mount_path(mount)
	local root = Gio.File.new_for_path(path)
	local info = root:query_filesystem_info(query)
	local size = info:get_attribute_uint64(query_size)
	local free = info:get_attribute_uint64(query_free)
	local used = info:get_attribute_uint64(query_used)
	local percentage = 100 * used / size
	print(string.format("%s has %.3f%% used (%d used of %d)", path, percentage, used, size))
end

@lcpz
Copy link
Owner Author

lcpz commented Jan 8, 2018

@otommod @psychon Thank you both.

I'm going to do this ASAP, but any help is welcome.

@lcpz lcpz closed this as completed Jan 8, 2018
@lcpz lcpz reopened this Jan 8, 2018
@lcpz
Copy link
Owner Author

lcpz commented Jan 8, 2018

Closed by mistake. Reopening.

lcpz added a commit that referenced this issue Feb 16, 2018
lcpz added a commit that referenced this issue Feb 16, 2018
@lcpz
Copy link
Owner Author

lcpz commented Feb 16, 2018

Done. Also, new API introduced. Read the wiki.

lcpz added a commit that referenced this issue Feb 16, 2018
lcpz added a commit that referenced this issue Feb 16, 2018
@lcpz lcpz closed this as completed Feb 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants