[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#761149: debsources: allow redirects to package versions based on suite/codename



Hello again,

I have worked a bit more on this (see attached patch) :

 * There's a new column in suites_info: alias. (For example, in the
suite 'sid', alias will be 'unstable')
 * The database schema in doc/ has been updated to reflect the above
 * unstable/testing/stable/oldstable redirects now work (assuming the
alias column is set correctly for each suite)
 * I have added unit tests for both suite redirects (/sid) and alias
redirects (/unstable)

After our discussion this morning on #debian-qa, I thought it'd be a
good idea to include the suites alias in the database directly :

 * It allows other distributions to easily manage them
 * On our side, we'll simply need to update this table in each update
run (calling an external API for example to get the update suites).

   There's no code in this patch to update the table, I think we were
waiting for the API to be finalized?

I'll submit a proper git commit patch once we have ironed out issues :)

Note: The data in testdata/ git submodule must be updated (make
distclean dump) or else the unit tests will fail because of a missing
column.

Thanks

-- 
Jason Pleau
diff --git a/debsources/app/views.py b/debsources/app/views.py
index 565b17a..3cbafc0 100644
--- a/debsources/app/views.py
+++ b/debsources/app/views.py
@@ -37,7 +37,7 @@ from debsources.excepts import (
     Http500Error, Http404Error, Http404ErrorSuggestions, Http403Error)
 from debsources.models import (
     Ctag, Package, PackageName, Checksum, Location, Directory,
-    SourceFile, File)
+    SourceFile, File, SuiteInfo)
 from debsources.app.sourcecode import SourceCodeIterator
 from debsources.app.forms import SearchForm
 from debsources.app.infobox import Infobox
@@ -572,6 +572,20 @@ class SourceView(GeneralView):
             if version == "latest":  # we search the latest available version
                 return self._handle_latest_version(package, path)
             else:
+                suites_info = session.query(SuiteInfo).all()
+                suites_aliases = { s.alias: s.name for s in suites_info }
+                try:
+                    versions_w_suites = PackageName.list_versions_w_suites(
+                        session, package)
+                except InvalidPackageOrVersionError:
+                    raise Http404Error("%s not found" % package)
+                for version_suite in versions_w_suites:
+                    if version in suites_aliases:
+                        version = suites_aliases[version]
+                    if version in version_suite['suites']:
+                        return self._render_location(
+                            package, version_suite['version'], path)
+
                 return self._render_location(package, version, path)
 
 
diff --git a/debsources/models.py b/debsources/models.py
index 45647af..78f32ad 100644
--- a/debsources/models.py
+++ b/debsources/models.py
@@ -42,8 +42,8 @@ from debsources.consts import SUITES
 Base = declarative_base()
 
 
-# used for migrations, see scripts under python/migrate/
-DB_SCHEMA_VERSION = 7
+# used for migrations, see scripts under debsources/migrate/
+DB_SCHEMA_VERSION = 8
 
 
 class PackageName(Base):
@@ -163,24 +163,6 @@ class Package(Base):
 Index('ix_packages_name_id_version', Package.name_id, Package.version)
 
 
