I think it would be an helpful functionality to be able to save a veusz
graph into a zip archive containing all needed files to make it work on
another computer. 

The attached file is a simple concept of how a vsz script could be
parsed for Imports. Then all the imported files are compressed in a zip
archive, with a copy of the script (with renamed filenames in import
arguments).

An inverse function should be written to recognize the compressed
format, decompress it in a temporary location, add to the script an
AddImportPath for that temporary location, and redirect the usual file
opening method to the extracted script.

This way one could excange veusz graph linked to many files, along with
the files containing the data. 
I know that one could always unlink them and obtain a similar effect,
but he will loose the very original files. 
import zipfile
import os
def vsz_pack(path):
	name=os.path.basename(path)
	dirn=os.path.dirname(path)
	zipname=dirn+'/'+name[:-3]+'zvs' # without vsz
	fnames=[]
	new_names=[]
	script=open(path, 'r').read()
	ni=0
	oscript=script[:]
	for line in script.splitlines():
		if line.startswith('Import'):
			i=line.find('(')+1
			if i==0: 
				print 'skipped', line
				continue
			e=line.find(',')
			fname=line[i:e]
			if fname[0]=='u':
				fname=unicode(fname[1:])
			fname=fname.strip('\'"')
			if not os.path.exists(fname):
				print 'non existent file import', fname
				continue
			if fname not in fnames:
				fnames.append(fname)
				nn='%i_%s' % (ni, os.path.basename(fname))
				new_names.append(nn)
				oscript=script.replace(fname, nn)
				print 'found', fname, 'renamed', nn
				ni+=1
	ark=zipfile.ZipFile(zipname, 'w')
	ark.writestr('script.vsz', oscript)
	for i, f in enumerate(fnames):
		ark.write(f, new_names[i])
	ark.close()
	

vsz_pack('/home/daniele/test.vsz')
_______________________________________________
Veusz-discuss mailing list
[email protected]
https://mail.gna.org/listinfo/veusz-discuss

Répondre à