Sublime Forum

Plugin that will download a file and extract it

#1

Hi,

I’m trying to write a simple plugin that will download a file and extract it into a specific directory under the current project root. So for example, I’d have a command that takes two parameters:

download http://example.com/myarchive.gz assets/components

And that would download example.com/myarchive.gz, extract it into [project root]/assets/components/myarchive, and then delete the old file.

I’m at a complete loss as to how to do this, and I’m struggling to find any similar examples to learn from. Any pointers in the right direction would be fantastic. Thanks in advance for any help.

Jack

0 Likes

#2

You should be able to write a command that first prompts for a URL, then for an extraction location. I’m sure there’s some python library (or perhaps use a command like curl if you are only developing for nix systems) to get the file. I am also sure there is a python library to perform the extractions. Sorry I don’t know exactly what they are, I am just making an assumption that they exist based on how widely python is used. In terms of prompting, you may be able to use something like window.show_input_panel (which is documented as part of the api).

Anyways, best of luck.

0 Likes

#3

For a starting point, take a look at: net.tutsplus.com/articles/news/i … uts-fetch/

0 Likes

#4

Thanks guys! That Fetch plugin does almost exactly what I want already, so I may be able to build something on top of that. I’m not too hot on python, but will have a go.

0 Likes