Re: [O] function for cleaning org-attach directories

2015-07-20 Thread Alan Schmitt
On 2015-07-18 05:11, Eric Abrahamsen e...@ericabrahamsen.net writes:

 Alan Schmitt alan.schm...@polytechnique.org writes:

 I gave this a try and it seems that `org-attach-directory' needs to be
 defined for it to work. I'm surprised because I never configured this
 and with gnorb I have had files attached using org-attach. Does gnorb
 use a default value for this?

 Gnorb has calls to (require 'org-attach) in certain places -- unless
 you've loaded and used gnorb in your current session, you'll probably
 want to require that yourself.

Ah, yes, of course. It seems to be working, but it’s awfully silent. It
would be great if it gave some feedback (I don’t know if it actually
deleted anything, as there was nothing in the *Messages* buffer).

Alan

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7
Last week athmospheric CO₂ average (Updated July 14, 2015, Mauna Loa Obs.):
401.73 ppm


signature.asc
Description: PGP signature


Re: [O] function for cleaning org-attach directories

2015-07-17 Thread Alan Schmitt
On 2015-07-17 07:19, Eric Abrahamsen e...@ericabrahamsen.net writes:

 Here we go, and this one ought to be a little more portable. I guess
 I'll do it as a proper patch in a bit.

I gave this a try and it seems that `org-attach-directory' needs to be
defined for it to work. I'm surprised because I never configured this
and with gnorb I have had files attached using org-attach. Does gnorb
use a default value for this?

Thanks,

Alan

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7
Last week athmospheric CO₂ average (Updated July 14, 2015, Mauna Loa Obs.):
401.73 ppm


signature.asc
Description: PGP signature


Re: [O] function for cleaning org-attach directories

2015-07-17 Thread Eric Abrahamsen
Alan Schmitt alan.schm...@polytechnique.org writes:

 On 2015-07-17 07:19, Eric Abrahamsen e...@ericabrahamsen.net writes:

 Here we go, and this one ought to be a little more portable. I guess
 I'll do it as a proper patch in a bit.

 I gave this a try and it seems that `org-attach-directory' needs to be
 defined for it to work. I'm surprised because I never configured this
 and with gnorb I have had files attached using org-attach. Does gnorb
 use a default value for this?

Gnorb has calls to (require 'org-attach) in certain places -- unless
you've loaded and used gnorb in your current session, you'll probably
want to require that yourself.




Re: [O] function for cleaning org-attach directories

2015-07-16 Thread Alan Schmitt
Hi Eric,

On 2015-07-16 10:57, Eric Abrahamsen e...@ericabrahamsen.net writes:

 I use org-attach a lot, and if you're not careful you can get a data/
 directory of many gigabytes. Not a problem, until you want to rsync it
 and it takes all day...

 I wrote this to clean my attach directories. I'm not sure how portable
 it is (and I'm really not pleased with the (concat attach-dir / d /
 d+)), but I'm posting it to see if it's useful to anyone.

 Comments/improvements welcome! If the final product is desirable, I can
 work it up as a patch.

This would be most useful indeed. One quick question: why do you use
rm instead of delete-file?

Alan

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7
Last week athmospheric CO₂ average (Updated July 14, 2015, Mauna Loa Obs.):
401.73 ppm


signature.asc
Description: PGP signature


Re: [O] function for cleaning org-attach directories

2015-07-16 Thread Eric Abrahamsen
Alan Schmitt alan.schm...@polytechnique.org writes:

 Hi Eric,

 On 2015-07-16 10:57, Eric Abrahamsen e...@ericabrahamsen.net writes:

 I use org-attach a lot, and if you're not careful you can get a data/
 directory of many gigabytes. Not a problem, until you want to rsync it
 and it takes all day...

 I wrote this to clean my attach directories. I'm not sure how portable
 it is (and I'm really not pleased with the (concat attach-dir / d /
 d+)), but I'm posting it to see if it's useful to anyone.

 Comments/improvements welcome! If the final product is desirable, I can
 work it up as a patch.

 This would be most useful indeed. One quick question: why do you use
 rm instead of delete-file?

Because I was copy-pasting from org-attach! The real question is: why
didn't I use `delete-directory' :)

I'll do another version!

E




Re: [O] function for cleaning org-attach directories

2015-07-16 Thread Eric Abrahamsen
Eric Abrahamsen e...@ericabrahamsen.net writes:

 Alan Schmitt alan.schm...@polytechnique.org writes:

 Hi Eric,

 On 2015-07-16 10:57, Eric Abrahamsen e...@ericabrahamsen.net writes:

 I use org-attach a lot, and if you're not careful you can get a data/
 directory of many gigabytes. Not a problem, until you want to rsync it
 and it takes all day...

 I wrote this to clean my attach directories. I'm not sure how portable
 it is (and I'm really not pleased with the (concat attach-dir / d /
 d+)), but I'm posting it to see if it's useful to anyone.

 Comments/improvements welcome! If the final product is desirable, I can
 work it up as a patch.

 This would be most useful indeed. One quick question: why do you use
 rm instead of delete-file?

 Because I was copy-pasting from org-attach! The real question is: why
 didn't I use `delete-directory' :)

 I'll do another version!

 E

Here we go, and this one ought to be a little more portable. I guess
I'll do it as a proper patch in a bit.

(defun org-attach-clean-dirs (optional attach-dir clean-archived)
  (interactive)
  (let ((attach-dir
 (if attach-dir
 (file-name-as-directory attach-dir)
   (concat (file-name-as-directory org-directory)
   org-attach-directory)))
(valid-dir-re \\`[0-9a-z-]+\\')
(org-id-search-archives (if clean-archived nil org-id-search-archives)))
(dolist (d (directory-files attach-dir nil valid-dir-re))
  (dolist (d+ (directory-files
   (concat attach-dir d) nil valid-dir-re))
(let ((id (format %s%s d d+))
  (full-path (concat
  attach-dir
  (file-name-as-directory d)
  d+)))
  (unless (org-id-find id)
(delete-directory full-path t)))