This repository has been archived by the owner on Jan 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfabfile.py
64 lines (51 loc) · 2 KB
/
fabfile.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from fabric.api import *
from armstrong.dev.tasks import test
full_name = "armstrong.cli"
@task
def reinstall():
local("pip uninstall -y `basename \`pwd\`` ; pip install .")
@task
def generate_images():
import os
import sys
sys.path.insert(0, os.getcwd())
os.environ["DJANGO_SETTINGS_MODULE"] = "settings.development"
import Image
import ImageDraw
import random
from armstrong.apps.images import models
from armstrong.apps.articles.models import Article
from armstrong.apps.related_content.models import RelatedContent, RelatedType
import datetime
from django.core.files import File
from django.conf import settings
WIDTH = 640
HEIGHT = 480
def rint(x):
return random.randint(1, x)
def getRandomPt():
return (rint(WIDTH - 1), rint(HEIGHT - 1))
def getRandomColor():
return (rint(255), rint(255), rint(255))
def make_image(path):
im = Image.new('RGB', (WIDTH, HEIGHT))
draw = ImageDraw.Draw(im)
for j in range(20):
draw.rectangle((getRandomPt(), getRandomPt()), fill=getRandomColor())
del draw
with open(path, 'wb') as f:
im.save(f)
lede_art, created = RelatedType.objects.get_or_create(title='lede_art')
for i, article in enumerate(Article.objects.all()):
image_path = '/tmp/images/image-%i.png' % i
make_image(image_path)
img = models.Image.objects.create(title='image-%i' % i,
slug='image-%i' % i,
summary='colored boxes',
pub_status='P',
pub_date=datetime.datetime.now(),
image=File(open(image_path)))
img.sites.add(settings.SITE_ID)
RelatedContent.objects.create(destination_object=img,
source_object=article,
related_type=lede_art)