Peters Flexible RenAmiNg Kit (PFrank) Forum Index Peters Flexible RenAmiNg Kit (PFrank)
Support and Discussion Site for the PFrank File/Folder Renaming Tool (http://www3.telus.net/pfrank)
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Passing arguments to user defined commands

 
Post new topic   Reply to topic    Peters Flexible RenAmiNg Kit (PFrank) Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
nharding



Joined: 19 Nov 2007
Posts: 11

PostPosted: Tue Nov 20, 2007 5:10 pm    Post subject: Passing arguments to user defined commands Reply with quote

I'm writing a user defined command that file find a date in a variety of formats. It currently recognizes all the dates below.

"Date 2nd July 1967 test",
"Date July-2-1967 test",
"Date Jul 1967 test",
"5 sept 43",
"september-5-43",
"sep 1943",
"Date 17-12-2007 test",
"(1967-07-02) # What the end result should be",
"171207",
"1943 # Not a valid date",

I want it to output in the form (1967-07-02), but it would be nicer if you could specify the format output. I have thought of 2 ways of doing this.

1: Read a parameter from the search expression. (How do I get that value?)
I get an error, because *(User... * contains *

2: The other is to encode it into the filename, so a previous rule would add Date=MMDDYYYY (or another format) to the end of the string and it could use that.

Also when I try and use configurator.optionlist in the standalone mode for testing, or the options like SEARCHREP_COMMANDFILEDIRECTORY_ID these are not defined and I get an error.

I have managed to work out the indices for the configurator.optionlist by trial and error, are these safe to use for future versions? I am planning on using the a subset of the date formatter options. Once it is complete I will post it here for people to use.

I have to say this is a very good program, very flexible and I will be making a Paypal donation at the end of the month Very Happy
Back to top
View user's profile Send private message
admin
Site Admin


Joined: 09 Mar 2007
Posts: 446
Location: Canada

PostPosted: Wed Nov 21, 2007 5:11 am    Post subject: Reply with quote

Another way is to use the PFrank configurable date format parameters. You have a choice of the fixed format string or the custom format string (both are configurable on the options window using the date formatter panel).

Those strings are accessible from the configurator.optionlist variable. Try printing the values in the user-defined command with the following:

print "Fixed datetime format is: ", configurator.optionlist[SEARCHREP_OPTIONDATEFORMAT_ID]
print "custom datetime format is: ", configurator.optionlist[SEARCHREP_OPTIONCUSTOMDATE_ID]

You can use the custom format string as-is as input to the strftime function.
The configurator.optionlist is a data dictionary that stores all the PFrank configuration parameters. If you need access to any more of the parameters, then I'll give you the keys.

I'm assuming that the date/time information is not available in the file properties or stored as meta-data within the files otherwise you might be able to wipe out the date from the name and replace with info obtained from the file.

Hope all this helps!

Peter.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
nharding



Joined: 19 Nov 2007
Posts: 11

PostPosted: Wed Nov 21, 2007 7:06 pm    Post subject: Reply with quote

Thanks, one option I have found is the flag to detect whether we use FIXED or CUSTOM. What is the SEARCHREP variable that corresponds to that (currently I am using [221] == "Custom Format")

Also can the skeletal wrapper be changed to include configurator.optionlist (it gives undefined error, but I copy the variables in the __MAIN__ check, but it is slightly messy)

I've extended the date format slightly, so I can't use the standard functions, I also allow dates like Spring 1941, Christmas 2001.
Back to top
View user's profile Send private message
admin
Site Admin


Joined: 09 Mar 2007
Posts: 446
Location: Canada

PostPosted: Thu Nov 22, 2007 4:55 am    Post subject: Reply with quote

221 is correct and the "Custom Format" value is correct.
Instead of using the magic number 221 you can use the name:

SEARCHREP_CUSTOMORFIXEDDATE_ID

which is defined as 221.

I'll have to set up a stub for the configurator member and provide all the key values so that everyone can use them in a stand-alone program as you are doing. this will be in a future version of PFrank.

For now you can change the SearchRep_initStubs.py file (should be in your install folder) so that the initialization is:

def __init__ (self) :

# set up current file
self.filename = ""

self.optionlist = {}


Then you can just initialize the optionlist key values in the
if __name__ == '__main__'
block of the PFrankUser.py file.

I like your idea of the extended date format.

Looks like you are very close to completing your first plugin.
Nice Work!

Peter.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Peters Flexible RenAmiNg Kit (PFrank) Forum Index -> Plugins All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group. Hosted by phpBB.BizHat.com


Start Your Own Video Sharing Site

Free Web Hosting | Free Forum Hosting | FlashWebHost.com | Image Hosting | Photo Gallery | FreeMarriage.com

Powered by PhpBBweb.com, setup your forum now!
For Support, visit Forums.BizHat.com