Generating generations of files
DL Neil
PythonList at DancesWithMice.info
Mon Apr 29 19:27:02 EDT 2019
On 30/04/19 9:04 AM, Peter J. Holzer wrote:
> On 2019-04-29 20:12:28 -0000, Grant Edwards wrote:
>> On 2019-04-29, DL Neil <PythonList at DancesWithMice.info> wrote:
>>> Are you aware of a library/utility which will generate and maintain the
>>> file names of multiple generations of a file?
>>
>> Well, the FILES-11 filesystem on VAX/VMS did that automatically, but
>> that's probably not too helpful. Though I guess Python is actually
>> available for OpenVMS, and the porting of OpenVMS to AMD64 (aka
>> x86-64) is progressing: https://www.vmssoftware.com/updates_port.html
>
> Until this is finished you could use something like this:
>
> #!/usr/bin/python3
>
> import os
>
> def open11(file, mode, **kwargs):
> if "w" in mode:
> try:
> oldfile = os.readlink(file)
> basename, version = oldfile.split(";")
> except FileNotFoundError:
> basename = os.path.basename(file)
> version = 0
> newfile = basename + ";" + str(int(version) + 1)
> os.unlink(file)
> os.symlink(newfile, file)
> return open(file, mode, **kwargs)
>
>
> if __name__ == "__main__":
> with open11("foo", "w") as f:
> f.write("test1")
>
> with open11("foo", "w") as f:
> f.write("test2")
>
> with open11("foo", "w") as f:
> f.write("test3")
>
> :-)
>
> (WARNING: I haven't really tested this)
Didn't think of the concept of using links!
As Eli showed, with a bit of refinement, we can make something from here...
Thanks!
--
Regards =dn
More information about the Python-list
mailing list