diff options
author | Alexandru DAMIAN <alexandru.damian@intel.com> | 2014-11-14 17:07:06 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2014-11-21 11:49:23 +0000 |
commit | 0b6859cdf3a4b66bb8b94361681a5b6b362f93ae (patch) | |
tree | 37bf5c650e99b023bd0e0605b63a53cc0ebd0b72 /bitbake/lib/toaster/orm/models.py | |
parent | 5b0616ad7d7c3734f1818a56b631a2d254271678 (diff) | |
download | poky-0b6859cdf3a4b66bb8b94361681a5b6b362f93ae.tar.gz |
bitbake: toastergui: layer name correlation
This patch modifies how layers are identified and matched.
Layers were primarely organized by the source of layer information,
and Releases were separated by both layer git branches and originating
source of layer information. This setup prevented mixing layers from
different sources for a certain release, which didn't match the way
people use Yocto Project / bitbake.
This patch brings name-based indentification, where layers with the
same name are assumed to be equivalent, in the sense of being able
to substitute one another. To facilitate this identification to
humans, layers are differentiated by GIT URI instead of layer sources,
which was a rather arbitrary abstraction.
Additional changes include modification to models in order accomodate
for the new data structure, and to config file loading to match
the new toasterconf.json layout.
(Bitbake rev: 4357200aed522ad56cfd84917f877645b83b6a70)
Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster/orm/models.py')
-rw-r--r-- | bitbake/lib/toaster/orm/models.py | 115 |
1 files changed, 86 insertions, 29 deletions
diff --git a/bitbake/lib/toaster/orm/models.py b/bitbake/lib/toaster/orm/models.py index d99a4c2129..c90e047caf 100644 --- a/bitbake/lib/toaster/orm/models.py +++ b/bitbake/lib/toaster/orm/models.py | |||
@@ -21,7 +21,6 @@ | |||
21 | 21 | ||
22 | from django.db import models | 22 | from django.db import models |
23 | from django.db.models import F | 23 | from django.db.models import F |
24 | from django.utils.encoding import python_2_unicode_compatible | ||
25 | from django.utils import timezone | 24 | from django.utils import timezone |
26 | 25 | ||
27 | 26 | ||
@@ -54,9 +53,6 @@ class ToasterSetting(models.Model): | |||
54 | def __unicode__(self): | 53 | def __unicode__(self): |
55 | return "Setting %s" % self.name | 54 | return "Setting %s" % self.name |
56 | 55 | ||
57 | class ToasterSettingDefaultLayer(models.Model): | ||
58 | layer_version = models.ForeignKey('Layer_Version') | ||
59 | |||
60 | class ProjectManager(models.Manager): | 56 | class ProjectManager(models.Manager): |
61 | def create_project(self, name, release): | 57 | def create_project(self, name, release): |
62 | prj = self.model(name = name, bitbake_version = release.bitbake_version, release = release) | 58 | prj = self.model(name = name, bitbake_version = release.bitbake_version, release = release) |
@@ -68,10 +64,10 @@ class ProjectManager(models.Manager): | |||
68 | name = name, | 64 | name = name, |
69 | value = defaultconf.value) | 65 | value = defaultconf.value) |
70 | 66 | ||
71 | for layer in map(lambda x: x.layer, ReleaseDefaultLayer.objects.filter(release = release)): | 67 | |
72 | for branches in Branch.objects.filter(name = release.branch): | 68 | for rdl in release.releasedefaultlayer_set.all(): |
73 | for lv in Layer_Version.objects.filter(layer = layer, up_branch = branches ): | 69 | lv = Layer_Version.objects.filter(layer__name = rdl.layer_name, up_branch__name = release.branch_name)[0].get_equivalents_wpriority(prj)[0] |
74 | ProjectLayer.objects.create( project = prj, | 70 | ProjectLayer.objects.create( project = prj, |
75 | layercommit = lv, | 71 | layercommit = lv, |
76 | optional = False ) | 72 | optional = False ) |
77 | 73 | ||
@@ -84,6 +80,7 @@ class ProjectManager(models.Manager): | |||
84 | raise Exception("Invalid call to Project.objects.get_or_create. Use Project.objects.create_project() to create a project") | 80 | raise Exception("Invalid call to Project.objects.get_or_create. Use Project.objects.create_project() to create a project") |
85 | 81 | ||
86 | class Project(models.Model): | 82 | class Project(models.Model): |
83 | search_allowed_fields = ['name', 'short_description', 'release__name', 'release__branch_name'] | ||
87 | name = models.CharField(max_length=100) | 84 | name = models.CharField(max_length=100) |
88 | short_description = models.CharField(max_length=50, blank=True) | 85 | short_description = models.CharField(max_length=50, blank=True) |
89 | bitbake_version = models.ForeignKey('BitbakeVersion') | 86 | bitbake_version = models.ForeignKey('BitbakeVersion') |
@@ -97,6 +94,8 @@ class Project(models.Model): | |||
97 | user_id = models.IntegerField(null = True) | 94 | user_id = models.IntegerField(null = True) |
98 | objects = ProjectManager() | 95 | objects = ProjectManager() |
99 | 96 | ||
97 | def __unicode__(self): | ||
98 | return "%s (%s, %s)" % (self.name, self.release, self.bitbake_version) | ||
100 | 99 | ||
101 | def schedule_build(self): | 100 | def schedule_build(self): |
102 | from bldcontrol.models import BuildRequest, BRTarget, BRLayer, BRVariable, BRBitbake | 101 | from bldcontrol.models import BuildRequest, BRTarget, BRLayer, BRVariable, BRBitbake |
@@ -184,7 +183,6 @@ class ProjectTarget(models.Model): | |||
184 | target = models.CharField(max_length=100) | 183 | target = models.CharField(max_length=100) |
185 | task = models.CharField(max_length=100, null=True) | 184 | task = models.CharField(max_length=100, null=True) |
186 | 185 | ||
187 | @python_2_unicode_compatible | ||
188 | class Target(models.Model): | 186 | class Target(models.Model): |
189 | search_allowed_fields = ['target', 'file_name'] | 187 | search_allowed_fields = ['target', 'file_name'] |
190 | build = models.ForeignKey(Build) | 188 | build = models.ForeignKey(Build) |
@@ -196,7 +194,7 @@ class Target(models.Model): | |||
196 | def package_count(self): | 194 | def package_count(self): |
197 | return Target_Installed_Package.objects.filter(target_id__exact=self.id).count() | 195 | return Target_Installed_Package.objects.filter(target_id__exact=self.id).count() |
198 | 196 | ||
199 | def __str__(self): | 197 | def __unicode__(self): |
200 | return self.target | 198 | return self.target |
201 | 199 | ||
202 | class Target_Image_File(models.Model): | 200 | class Target_Image_File(models.Model): |
@@ -391,10 +389,10 @@ class Package_Dependency(models.Model): | |||
391 | (TYPE_RREPLACES, "replaces"), | 389 | (TYPE_RREPLACES, "replaces"), |
392 | (TYPE_RCONFLICTS, "conflicts"), | 390 | (TYPE_RCONFLICTS, "conflicts"), |
393 | ) | 391 | ) |
394 | ''' Indexed by dep_type, in view order, key for short name and help | 392 | """ Indexed by dep_type, in view order, key for short name and help |
395 | description which when viewed will be printf'd with the | 393 | description which when viewed will be printf'd with the |
396 | package name. | 394 | package name. |
397 | ''' | 395 | """ |
398 | DEPENDS_DICT = { | 396 | DEPENDS_DICT = { |
399 | TYPE_RDEPENDS : ("depends", "%s is required to run %s"), | 397 | TYPE_RDEPENDS : ("depends", "%s is required to run %s"), |
400 | TYPE_TRDEPENDS : ("depends", "%s is required to run %s"), | 398 | TYPE_TRDEPENDS : ("depends", "%s is required to run %s"), |
@@ -509,33 +507,47 @@ class LayerSource(models.Model): | |||
509 | 507 | ||
510 | TYPE_LOCAL = 0 | 508 | TYPE_LOCAL = 0 |
511 | TYPE_LAYERINDEX = 1 | 509 | TYPE_LAYERINDEX = 1 |
510 | TYPE_IMPORTED = 2 | ||
512 | SOURCE_TYPE = ( | 511 | SOURCE_TYPE = ( |
513 | (TYPE_LOCAL, "local"), | 512 | (TYPE_LOCAL, "local"), |
514 | (TYPE_LAYERINDEX, "layerindex"), | 513 | (TYPE_LAYERINDEX, "layerindex"), |
514 | (TYPE_IMPORTED, "imported"), | ||
515 | ) | 515 | ) |
516 | 516 | ||
517 | name = models.CharField(max_length=63) | 517 | name = models.CharField(max_length=63, unique = True) |
518 | sourcetype = models.IntegerField(choices=SOURCE_TYPE) | 518 | sourcetype = models.IntegerField(choices=SOURCE_TYPE) |
519 | apiurl = models.CharField(max_length=255, null=True, default=None) | 519 | apiurl = models.CharField(max_length=255, null=True, default=None) |
520 | 520 | ||
521 | def update(self): | ||
522 | """ | ||
523 | Updates the local database information from the upstream layer source | ||
524 | """ | ||
525 | raise Exception("Abstract, update() must be implemented by all LayerSource-derived classes (object is %s)" % str(vars(self))) | ||
526 | |||
521 | def save(self, *args, **kwargs): | 527 | def save(self, *args, **kwargs): |
522 | if isinstance(self, LocalLayerSource): | 528 | if isinstance(self, LocalLayerSource): |
523 | self.sourcetype = LayerSource.TYPE_LOCAL | 529 | self.sourcetype = LayerSource.TYPE_LOCAL |
524 | elif isinstance(self, LayerIndexLayerSource): | 530 | elif isinstance(self, LayerIndexLayerSource): |
525 | self.sourcetype = LayerSource.TYPE_LAYERINDEX | 531 | self.sourcetype = LayerSource.TYPE_LAYERINDEX |
532 | elif isinstance(self, ImportedLayerSource): | ||
533 | self.sourcetype = LayerSource.TYPE_IMPORTED | ||
526 | elif self.sourcetype == None: | 534 | elif self.sourcetype == None: |
527 | raise Exception("Invalid LayerSource type") | 535 | raise Exception("Unknown LayerSource-derived class. If you added a new layer source type, fill out all code stubs.") |
528 | return super(LayerSource, self).save(*args, **kwargs) | 536 | return super(LayerSource, self).save(*args, **kwargs) |
529 | 537 | ||
530 | def get_object(self): | 538 | def get_object(self): |
531 | if self.sourcetype is not None: | 539 | if self.sourcetype == LayerSource.TYPE_LOCAL: |
532 | if self.sourcetype == LayerSource.TYPE_LOCAL: | 540 | self.__class__ = LocalLayerSource |
533 | self.__class__ = LocalLayerSource | 541 | elif self.sourcetype == LayerSource.TYPE_LAYERINDEX: |
534 | if self.sourcetype == LayerSource.TYPE_LAYERINDEX: | 542 | self.__class__ = LayerIndexLayerSource |
535 | self.__class__ = LayerIndexLayerSource | 543 | elif self.sourcetype == LayerSource.TYPE_IMPORTED: |
544 | self.__class__ = ImportedLayerSource | ||
545 | else: | ||
546 | raise Exception("Unknown LayerSource type. If you added a new layer source type, fill out all code stubs.") | ||
536 | return self | 547 | return self |
537 | 548 | ||
538 | return "LS " + self.sourcetype + " " + self.name | 549 | def __unicode__(self): |
550 | return "%s (%s)" % (self.name, self.sourcetype) | ||
539 | 551 | ||
540 | 552 | ||
541 | class LocalLayerSource(LayerSource): | 553 | class LocalLayerSource(LayerSource): |
@@ -547,11 +559,26 @@ class LocalLayerSource(LayerSource): | |||
547 | self.sourcetype = LayerSource.TYPE_LOCAL | 559 | self.sourcetype = LayerSource.TYPE_LOCAL |
548 | 560 | ||
549 | def update(self): | 561 | def update(self): |
550 | ''' | 562 | """ |
563 | Fetches layer, recipe and machine information from local repository | ||
564 | """ | ||
565 | pass | ||
566 | |||
567 | class ImportedLayerSource(LayerSource): | ||
568 | class Meta(LayerSource._meta.__class__): | ||
569 | proxy = True | ||
570 | |||
571 | def __init__(self, *args, **kwargs): | ||
572 | super(ImportedLayerSource, self).__init__(args, kwargs) | ||
573 | self.sourcetype = LayerSource.TYPE_IMPORTED | ||
574 | |||
575 | def update(self): | ||
576 | """ | ||
551 | Fetches layer, recipe and machine information from local repository | 577 | Fetches layer, recipe and machine information from local repository |
552 | ''' | 578 | """ |
553 | pass | 579 | pass |
554 | 580 | ||
581 | |||
555 | class LayerIndexLayerSource(LayerSource): | 582 | class LayerIndexLayerSource(LayerSource): |
556 | class Meta(LayerSource._meta.__class__): | 583 | class Meta(LayerSource._meta.__class__): |
557 | proxy = True | 584 | proxy = True |
@@ -566,9 +593,9 @@ class LayerIndexLayerSource(LayerSource): | |||
566 | return self.apiurl + "../branch/" + branch.name + "/" + objectype + "/?q=" + str(upid) | 593 | return self.apiurl + "../branch/" + branch.name + "/" + objectype + "/?q=" + str(upid) |
567 | 594 | ||
568 | def update(self): | 595 | def update(self): |
569 | ''' | 596 | """ |
570 | Fetches layer, recipe and machine information from remote repository | 597 | Fetches layer, recipe and machine information from remote repository |
571 | ''' | 598 | """ |
572 | assert self.apiurl is not None | 599 | assert self.apiurl is not None |
573 | from django.db import IntegrityError | 600 | from django.db import IntegrityError |
574 | 601 | ||
@@ -601,7 +628,7 @@ class LayerIndexLayerSource(LayerSource): | |||
601 | return | 628 | return |
602 | 629 | ||
603 | # update branches; only those that we already have names listed in the Releases table | 630 | # update branches; only those that we already have names listed in the Releases table |
604 | whitelist_branch_names = map(lambda x: x.branch.name, Release.objects.all()) | 631 | whitelist_branch_names = map(lambda x: x.branch_name, Release.objects.all()) |
605 | 632 | ||
606 | branches_info = _get_json_response(apilinks['branches'] | 633 | branches_info = _get_json_response(apilinks['branches'] |
607 | + "?filter=name:%s" % "OR".join(whitelist_branch_names)) | 634 | + "?filter=name:%s" % "OR".join(whitelist_branch_names)) |
@@ -713,16 +740,31 @@ class BitbakeVersion(models.Model): | |||
713 | 740 | ||
714 | 741 | ||
715 | class Release(models.Model): | 742 | class Release(models.Model): |
743 | """ A release is a project template, used to pre-populate Project settings with a configuration set """ | ||
716 | name = models.CharField(max_length=32, unique = True) | 744 | name = models.CharField(max_length=32, unique = True) |
717 | description = models.CharField(max_length=255) | 745 | description = models.CharField(max_length=255) |
718 | bitbake_version = models.ForeignKey(BitbakeVersion) | 746 | bitbake_version = models.ForeignKey(BitbakeVersion) |
719 | branch = models.ForeignKey('Branch') | 747 | branch_name = models.CharField(max_length=50, default = "") |
720 | helptext = models.TextField(null=True) | 748 | helptext = models.TextField(null=True) |
721 | 749 | ||
750 | def __unicode__(self): | ||
751 | return "%s (%s)" % (self.name, self.branch_name) | ||
752 | |||
753 | class ReleaseLayerSourcePriority(models.Model): | ||
754 | """ Each release selects layers from the set up layer sources, ordered by priority """ | ||
755 | release = models.ForeignKey("Release") | ||
756 | layer_source = models.ForeignKey("LayerSource") | ||
757 | priority = models.IntegerField(default = 0) | ||
758 | |||
759 | def __unicode__(self): | ||
760 | return "%s-%s:%d" % (self.release.name, self.layer_source.name, self.priority) | ||
761 | class Meta: | ||
762 | unique_together = (('release', 'layer_source'),) | ||
763 | |||
722 | 764 | ||
723 | class ReleaseDefaultLayer(models.Model): | 765 | class ReleaseDefaultLayer(models.Model): |
724 | release = models.ForeignKey(Release) | 766 | release = models.ForeignKey(Release) |
725 | layer = models.ForeignKey('Layer') | 767 | layer_name = models.CharField(max_length=100, default="") |
726 | 768 | ||
727 | 769 | ||
728 | # Branch class is synced with layerindex.Branch, branches can only come from remote layer indexes | 770 | # Branch class is synced with layerindex.Branch, branches can only come from remote layer indexes |
@@ -760,7 +802,7 @@ class Layer(models.Model): | |||
760 | description = models.TextField(null = True, default = None) | 802 | description = models.TextField(null = True, default = None) |
761 | 803 | ||
762 | def __unicode__(self): | 804 | def __unicode__(self): |
763 | return "L " + self.name | 805 | return "%s / %s " % (self.name, self.layer_source) |
764 | 806 | ||
765 | class Meta: | 807 | class Meta: |
766 | unique_together = (("layer_source", "up_id"), ("layer_source", "name")) | 808 | unique_together = (("layer_source", "up_id"), ("layer_source", "name")) |
@@ -831,9 +873,21 @@ class Layer_Version(models.Model): | |||
831 | return None | 873 | return None |
832 | return self._handle_url_path(self.layer.vcs_web_tree_base_url, '') | 874 | return self._handle_url_path(self.layer.vcs_web_tree_base_url, '') |
833 | 875 | ||
876 | def get_equivalents_wpriority(self, project): | ||
877 | """ Returns an ordered layerversion list that satisfies a LayerVersionDependency using the layer name and the current Project Releases' LayerSource priority """ | ||
878 | def _get_ls_priority(ls): | ||
879 | try: | ||
880 | return ls.releaselayersourcepriority_set.get(release=project.release).priority | ||
881 | except ReleaseLayerSourcePriority.DoesNotExist: | ||
882 | raise | ||
883 | return sorted( | ||
884 | Layer_Version.objects.filter( layer__name = self.layer.name, up_branch__name = self.up_branch.name ), | ||
885 | key = lambda x: _get_ls_priority(x.layer_source), | ||
886 | reverse = False) | ||
887 | |||
834 | 888 | ||
835 | def __unicode__(self): | 889 | def __unicode__(self): |
836 | return "LV " + str(self.layer) + " " + self.commit | 890 | return str(self.layer) + " (" + self.commit +")" |
837 | 891 | ||
838 | class Meta: | 892 | class Meta: |
839 | unique_together = ("layer_source", "up_id") | 893 | unique_together = ("layer_source", "up_id") |
@@ -853,6 +907,9 @@ class ProjectLayer(models.Model): | |||
853 | layercommit = models.ForeignKey(Layer_Version, null=True) | 907 | layercommit = models.ForeignKey(Layer_Version, null=True) |
854 | optional = models.BooleanField(default = True) | 908 | optional = models.BooleanField(default = True) |
855 | 909 | ||
910 | def __unicode__(self): | ||
911 | return "%s, %s" % (self.project.name, self.layercommit) | ||
912 | |||
856 | class Meta: | 913 | class Meta: |
857 | unique_together = (("project", "layercommit"),) | 914 | unique_together = (("project", "layercommit"),) |
858 | 915 | ||