Filter for uncompressed storage of zipped document formats like docx (http://stackoverflow.com/questions/3298525/version-control-for-docx-and-pdf)
Andreas Gobell
andreasgobell at gmx.de
Fri May 13 15:40:28 UTC 2011
Am 12.05.2011 um 19:11 schrieb Martin Geisler:
> Andreas Gobell <andreasgobell at gmx.de> writes:
>
>> Thanks for the positive comments.
>>
>> I created the repository https://bitbucket.org/gobell/hg-zipdoc/, the
>> http://mercurial.selenic.com/wiki/ZipdocExtension and made an entry in
>> http://mercurial.selenic.com/wiki/UsingExtension.
>
> It looks great!
>
>> I renamed the extension to zipdoc - it sounds better and reflects that
>> it is really just a filter processing zip files and is just intended
>> to be used for zipped document formats. It works for any zip file
>> including regular zips.
>>
>> To improve the extension I added error handling when the file passed
>> to the filter is not a zip file or is broken. I think a common case
>> would be if a symlink to a zip is version controlled.
>>
>> try:
>> uncompressedDoc = zipfile.ZipFile(memoryInFile, "r")
>> except zipfile.BadZipfile:
>> userInterface = ui.ui()
>> userInterface.note(_("zipdoc: Skipped decode due to bad ZIP archive. Either the file is not a ZIP (might be a link to a ZIP file) or the archive is broken.\n"))
>> return s
>
> You should wrap such long strings to make the soruce easier to read:
>
> userInterface.note(_("zipdoc: Skipped decode due to bad ZIP archive. "
> "Either the file is not a ZIP (might be a link "
> " to a ZIP file) or the archive is broken.\n"))
>
> (Python automatically joins adjacent string literals, just like in C.)
>
>> Is this the correct way to obtain a reference to the ui object?
>
> Not really -- you get a reference to a new ui object like this.
>
>> Is it possible to get the name/path of the file that is passed to the
>> filter so I can give better user feedback by including the file
>> concerned by the message?
>
> Yeah, your filter is called like this in localrepo._filter:
>
> data = fn(data, cmd, ui=self.ui, repo=self, filename=filename)
>
> This means that your kwargs have ui, repo, and filename keys. That also
> explains where to get the right ui object from -- just change
>
> def zipdocdecode(s, cmd, **kwargs):
>
> to
>
> def zipdocdecode(s, cmd, ui, repo, filename):
>
>
> --
> Martin Geisler
>
> aragost Trifork
> Professional Mercurial support
> http://mercurial.aragost.com/kick-start/
Thanks for your help. I made the according changes to the extension and updated the repo.
Cheers
Andreas Gobell
More information about the Mercurial
mailing list