1 |
commit: a5f76db6b3de800069672038421943b26a6b1bd2 |
2 |
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org> |
3 |
AuthorDate: Fri Jul 6 16:04:00 2012 +0000 |
4 |
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua> |
5 |
CommitDate: Fri Jul 6 16:04:00 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=a5f76db6 |
7 |
|
8 |
Save license text to database |
9 |
|
10 |
--- |
11 |
.../management/commands/scanlicensetext.py | 17 +++++++++++++++++ |
12 |
gpackages/apps/packages/models.py | 3 ++- |
13 |
gpackages/apps/packages/scan.py | 12 ++++++++++++ |
14 |
3 files changed, 31 insertions(+), 1 deletions(-) |
15 |
|
16 |
diff --git a/gpackages/apps/packages/management/commands/scanlicensetext.py b/gpackages/apps/packages/management/commands/scanlicensetext.py |
17 |
new file mode 100644 |
18 |
index 0000000..40f9de4 |
19 |
--- /dev/null |
20 |
+++ b/gpackages/apps/packages/management/commands/scanlicensetext.py |
21 |
@@ -0,0 +1,17 @@ |
22 |
+from django.core.management.base import BaseCommand, CommandError |
23 |
+from packages.scan import Scanner |
24 |
+from optparse import make_option |
25 |
+ |
26 |
+ |
27 |
+class Command(BaseCommand): |
28 |
+ option_list = BaseCommand.option_list + ( |
29 |
+ make_option('--not-show-time', |
30 |
+ action='store_false', |
31 |
+ dest='show_time', |
32 |
+ default=True, |
33 |
+ help='Show time of scanning'), |
34 |
+ ) |
35 |
+ args = '' |
36 |
+ help = 'Will scan license text' |
37 |
+ def handle(self, *args, **options): |
38 |
+ Scanner(license_text = True, **options).scan() |
39 |
|
40 |
diff --git a/gpackages/apps/packages/models.py b/gpackages/apps/packages/models.py |
41 |
index 1bfc2ba..c89db88 100644 |
42 |
--- a/gpackages/apps/packages/models.py |
43 |
+++ b/gpackages/apps/packages/models.py |
44 |
@@ -494,7 +494,8 @@ class LicenseModel(StatsModel): |
45 |
) |
46 |
|
47 |
name = models.CharField(unique = True, max_length = 60, db_index = True) |
48 |
- #description = TextField() |
49 |
+ text = models.TextField(null = True) |
50 |
+ #description = models.TextField() |
51 |
|
52 |
# Autogenerated fields for fast stats |
53 |
#ebuilds_count = models.PositiveIntegerField(default = 0) |
54 |
|
55 |
diff --git a/gpackages/apps/packages/scan.py b/gpackages/apps/packages/scan.py |
56 |
index 0fdf488..e0cc09c 100644 |
57 |
--- a/gpackages/apps/packages/scan.py |
58 |
+++ b/gpackages/apps/packages/scan.py |
59 |
@@ -129,6 +129,7 @@ class Scanner(object): |
60 |
self.scan_local_use_descr = bool_get('scan_local_use', False) |
61 |
self.is_scan_license_groups = bool_get('scan_license_groups', False) |
62 |
self.is_scan_news = bool_get('scan_news', False) |
63 |
+ self.is_scan_license_text = bool_get('license_text', False) |
64 |
|
65 |
def show_time(self): |
66 |
"Prints scan time" |
67 |
@@ -168,6 +169,9 @@ class Scanner(object): |
68 |
if self.is_scan_news: |
69 |
self.scan_news() |
70 |
|
71 |
+ if self.is_scan_license_text: |
72 |
+ self.scan_license_text() |
73 |
+ |
74 |
if self.is_show_time: |
75 |
self.show_time() |
76 |
|
77 |
@@ -702,3 +706,11 @@ class Scanner(object): |
78 |
n_obj.save(force_update = True) |
79 |
self.update_related_to_news(n, n_obj) |
80 |
|
81 |
+ def scan_license_text(self): |
82 |
+ licenses = models.LicenseModel.objects.all() |
83 |
+ for license in licenses: |
84 |
+ text = porttree.licenses.get_license(license.name) |
85 |
+ if text: |
86 |
+ license.text = smart_unicode(text, errors='ignore') |
87 |
+ license.save(force_update = True) |
88 |
+ |