RSS/Atom feed Twitter
Site is read-only, email is disabled

filetype plug-in to get type of entity (file/directory)

This discussion is connected to the gimp-developer-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

This is a read-only list on gimpusers.com so this discussion thread is read-only, too.

4 of 5 messages available
Toggle history

Please log in to manage your subscriptions.

200407162347.46356.triska@g... Markus Triska 17 Jul 01:47
  filetype plug-in to get type of entity (file/directory) Sven Neumann 21 Jul 15:37
  filetype plug-in to get type of entity (file/directory) Kevin Cozens 21 Jul 22:07
   filetype plug-in to get type of entity (file/directory) Markus Triska 22 Jul 23:05
    filetype plug-in to get type of entity (file/directory) Kevin Cozens 28 Jul 18:01
Sven Neumann
2004-07-21 15:37:24 UTC (almost 20 years ago)

filetype plug-in to get type of entity (file/directory)

Hi,

Markus Triska writes:

this is a trivial plug-in that implements one single call:

file-get-type

returning the type of the entity pointed to by 'path' (currently only: 0 = directory, 1 = file). (Symbolic constants like TYPE-DIRECTORY or such should be added if this is included.)

I'm also attaching a script that recursively traverses a given directory and returns a list of path names to (exclusively) regular files that are located inside this directory or any of its sub-directories for further processing. Try with

(all-files "/home/yourname/testdir")

on the Script-FU console, where "testdir" is a directory containing a few directories and files, NOT a few thousands (can cause problems on the console).

I'm giving this another shot (after bug #145370, taking your feedback into account - TinyScheme currently lacks a similar feature), because it seems to me that batch-processing is the single most often asked issue on the comp.graphics.apps.gimp NG, and it would be great if we could just give people a script similar to the sample I'm attaching, tell them to copy it to ~/.gimpXY/scripts/ and let's rock, without the need to download and compile a separate plug-in. After the transition to TinyScheme, they would simply type:

gimp -c -i -b "(map my-specialized-conversion (all-files "allmypictures"))"

no matter which platform they are on.

Your script is certainly useful for users of GIMP 2.0 but I don't want to see such functionality being added to the main trunk for the following reason: The plug-in attempts to fix a problem in Script-Fu. All other languages that you could use to write a GIMP script or plug-in don't have this problem as they already offer the functionality provided by your plug-in. The problem should therefore not be fixed by adding a plug-in but by fixing Script-Fu.

Alternatively to fixing Script-Fu, a replacement for Script-Fu should be found. Kevin is working on Tiny-Fu and I hope that Tiny-Fu will be ready for GIMP 2.2 thus fixing this problem for us.

Sven

Kevin Cozens
2004-07-21 22:07:19 UTC (almost 20 years ago)

filetype plug-in to get type of entity (file/directory)

Greetings, Markus (and everyone else).

At 07:47 PM 07/16/2004, you wrote:

this is a trivial plug-in that implements one single call:

file-get-type

[snip]

I'm giving this another shot (after bug #145370, taking your feedback into account - TinyScheme currently lacks a similar feature), because it seems to me that batch-processing is the single most often asked issue on the comp.graphics.apps.gimp NG, and it would be great if we could just give people a script similar to the sample I'm attaching, tell them to copy it to ~/.gimpXY/scripts/ and let's rock, without the need to download and compile a separate plug-in.

Users of GIMP 2.0.x may find your scripts useful, Markus. It could also fill a gap in the current Script-Fu plug-in. The Tiny-Fu plug-in, while not making your work obsolete, will provide an alternative approach to batch processing.

The following code snippet (shown without the 'tiny-fu-register' block) demonstrates how a script written for Tiny-Fu would be able to handle batch-processing. When called up from the GIMP menus, you would get a dialog box where you could enter (or browse for) a directory. The script will then open up the directory and generate a list of all entries (including . and ..). With the use of the 're' extension, pattern matching could be applied to the file names and only the ones that match a supplied pattern could be listed. Once I add a 'file-type' routine to one of the extension packages, it will be possible to only list files of a given type.

(define (tiny-fu-listfiles dir) (let* (
(dir-stream (open-dir-stream dir)) (file)
)

(if (not dir-stream) (gimp-message (string-append "Unable to open directory " dir)) (
(do
( (file (read-dir-entry dir-stream) (read-dir-entry dir-stream)) ) ( (eof-object? file) )
(display file)
(newline)
)
(close-dir-stream dir-stream) )
)
)
)

Also, the new file handling routines available allow for a file to be deleted (assuming you have the permissions necessary to do so).

