forked from seiti/geeknote-container
-
Notifications
You must be signed in to change notification settings - Fork 1
/
getplastic.py
30 lines (25 loc) · 742 Bytes
/
getplastic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#! /usr/bin/env python
from urllib2 import urlopen
from StringIO import StringIO
from tarfile import open as tarOpen
from os.path import sep, join
from os import mkdir
DIR="/root/.vim"
try:
mkdir(DIR)
except OSError:
pass
tar = tarOpen(fileobj=StringIO(urlopen("https://github.com/plasticboy/vim-markdown/archive/master.tar.gz").read()),
mode="r:gz")
# This function imitates tar's --strip=1 option and filters out unneccessary stuff
def strip_1(members):
for x in members:
sp = x.name.split(sep, 2)
if len(sp) <= 1:
continue
n = sp[1]
if n.endswith(".md") or n in ("Makefile", "test"):
continue
x.name = apply(join, sp[1:])
yield x
tar.extractall(members=strip_1(tar), path=DIR)