-class Suite(Base):
-    """
-    Debian suites (squeeze, wheezy, etc) mapping with source package versions
-    """
-    __tablename__ = 'suites'
-    __table_args__ = (UniqueConstraint('package_id', 'suite'),)
-
-    id = Column(Integer, primary_key=True)
-    package_id = Column(Integer,
-                        ForeignKey('packages.id', ondelete="CASCADE"),
-                        index=True, nullable=False)
-    suite = Column(String, index=True)
-
-    def __init__(self, package, suite):
-        self.package_id = package.id
-        self.suite = suite
-
-
 class SuiteInfo(Base):
     """static information about known suites
 
@@ -194,14 +176,38 @@ class SuiteInfo(Base):
     version = Column(String, nullable=True)
     release_date = Column(Date, nullable=True)
     sticky = Column(Boolean, nullable=False)
+    alias = Column(String, nullable=True)
 
-    def __init__(self, name, sticky=False, version=None, release_date=None):
+    def __init__(self, name, sticky=False, version=None, release_date=None,
+                 alias=None):
         self.name = name
         if version:
             self.version = version
         if release_date:
             self.release_date = release_date
         self.sticky = sticky
+        self.alias = alias
+
+
+class Suite(Base):
+    """
+    Debian suites (squeeze, wheezy, etc) mapping with source package versions
+    """
+    __tablename__ = 'suites'
+    __table_args__ = (UniqueConstraint('package_id', 'suite'),)
+
+    id = Column(Integer, primary_key=True)
+    package_id = Column(Integer,
+                        ForeignKey('packages.id', ondelete="CASCADE"),
+                        index=True, nullable=False)
+    suite = Column(String, index=True)
+
+    suite = Column(String, ForeignKey(SuiteInfo.name), index=True)
+    suite_info = relationship("SuiteInfo", backref="suite_info")
+
+    def __init__(self, package, suite):
+        self.package_id = package.id
+        self.suite = suite
 
 
 class File(Base):
diff --git a/debsources/tests/test_webapp.py b/debsources/tests/test_webapp.py
index 5b9da1d..c41437d 100644
--- a/debsources/tests/test_webapp.py
+++ b/debsources/tests/test_webapp.py
@@ -186,6 +186,16 @@ class DebsourcesTestCase(unittest.TestCase, DbTestFixture):
                                      follow_redirects=True).data)
         self.assertIn("2.03-2", rv['path'])
 
+    def test_suite_folder(self):
+        rv = json.loads(self.app.get('/api/src/ledit/sid/',
+                                    follow_redirects=True).data)
+        self.assertIn("2.03-2", rv['path'])
+
+    def test_suite_folder_alias(self):
+        rv = json.loads(self.app.get('/api/src/ledit/unstable/',
+                                    follow_redirects=True).data)
+        self.assertIn("2.03-2", rv['path'])
+
     def test_codesearch_box(self):
         rv = self.app.get('/src/ledit/2.03-2/ledit.ml/')
         self.assertIn('value="package:ledit "', rv.data)
diff --git a/doc/db-schema/debsources.dia b/doc/db-schema/debsources.dia
index 5487cb0..960f76e 100644
--- a/doc/db-schema/debsources.dia
+++ b/doc/db-schema/debsources.dia
@@ -3344,6 +3344,29 @@
           </dia:attribute>
         </dia:composite>
 
+        <dia:composite type="umlattribute">
+          <dia:attribute name="name">
+            <dia:string>#  alias#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="type">
+            <dia:string>#character varying#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="value">
+
+            <dia:string/>
+
+          </dia:attribute>
+          <dia:attribute name="visibility">
+            <dia:enum val="3"/>
+          </dia:attribute>
+          <dia:attribute name="abstract">
+            <dia:boolean val="false"/>
+          </dia:attribute>
+          <dia:attribute name="class_scope">
+            <dia:boolean val="false"/>
+          </dia:attribute>
+        </dia:composite>
+
       </dia:attribute>
 
       <dia:attribute name="visible_operations">
diff --git a/doc/db-schema/debsources.dot b/doc/db-schema/debsources.dot
index 43aac6c..3129a48 100644
--- a/doc/db-schema/debsources.dot
+++ b/doc/db-schema/debsources.dot
@@ -35,7 +35,7 @@ edge [
 
 "suites" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > id </TD><TD align="left" > serial </TD><TD align="left" > PK </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > package_id </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" > FK </TD><TD align="left" PORT="rtcol2"> </TD></TR> <TR><TD PORT="ltcol3" ></TD><TD align="left" > suite </TD><TD align="left" > character varying </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol3"> </TD></TR> </TABLE>> ];
 
-"suites_info" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > name </TD><TD align="left" > character varying </TD><TD align="left" > PK </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > version </TD><TD align="left" > character varying </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol2"> </TD></TR> <TR><TD PORT="ltcol3" ></TD><TD align="left" > release_date </TD><TD align="left" > date </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol3"> </TD></TR> <TR><TD PORT="ltcol4" ></TD><TD align="left" > sticky </TD><TD align="left" > boolean </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol4"> </TD></TR> </TABLE>> ];
+"suites_info" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > name </TD><TD align="left" > character varying </TD><TD align="left" > PK </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > version </TD><TD align="left" > character varying </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol2"> </TD></TR> <TR><TD PORT="ltcol3" ></TD><TD align="left" > release_date </TD><TD align="left" > date </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol3"> </TD></TR> <TR><TD PORT="ltcol4" ></TD><TD align="left" > sticky </TD><TD align="left" > boolean </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol4"> </TD></TR> <TR><TD PORT="ltcol5" ></TD><TD align="left" > alias </TD><TD align="left" > character varying </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol5"> </TD></TR> </TABLE>> ];
 
 
 
diff --git a/doc/db-schema/debsources.html b/doc/db-schema/debsources.html
index 79ba33e..e3f926b 100644
--- a/doc/db-schema/debsources.html
+++ b/doc/db-schema/debsources.html
@@ -112,7 +112,7 @@
   <body>
 
     <!-- Primary Index -->
-	<p><br><br>Dumped on 2014-03-11</p>
+	<p><br><br>Dumped on 2014-11-09</p>
 <h1><a name="index">Index of database - debsources</a></h1>
 <ul>
     
@@ -2449,6 +2449,22 @@
 				</td>
 			 </tr>
             
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>alias</td>
+            	<td>character varying</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
         </table>
 
         <!-- Inherits -->
diff --git a/doc/db-schema/debsources.neato b/doc/db-schema/debsources.neato
index a8fdb60..bfb9cb8 100644
--- a/doc/db-schema/debsources.neato
+++ b/doc/db-schema/debsources.neato
@@ -26,7 +26,7 @@ edge [];
 
 "suites" [shape = record, label = "{<col0> \N| id:  serial\lpackage_id:  integer\lsuite:  character varying\l}" ];
 
-"suites_info" [shape = record, label = "{<col0> \N| name:  character varying\lversion:  character varying\lrelease_date:  date\lsticky:  boolean\l}" ];
+"suites_info" [shape = record, label = "{<col0> \N| name:  character varying\lversion:  character varying\lrelease_date:  date\lsticky:  boolean\lalias:  character varying\l}" ];
 
 
 "binaries" -> "binary_names" [label="binaries_name_id_fkey"];
diff --git a/doc/db-schema/debsources.xml b/doc/db-schema/debsources.xml
index 538f9ca..b0c428f 100644
--- a/doc/db-schema/debsources.xml
+++ b/doc/db-schema/debsources.xml
@@ -2458,6 +2458,22 @@
             </listitem>
           </varlistentry>
 
+            <varlistentry>
+              <term><structfield>alias</structfield></term>
+              <listitem><para>
+                <type>character varying</type>
+
+
+
+
+
+
+
+              </para>
+
+            </listitem>
+          </varlistentry>
+
         </variablelist>
 
 
diff --git a/doc/db-schema/debsources.zigzag.dia b/doc/db-schema/debsources.zigzag.dia
index cd626cb..0717245 100644
--- a/doc/db-schema/debsources.zigzag.dia
+++ b/doc/db-schema/debsources.zigzag.dia
@@ -3344,6 +3344,29 @@
           </dia:attribute>
         </dia:composite>
 
+        <dia:composite type="umlattribute">
+          <dia:attribute name="name">
+            <dia:string>#  alias#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="type">
+            <dia:string>#character varying#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="value">
+
+            <dia:string/>
+
+          </dia:attribute>
+          <dia:attribute name="visibility">
+            <dia:enum val="3"/>
+          </dia:attribute>
+          <dia:attribute name="abstract">
+            <dia:boolean val="false"/>
+          </dia:attribute>
+          <dia:attribute name="class_scope">
+            <dia:boolean val="false"/>
+          </dia:attribute>
+        </dia:composite>
+
       </dia:attribute>
 
       <dia:attribute name="visible_operations">
diff --git a/testdata b/testdata
--- a/testdata
+++ b/testdata
@@ -1 +1 @@
-Subproject commit d79b3acbf332a92d60e4a7e0ff68c70e71e2b6a1
+Subproject commit d79b3acbf332a92d60e4a7e0ff68c70e71e2b6a1-dirty

Reply to: