specfile icon indicating copy to clipboard operation
specfile copied to clipboard

Create Specfile from a virtual file

Open FrostyX opened this issue 2 years ago • 4 comments

Currently, it is possible to create an object of Specfile like this:

# using an absolute path
specfile = Specfile('/tmp/test.spec')

# using a relative path and a different sourcedir
specfile = Specfile('test.spec', sourcedir='/tmp/sources')

It would be nice to be able to create it also like this

with open('/tmp/test.spec', 'r') as fp:
    specfile = Specfile(fp)

This alone is not so interesting, but it allows for creating Specfile from a virtual file

from io import StringIO
fp = StringIO()
fp.write("Name: foo\nVersion: 1.0\nRelease: 1\n...")
specfile = Specfile(fp)

Of course, I am interested in the feature, not the exact syntax. My suggestion will probably have an issue with the .save() method so if it is done like

specfile = Specfile(fp=fp)

# or

specfile = Specfile.from_fp(fp)

It is all fine with me :-)

FrostyX avatar Feb 04 '23 06:02 FrostyX