When I mentioned on #gimp that a script should be written to demonstrate the new possibilities for scripts, schumaml suggested a contact sheet. Tiny-Fu makes such a script a very real possibility. I have already started to plan out how such a script should behave and the information a user would need to provide.

This is just a taste of the possibilities for scripting in GIMP using Scheme based scripts with Tiny-Fu. What would you like to do today? :-)

Cheers!

Kevin. (http://www.interlog.com/~kcozens/)

Owner of Elecraft K2 #2172 |"What are we going to do today, Borg?" E-mail:kcozens at interlog dot com|"Same thing we always do, Pinkutus: Packet:ve3syb@ve3yra.#con.on.ca.na| Try to assimilate the world!" #include | -Pinkutus & the Borg

Markus Triska
2004-07-22 23:05:41 UTC (almost 20 years ago)

filetype plug-in to get type of entity (file/directory)

On Wednesday 21 July 2004 08:07 pm, Kevin Cozens wrote:

This is just a taste of the possibilities for scripting in GIMP using Scheme based scripts with Tiny-Fu. What would you like to do today? :-)

Thank you for your explanation, Kevin. I was not aware of all the useful extensions you are incorporating into Tiny-Fu. I'm really looking forward to seeing (and implementing?) many scripts that will then become easy and, most of all, possible (it is now only a matter of time until someone implements all the functionality of GIMP in some Scheme script, oh wait - that's Emacs already).

By the way: I favour the current convention (used throughout GIMP scripts) of parenthesizing [for example, instead of:

(let* (          (dir-stream (open-dir-stream dir))          (file)
         )
(mycode)
)

I write:

(let* ((dir-stream (open-dir-stream dir))          (file))
(mycode))
]

because it has become the de-facto standard for Scheme (also used in TinyScheme's "init.scm", in Emacs etc.) and it is recommended in all books and tutorials I could find in print and on the web, so apart from the fact that I use this style habitually by now, maybe sticking to it will help both newcomers (being accustomed to the style from the tutorials) and professional Lisp coders (having seen more braces, so to speak) to follow the code. It also saves many lines containing only ")" and thereby allows to grasp more code at once. Maybe you also find it advantageous (or even, more beautiful?) if you try it some day (well, it can't hurt to try both for some time and see which one is more appealing).

Markus.

Kevin Cozens
2004-07-28 18:01:22 UTC (over 19 years ago)

filetype plug-in to get type of entity (file/directory)

Greetings, Markus.

At 05:05 PM 07/22/2004, you wrote:

I was not aware of all the useful extensions you are incorporating into Tiny-Fu.

There are only two extensions for the TinyScheme interpreter I'm using them both since they each add something useful for scripts. I have used the extensions to create a script that creates contact sheets. Just point it at a directory and it will create as many 1024x768 image sheets as are needed to show all images in the directory. Each image sheet will hold up to 36 images each.

By the way: I favour the current convention (used throughout GIMP scripts) of parenthesizing [for example, instead of:

[example snipped]

I write:

[example snipped]

because it has become the de-facto standard for Scheme (also used in TinyScheme's "init.scm", in Emacs etc.) and it is recommended in all books and tutorials I could find in print and on the web, so apart from the fact that I use this style habitually by now, maybe sticking to it will help both newcomers (being accustomed to the style from the tutorials) and professional Lisp coders (having seen more braces, so to speak) to follow the code.

We will have to agree to disagree about the formatting of Scheme code.

I would not treat the method used to format code as shown in a book as THE recommended guideline for how code should be formatted. Not unless they come right out and say "thou shalt format thy code thusly". :-) Books format code to save space and paper. I first learned C from K&R and I just copied their style until I became aware of a better way to format my code. I am formatting the Scheme code in a way that befits the language it is. In C, you don't put all the closing braces on one line so I don't see why a script written in Scheme should do the same with the closing parenthesis.

I was aware of LISP from some articles in early issues of BYTE magazine. I was never taught LISP or Scheme in any classes. My first experience with Scheme was with the scripts for Script-Fu. I could make some simple changes but sometimes after copying/moving a line or two, I would get problems with loops or complaints about the brackets not matching up.

I'm formatting the scripts which come with Tiny-Fu in a way that should make it much easier for someone totally new to Scheme to see and learn the syntax of the language. Something I wish had been done to the scripts I first looked at. To someone who already knows LISP or Scheme the format won't affect them as they already know the basic syntax and placement of brackets.

Cheers!

Kevin. (http://www.interlog.com/~kcozens/)

Owner of Elecraft K2 #2172 |"What are we going to do today, Borg?" E-mail:kcozens at interlog dot com|"Same thing we always do, Pinkutus: Packet:ve3syb@ve3yra.#con.on.ca.na| Try to assimilate the world!" #include | -Pinkutus & the Borg