Xfce Forum

Sub domains
 

You are not logged in.

#1 2015-01-21 01:05:58

alcornoqui
Member
Registered: 2014-07-28
Posts: 832

[Solved] FATSort: help me make a launcher (or even better, update fatsort-gui)

I recently came across the fantastic FATSort utility (already in the Fedora, Debian, Ubuntu, and Gentoo repositories) to sort the files in FAT partitions.

I find it really useful when you have to play music, videos or whatever in proper order in some dumb device with a USB port.

As I have installed Xubuntu (14.04) on some friends and relatives' computers, I wanted to use the command, and turn it into a simple button/launcher, which proved not so easy for my actual skills (I tried with

sudo fatsort -f /dev/sdb1

but there are some variables to account for, as the actual mount point not being fixed, etc, which makes it sub-optimal).

Anyway, shortly after that I stumbled upon fatsort-gui.py (blog post and source code) but, unfortunately, it seems outdated, and fails quickly with a

/bin/sh: 1: hal-device: not found

showing me a beautiful, but empty GUI :-(

So I wondered if, being the Python script quite short (under 100 lines with notice and all), any of you could help me updating it and adding this simple button to the panel of some new users. Just that, thanks, cheers!

Last edited by alcornoqui (2015-01-21 01:07:08)

Offline

#2 2015-01-21 02:01:44

sixsixfive
Member
From: behind you
Registered: 2012-04-08
Posts: 579
Website

Re: [Solved] FATSort: help me make a launcher (or even better, update fatsort-gui)

Usage: fatsort [options] device

Options:
	-c	 Ignore case of file names
	-f	 Force sorting even if filesystem is mounted
	-h	 Print some help
	-i	 Print file system information only
	-I	 Ignore prefixes "a" and "the"
	-l	 Print current order of files only
	-o flag	 Sort order of files where flag is one of
			d : directories first (default)
			f : files first
			a : files and directories are not differentiated
	-n	 Natural order sorting
	-q	 Be quiet
	-r	 Sort in reverse order
	-R	 Sort in random order
	-v	 Print version information

	The following options can be specified multiple times:

	-d dir	 Sort directory dir only
	-D dir	 Sort directory dir and all subdirectories
	-x dir	 Don't sort directory dir
	-X dir	 Don't sort directory dir and its subdirectories

-h, -i, -l, -q and -v is basically useless for sorting, -f, -r, -c, -n and -R is probably not wanted, -o will be most time d(which is default) and I don't really see a point in ignoring dirs or folders on an mp3 player. So this would bring us to this two possible commands:

sudo fatsort /dev/sdX

or

sudo fatsort -I /dev/sdX

as you can see every script here would be a waste of time

Offline

#3 2015-01-21 02:30:55

alcornoqui
Member
Registered: 2014-07-28
Posts: 832

Re: [Solved] FATSort: help me make a launcher (or even better, update fatsort-gui)

Well, the point of the GUI is mostly to select the right device to be sorted. If this is going to be used by people with even less computer skills than me, I feel like I can't assume that it's always going to be /dev/sdb1 (I use the terminal myself, and know when to change the command to /dev/sdc1 or whatever if necessary, but I still unmount and eject the drive through Thunar, for example, and those actions can be scripted).

There are, then, I think, three or four parts here: identify/select the device to sort, unmount it, and eject it after the command is executed. The linked fatsort-gui script goes in that direction (I'm not sure if it ejects the device), and I think it's perfect for my usecase but, alas, I can't make it work...

Thanks for your comment, though, I'll keep digging, I should learn how to do these kind of things!

Last edited by alcornoqui (2015-01-21 02:31:50)

Offline

#4 2015-01-21 09:05:33

sixsixfive
Member
From: behind you
Registered: 2012-04-08
Posts: 579
Website

Re: [Solved] FATSort: help me make a launcher (or even better, update fatsort-gui)

so you would need something like:

#!/bin/sh
if [ ! -t 0 ]; then
	x-terminal-emulator -e "$0"
	exit 0
fi
findmnt -Do TARGET,SOURCE,FSTYPE | grep -e "sd[b-z]" | grep vfat
printf "\n"
read -p "Please enter the device name(eg:/dev/sdc) :" disk
printf "\n"
read -p "Ignore prefixes? [y/n] :" ignprefixes
if [ `echo $ignprefixes` = "y" ]; then
	printf "ignoring prefixes\n"
	opt1="-I"
fi
printf "\n"
read -p "I will now unmount and fatsort $disk, OK? [y/n] :" input
if [ `echo $input` != "y" ]; then
	printf "Aborting...\n"
	sleep 3
	exit 1
fi
#sudo umount $disk && fatsort $opt1 $disk
#su -c "umount $disk && fatsort $opt1 $disk"
printf "\ndone\n"
sleep 3

Last edited by sixsixfive (2015-01-21 16:48:09)

Offline

#5 2015-01-21 12:49:44

alcornoqui
Member
Registered: 2014-07-28
Posts: 832

Re: [Solved] FATSort: help me make a launcher (or even better, update fatsort-gui)

Wow, thanks a lot... Still, I get this error:

findmnt: opción incorrecta -- «D»

followed by the help text of "findmnt" (which I didn't even know I had installed!).

I guess I'll take a good look at it this evening (GMT here), and try to tweak it without bothering you too much (I see the actual fatsort commands are commented, I guess at one point I should uncomment one of them, am I right?).

I really appreciate your help, I'll keep posting until I grok it! (I won't apologise for my english because I know it's funny, enjoy!)

Offline

#6 2015-01-21 16:52:21

sixsixfive
Member
From: behind you
Registered: 2012-04-08
Posts: 579
Website

Re: [Solved] FATSort: help me make a launcher (or even better, update fatsort-gui)

the incorrect option is probably because you have an old(very old) udev release

>I guess at one point I should uncomment one of them, am I right?

correct either the su or sudo command

Offline

#7 2015-01-21 18:32:18

alcornoqui
Member
Registered: 2014-07-28
Posts: 832

Re: [Solved] FATSort: help me make a launcher (or even better, update fatsort-gui)

Away from my computer now, will check tonight... Thanks!

Offline

#8 2015-01-22 00:56:22

alcornoqui
Member
Registered: 2014-07-28
Posts: 832

Re: [Solved] FATSort: help me make a launcher (or even better, update fatsort-gui)

Hello. I got it working, wooo!

I have quite a hard time with bash builtins and regexes, but it's being nice to scratch this itch... Here's the commented script as of now:

#!/bin/sh
# Let's see if I understand the script:
# This opens a terminal if needed
if [ ! -t 0 ]; then
	x-terminal-emulator -e "$0"
	exit 0
fi
# The next line is the one that threw the error.
# I changed "D" for "m", after RTFM. The output was:
# /media/alcornoqui/USBSTICK        /dev/sdb1  vfat
findmnt -mo TARGET,SOURCE,FSTYPE | grep -e "sd[b-z]" | grep vfat
#
printf "\n"
read -p "Please enter the device name(eg:/dev/sdc) :" disk
printf "\n"
# I could ignore this, a's and the's are fine.
#read -p "Ignore prefixes? [y/n] :" ignprefixes
#if [ `echo $ignprefixes` = "y" ]; then
#	printf "ignoring prefixes\n"
#	opt1="-I"
#fi
#printf "\n"
# But this should stay
read -p "I will now unmount and fatsort $disk, OK? [y/n] :" input
if [ `echo $input` != "y" ]; then
	printf "Aborting...\n"
	sleep 3
	exit 1
fi
# These two next lines came commented, I've uncommented 
# the first (but I've removed $opt1 for now) 
sudo umount $disk && sudo fatsort $disk #removed the trailing "
# I had to put sudo before fatsort, but it worked!!!
#su -c "umount $disk && fatsort $opt1 $disk"
# I wonder if I could include the "eject" command in the same way:
# sudo eject $disk
# I tried but I'm not sure it worked
printf "\ndone\n"
sleep 3

BTW, my version of udev is 204-5ubuntu20.9 from the Trusty updates repository.

Lastly, did you take a look at fatsort-gui? The window that shows (through Zenity) looks great, and would allow my terminal-fearing family to sleep tight-er...

1421887582.png

Couldn't we somehow shoehorne it in? tongue

Anyway, I'll keep digging tomorrow, thanks a lot! It's being fun...

Offline

#9 2015-01-22 09:22:12

sixsixfive
Member
From: behind you
Registered: 2012-04-08
Posts: 579
Website

Re: [Solved] FATSort: help me make a launcher (or even better, update fatsort-gui)

for yad this would be: (zenity is like gtk3, it breaks things in every release)

disk=$(yad --list --title="Please choose your device" --column="Mountpoint" --column="Device" --column="fs type" `findmnt -Do TARGET,SOURCE,FSTYPE | grep -e "sd[b-z]" | grep vfat` --geometry 640x480 | cut -d'|' -f2)

Offline

#10 2015-01-22 19:40:40

alcornoqui
Member
Registered: 2014-07-28
Posts: 832

Re: [Solved] FATSort: help me make a launcher (or even better, update fatsort-gui)

Thank you! No wonder you're just one step beyond the devil wink

That line did it. Minimal version:

#!/bin/sh
if [ ! -t 0 ]; then
	x-terminal-emulator -e "$0"
	exit 0
fi
disk=$(yad --list --title="Please choose your device" --column="Mountpoint" --column="Device" --column="fs type" `findmnt -mo TARGET,SOURCE,FSTYPE | grep vfat` --geometry 480x320 | cut -d'|' -f2)
read -p "I will now unmount and fatsort $disk, OK? [y/n] :" input
if [ `echo $input` != "y" ]; then
	printf "Aborting...\n"
	sleep 3
	exit 1
fi
sudo umount $disk && sudo fatsort $disk && sudo eject $disk
printf "\ndone\n"
sleep 3

The changes (feel free to comment on them, of course):
1. Removed the first "grep" (as I don't have any internal FAT partition).
2. Removed the question about prefixes.
3. Added the eject command to the chain (it worked!)

Ideally, I should keep improving it (I really think I will), but I consider the problem solved.

Again, thank you and all the makers and maintainers & family of FOSS, you rock!!!

Offline

#11 2015-01-22 19:43:46

alcornoqui
Member
Registered: 2014-07-28
Posts: 832

Re: [Solved] FATSort: help me make a launcher (or even better, update fatsort-gui)

I should mention that this works through a nice button within my panel, etc. When I get some more time I'll post some screenshots and instructions for other new users. Bye!

Offline

Registered users online in this topic: 0, guests: 1
[Bot] ClaudeBot

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.012 seconds, 9 queries executed - Memory usage: 601.7 KiB (Peak: 618.54 KiB) ]