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

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



Updated patch

I made a proper git patch, so that the new file would be displayed. Also
cleaned up the models.py file, I had some leftover from previous strategies.

It's still required to regenerate the data in testdata (make distclean
dump) to account for the new column

Thanks

-- 
Jason Pleau
From fd6ff45605f17c9e91664e3bf160f23ed1515597 Mon Sep 17 00:00:00 2001
From: Jason Pleau <jason@jpleau.ca>
Date: Tue, 11 Nov 2014 06:52:38 -0500
Subject: [PATCH] allow redirects to package versions based on suite/codename

Like the /latest redirect, we now check for suite names to redirect to
a specific version. If package foo has version 1.5-1 in sid, going to
/src/foo/sid will display as if we went to /src/foo/1.5-1.

When going to /src/foo/sid for example, It iterates through the package's suite,
and if it finds what's provided in the url, it redirects the request (in the
application) to the proper version.

This commit also adds an 'alias' column to the suites_info table. This allows
us to add 'unstable' to 'sid', 'testing' to 'jessie' and so on. We'll be able
to update this column in an update script, and it will be easy for other
distributions using debsources to manage their suites aliases.

When going to /src/foo/unstable, if it detects that 'unstable' matches
'sid', it will change the version to 'sid', and will use the same logic
as described above to redirect to the right version.
---
 debsources/app/views.py             | 16 +++++++++++++++-
 debsources/migrate/007-to-008.sql   | 14 ++++++++++++++
 debsources/models.py                | 10 ++++++----
 debsources/tests/test_webapp.py     | 10 ++++++++++
 doc/db-schema/debsources.dia        | 23 +++++++++++++++++++++++
 doc/db-schema/debsources.dot        |  2 +-
 doc/db-schema/debsources.html       | 18 +++++++++++++++++-
 doc/db-schema/debsources.neato      |  2 +-
 doc/db-schema/debsources.xml        | 16 ++++++++++++++++
 doc/db-schema/debsources.zigzag.dia | 23 +++++++++++++++++++++++
 10 files changed, 126 insertions(+), 8 deletions(-)
 create mode 100644 debsources/migrate/007-to-008.sql

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/migrate/007-to-008.sql b/debsources/migrate/007-to-008.sql
new file mode 100644
index 0000000..838346e
--- /dev/null
+++ b/debsources/migrate/007-to-008.sql
@@ -0,0 +1,14 @@
+ALTER TABLE suites_info
+  ADD COLUMN alias VARCHAR;
+
+UPDATE suites_info
+  SET alias='unstable' WHERE name='sid';
+
+UPDATE suites_info
+  SET alias='testing' WHERE name='jessie';
+
+UPDATE suites_info
+  SET alias='stable' WHERE name='wheezy';
+
+UPDATE suites_info
+  SET alias='oldstable' WHERE name='squeeze';
diff --git a/debsources/models.py b/debsources/models.py
index 45647af..86b6648 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):
@@ -194,15 +194,17 @@ 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 File(Base):
     """source file table"""
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">
-- 
2.1.3


Reply to: