Re: [Vala] Simple filewalker code. Comments?

2015-08-07 Thread Raum
Hello

My objective was not to monitor un real tome so... No :-)

Regards

Le 6 août 2015 20:33, Al Thomas astav...@yahoo.co.uk a écrit :

  From: Raum r...@no-log.org 
  Sent: Wednesday, 5 August 2015, 8:19 
  Subject: Re: [Vala] Simple filewalker code.  Comments? 
  
  Hello 
  
  I've tried to code something similar 
  https://github.com/Raumy/check_fs 
  
  (It uses md5 hash to check changed files on filesystems) 
  
  You should have a look to check.vala. 


 Thanks for sharing your code. Looks like a useful example 
 of GLib's FileEnumerator. 

 Had you tried GLib's FileMonitor to check for changed files? 
 ( http://valadoc.org/#!api=gio-2.0/GLib.FileMonitor ) 

 Al 
 ___ 
 vala-list mailing list 
 vala-list@gnome.org 
 https://mail.gnome.org/mailman/listinfo/vala-list 
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Simple filewalker code. Comments?

2015-08-05 Thread Raum

Hello

I've tried to code something similar
https://github.com/Raumy/check_fs

(It uses md5 hash to check changed files on filesystems)

I should write a makefile and more comments ^_^ (main class name ils testapp... 
So you should consider this ils not finished :-) )

You should have a look to check.vala.

Regards

Le 28 juil. 2015 12:55, Al Thomas astav...@yahoo.co.uk a écrit :

  From: Charles Hixson charleshixsn@earthl

ink.net   Sent: Tuesday, 28 July 2015, 1:40   Subject: Re: [Vala] Simple 
filewalker code.  Comments? Well, part of what I was looking for was 
stylistic pointers.    The Wiki Vala hacking page has a style guide:  
https://wiki.gnome.org/Projects/Vala/Hacking#Coding_Style  and Elementary OS 
write their apps in Vala and they seem  to be using similar:  
https://elementary.io/docs/code/reference#code-style  Although Yorba take a 
different approach:  https://wiki.gnome.org/Apps/Geary/CodingConventions   
That's code formatting style, but also Vala is seen  generally as an object 
oriented language so you want  to be thinking about classes and interfaces. 
Starting to  get an understanding of design patterns by the so-called  Gang 
of Four and also the SOLID principles helped me. This is  the first 
thing I've written in vala.  Partially, the find command is   less than 
optimal because I want to include the code within another   program.    I 
use find and it took a while for me to get to grips with it  so I thought I 
would share a tip based on what I use. Many languages include a simple 
filewalking approach, and I   was somewhat surprised that I couldn't find one 
within vala, so   partially I was looking for a pointer to a library that I 
had overlooked.That's interesting, for low level stuff GLib is often the 
firstplace to look. The best I could find was this StackOverflow answer  
http://stackoverflow.com/questions/2217519/how-to-walk-a-directory-in-c  One 
answer pointed to GFileEnumerator. Code examples on Valadoc:  
http://valadoc.org/#!api=gio-2.0/GLib.FileEnumerator  but not recursive from 
what I can see.  And partially I was looking for pointers as to where 
the community  recommended that beginners post code and look for tips. 
I haven't been really pleased by the documentation of vala that I could   
find, so I was hoping that there was someplace better than the mailing   
list...and a bit over 24 hours for the first response isn't   encouraging.  
OTOH, the civil response *is* encouraging.  ValaDoc is   greatly improved 
over the last time I investigated vala, but many things   still seem to 
assume that you are coming from a background of C   coding...and that you 
remember the C libraries.  My most recent   background is Python and D, so 
I'm often left in confusion until I dig   back deeper...which slows 
everything down. You could try StackOverflow:  
http://stackoverflow.com/questions/tagged/vala   One of Vala's key points is 
its strong compatibility  with C. This enables a lot of libraries to be used 
in  a modern object oriented way without having to rewrite  the libraries. 
This does mean though you may have to start  a search with how something is 
done in C, often GLib,  and then see if their is a Vala translation.
Being able to recognise some basic C interfaces has a  lot less cognitive load 
that trying to write good,  scalable code in C.   As to response times that 
is a function of the number  of people you are addressing and whether your 
question  piques their interest. The larger the community the more  chance of 
getting someone's interest and they will then  take the time to write a 
response. Vala certainly has a  smaller community than Python. 
   On 07/27/2015 12:57 PM, Al Thomas wrote:    From: Charles Hixson   
   Sent: Sunday, 26 July 2015, 21:09    Subject: [Vala] Simple 
filewalker code.  Comments?  T his is working filewalker code, but 
I'm hoping someone will tell   me if    this is the correct approach.  
  correctness depends on your criteria. You say it works so it is   
correct.  If on the other hand you want to be productive. Why 
reinvent the wheel?    Why not just use something like the 'find' command 
line tool, e.g.    find ./ -type d -exec du --human-readable '{}' \;    
will apply the disk usage command to each file in the current directory.    
It is a trivial example that just shows how much space each file takes up.   
   If you want to create a program with a bit more flexibility. Create a  
  list of file paths in the first step. Then apply a filter function    to 
each path, so you would use this to remove directories and then    another 
filter function to remove symlinks, as per your current program.    This 
allows you to add other filters later.    Once you have a good list iterate 
over it and call your function, or   functions    if you add more in 
future, with the file path as the parameter.  For a list exmaple see: 
   https://wiki.gnome.org/Projects/Vala

Re: [Vala] Simple filewalker code. Comments?

2015-07-28 Thread Al Thomas
 From: Charles Hixson charleshi...@earthlink.net
 Sent: Tuesday, 28 July 2015, 1:40
 Subject: Re: [Vala] Simple filewalker code.  Comments?
 
 Well, part of what I was looking for was stylistic pointers.  

The Wiki Vala hacking page has a style guide:
https://wiki.gnome.org/Projects/Vala/Hacking#Coding_Style
and Elementary OS write their apps in Vala and they seem 
to be using similar:
https://elementary.io/docs/code/reference#code-style
Although Yorba take a different approach:
https://wiki.gnome.org/Apps/Geary/CodingConventions

That's code formatting style, but also Vala is seen
generally as an object oriented language so you want
to be thinking about classes and interfaces. Starting to
get an understanding of design patterns by the so-called 
Gang of Four and also the SOLID principles helped me. 


 This is  the first thing I've written in vala.  Partially, the find command 
 is 
 less than optimal because I want to include the code within another 
 program.  

I use find and it took a while for me to get to grips with it
so I thought I would share a tip based on what I use.


 Many languages include a simple filewalking approach, and I 
 was somewhat surprised that I couldn't find one within vala, so 
 partially I was looking for a pointer to a library that I had overlooked.


That's interesting, for low level stuff GLib is often the firstplace to look. 
The best I could find was this StackOverflow answer
http://stackoverflow.com/questions/2217519/how-to-walk-a-directory-in-c
One answer pointed to GFileEnumerator. Code examples on Valadoc:
http://valadoc.org/#!api=gio-2.0/GLib.FileEnumerator
but not recursive from what I can see.



 And partially I was looking for pointers as to where the community  
 recommended that beginners post code and look for tips.
 
 I haven't been really pleased by the documentation of vala that I could 
 find, so I was hoping that there was someplace better than the mailing 
 list...and a bit over 24 hours for the first response isn't 
 encouraging.  OTOH, the civil response *is* encouraging.  ValaDoc is 
 greatly improved over the last time I investigated vala, but many things 
 still seem to assume that you are coming from a background of C 
 coding...and that you remember the C libraries.  My most recent 
 background is Python and D, so I'm often left in confusion until I dig 
 back deeper...which slows everything down.  


You could try StackOverflow:
http://stackoverflow.com/questions/tagged/vala

One of Vala's key points is its strong compatibility
with C. This enables a lot of libraries to be used in
a modern object oriented way without having to rewrite
the libraries. This does mean though you may have to start
a search with how something is done in C, often GLib, 
and then see if their is a Vala translation.


Being able to recognise some basic C interfaces has a
lot less cognitive load that trying to write good, 
scalable code in C.

As to response times that is a function of the number
of people you are addressing and whether your question
piques their interest. The larger the community the more
chance of getting someone's interest and they will then
take the time to write a response. Vala certainly has a 
smaller community than Python.







 
 On 07/27/2015 12:57 PM, Al Thomas wrote:
  From: Charles Hixson charleshi...@earthlink.net
 
  Sent: Sunday, 26 July 2015, 21:09
  Subject: [Vala] Simple filewalker code.  Comments?
 
  T his is working filewalker code, but I'm hoping someone will tell 
 me if
  this is the correct approach.
  correctness depends on your criteria. You say it works so it is 
 correct.
 
  If on the other hand you want to be productive. Why reinvent the wheel?
  Why not just use something like the 'find' command line tool, e.g.
  find ./ -type d -exec du --human-readable '{}' \;
  will apply the disk usage command to each file in the current directory.
  It is a trivial example that just shows how much space each file takes up.
 
  If you want to create a program with a bit more flexibility. Create a
  list of file paths in the first step. Then apply a filter function
  to each path, so you would use this to remove directories and then
  another filter function to remove symlinks, as per your current program.
  This allows you to add other filters later.
  Once you have a good list iterate over it and call your function, or 
 functions
  if you add more in future, with the file path as the parameter.
 
  For a list exmaple see:
  https://wiki.gnome.org/Projects/Vala/GeeSamples
 
  All the best with it,
 
  Al
  ___
  vala-list mailing list
  vala-list@gnome.org
  https://mail.gnome.org/mailman/listinfo/vala-list
 
 
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Simple filewalker code. Comments?

2015-07-27 Thread Al Thomas
 From: Charles Hixson charleshi...@earthlink.net


 Sent: Sunday, 26 July 2015, 21:09
 Subject: [Vala] Simple filewalker code.  Comments?
 
T his is working filewalker code, but I'm hoping someone will tell me if 
 this is the correct approach.
correctness depends on your criteria. You say it works so it is correct.

If on the other hand you want to be productive. Why reinvent the wheel?
Why not just use something like the 'find' command line tool, e.g. 
find ./ -type d -exec du --human-readable '{}' \;
will apply the disk usage command to each file in the current directory.
It is a trivial example that just shows how much space each file takes up.

If you want to create a program with a bit more flexibility. Create a 
list of file paths in the first step. Then apply a filter function 
to each path, so you would use this to remove directories and then
another filter function to remove symlinks, as per your current program.
This allows you to add other filters later.
Once you have a good list iterate over it and call your function, or functions
if you add more in future, with the file path as the parameter. 

For a list exmaple see: 
https://wiki.gnome.org/Projects/Vala/GeeSamples

All the best with it,

Al
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


[Vala] Simple filewalker code. Comments?

2015-07-26 Thread Charles Hixson
This is working filewalker code, but I'm hoping someone will tell me if 
this is the correct approach.


// valac --pkg gio-2.0 listdir.vala
// ./listdir

//TODO   rewrite the code to use this to specify the action.
delegate void ProcessFile (string fileName);

// Walk the paths descendant from the given position, applying an action
// to each regular file encountered.
void  walker   (string path)
{
   var   filD  =  File.new_for_path(path);
   if (!filD.query_exists())
   {  stderr.printf (ProcessFile:  Dir does not exist \%s\\n, 
path);   }


   Dir   d;
   string?  name;
   try   {  d =  Dir.open(path);   }
   catch
   {  stderr.printf (Dir %s was not openable.\n, path);
  return;
   }
   while ((name = d.read_name()) != null)
   {  var   fil   =  File.new_for_path(path);
  if (!fil.query_exists())
  {  stderr.printf (ProcessFile:  File does not exist \%s\\n, 
path);

 continue;
  }
  string   here  =  Path.build_filename(path, name);
  if (FileUtils.test(here, FileTest.IS_SYMLINK) )
  {  stdout.printf (Symlink %s was not followed.\n, here);  }
  else if (FileUtils.test(here, FileTest.IS_REGULAR) )
  {  walkerAct (here); }
  else if (FileUtils.test (here, FileTest.IS_DIR) )
  {  walker (here); }
   }

}  //end void  walker   (string path)

// The thing to do to each regular file
void  walkerAct(string path)
{  stdout.printf(%s\n, path);  }

// List current directory
void  main()
{ var   fil   =  File.new_for_path(.);
   string   here  =  fil.resolve_relative_path(.).get_path();
   stdout.printf(At: %s\n, here);
   walker (here);
}

___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list