This is my first time writing a python script. So, I need a little help getting kick started. In a folder called Test I have three PloneExternalFiles much like the Zope version of ExtFile. I am writing a python script to delete those files that are over 5 days old. I am trying to start small so for right now I don't want to worry about a scheduler, I just want to get started writing the script. I have some pseudocode that I have written and I am slowly tranferring it to the python script. So for example I want to pass the ploneexternalfile id's to the python script. So would I just put ## parameters=id ? Additionally, how would I compare the system date to the modification date of the file? I know in the PloneExternalFile.py they use getFileModDate method would I use this or do I need something else while id: mod_date = ? sys_date = ? cmp(mod_date, sys_date) if mod_date > 5 ?.manage_delObjects(id) Any ideas would help me. I have been stuck on this too long. Thanks.
http://docs.python.org/modindex.html Check the os and os.path module. Laura McCord wrote:
This is my first time writing a python script.
So, I need a little help getting kick started.
In a folder called Test I have three PloneExternalFiles much like the Zope version of ExtFile. I am writing a python script to delete those files that are over 5 days old. I am trying to start small so for right now I don't want to worry about a scheduler, I just want to get started writing the script. I have some pseudocode that I have written and I am slowly tranferring it to the python script.
So for example I want to pass the ploneexternalfile id's to the python script. So would I just put ## parameters=id ?
Additionally, how would I compare the system date to the modification date of the file? I know in the PloneExternalFile.py they use getFileModDate method would I use this or do I need something else
while id: mod_date = ? sys_date = ? cmp(mod_date, sys_date) if mod_date > 5 ?.manage_delObjects(id)
Any ideas would help me. I have been stuck on this too long.
Thanks.
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Il ven, 2004-05-14 alle 17:27, Joseph Kocherhans ha scritto:
yes, you have 2 ways to resolve your problem, 1) you can use cron (unix system service) and a python script to schedule and selectively delete your files directly from the filesystem. In this case you should start as Joseph told you, by looking into the standard os and os.path python modules; 2) you can use a Zope Python Script; in this case, you should loop over the files of a given folder and check the that of every file in the folder, delting them appropriately: ##parameters= folder, date # i suppose that date is a DateTime object if not, uncomment next line #date = DateTime(date) # obtain a list containing only PloneExternalFiles files = folder.objectItems('Plone External File') # loop over the file list for id, file in files: mod_date = DateTime (file.getFileModDate()) if mod_date < Date: # delete it folder.manage_delObjects(id) You should however have a look at the DateTime module into zope's help, as i don't know how the date coming from the PloneExternalFile is formatted and maybe it needs some adjustements ;-) azazel
participants (3)
-
azazel -
Joseph Kocherhans -
Laura McCord