aboutsummaryrefslogtreecommitdiffstats
path: root/servo/management
diff options
context:
space:
mode:
Diffstat (limited to 'servo/management')
-rw-r--r--servo/management/commands/clearcache.py9
-rw-r--r--servo/management/commands/periodic.py51
-rw-r--r--servo/management/commands/upgrade.py12
3 files changed, 69 insertions, 3 deletions
diff --git a/servo/management/commands/clearcache.py b/servo/management/commands/clearcache.py
index 7c00ef4..ce96459 100644
--- a/servo/management/commands/clearcache.py
+++ b/servo/management/commands/clearcache.py
@@ -1,12 +1,15 @@
# -*- coding: utf-8 -*-
-from django.core.cache import cache
+from django.core.cache import caches
from django.core.management.base import BaseCommand
class Command(BaseCommand):
- help = "Clears this install's cache"
+ help = "Clears this install's caches"
def handle(self, *args, **options):
- cache.clear()
+ for c in caches.all():
+ c.clear()
+
+ exit(0)
diff --git a/servo/management/commands/periodic.py b/servo/management/commands/periodic.py
new file mode 100644
index 0000000..e85f9a3
--- /dev/null
+++ b/servo/management/commands/periodic.py
@@ -0,0 +1,51 @@
+# -*- coding: utf-8 -*-
+
+import os
+import sys
+import gsxws
+import subprocess
+from time import strftime
+from django.conf import settings
+from django.core.cache import caches
+from django.core.management.base import BaseCommand
+
+from servo.models import GsxAccount, Article
+
+
+class Command(BaseCommand):
+ help = 'Peforms periodic commands'
+ VERBS = ('comptia', 'articles',)
+
+ def add_arguments(self, parser):
+ parser.add_argument('verb', type=str, choices=self.VERBS, help='Periodic command to perform')
+
+ def handle(self, *args, **options):
+ try:
+ act = GsxAccount.fallback()
+ except Exception as e:
+ print >> sys.stderr, 'Failed to connect to GSX (%s)' % e
+ sys.exit(-1)
+
+ if 'articles' in options['verb']: # Update GSX articles
+ articles = gsxws.comms.fetch()
+ for a in articles:
+ try:
+ article = Article.from_gsx(a)
+ try:
+ content = gsxws.comms.content(article.gsx_id)
+ article.content = content.articleContent
+ except Exception as e:
+ pass
+ article.save()
+ except ValueError as e:
+ pass
+
+ if 'comptia' in options['verb']: # Update raw CompTIA data (all product groups)
+ try:
+ codes = gsxws.comptia.fetch()
+ caches['comptia'].set('codes', codes)
+ except Exception as e:
+ print >> sys.stderr, 'Failed to fetch CompTIA codes (%s)' % e
+ sys.exit(-1)
+
+ exit(0)
diff --git a/servo/management/commands/upgrade.py b/servo/management/commands/upgrade.py
new file mode 100644
index 0000000..f232e73
--- /dev/null
+++ b/servo/management/commands/upgrade.py
@@ -0,0 +1,12 @@
+# -*- coding: utf-8 -*-
+
+import subprocess
+from django.core.management.base import BaseCommand
+
+
+class Command(BaseCommand):
+
+ help = "Upgrade requirements"
+
+ def handle(self, *args, **options):
+ subprocess.call(['pip', 'install', '-U', '-r', 'requirements.pip'])