]> git.ipfire.org Git - pbs.git/commitdiff
packages: Refactor filelist
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 17 Jul 2022 09:20:58 +0000 (09:20 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 17 Jul 2022 09:20:58 +0000 (09:20 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/misc.py
src/buildservice/packages.py
src/templates/modules/packages-files-table.html
src/templates/packages/view-file.html
src/web/base.py

index 0db857c674b058c9e60c1a65afe405e008d87d7a..5c331b580a3567108359985397c958d41befafe1 100644 (file)
@@ -5,7 +5,6 @@ import os
 import random
 import re
 import string
-import tarfile
 import unicodedata
 
 from .constants import *
@@ -85,16 +84,6 @@ def friendly_time(t):
 
        return " ".join(ret)
 
-def format_filemode(filetype, filemode):
-       if filetype == 2:
-               prefix = "l"
-       elif filetype == 5:
-               prefix = "d"
-       else:
-               prefix = "-"
-
-       return prefix + "TODO" # XXX tarfile.filemode(filemode)[1:]
-
 def calc_hash(filename, algo="sha512"):
        assert algo in hashlib.algorithms
 
index 0986f238f4f1ab9ff2f2d842254a676a725202c5..bdb7868d34f635d248aae4480db7d2817e9ec1a5 100644 (file)
@@ -6,6 +6,7 @@ import logging
 import mimetypes
 import os
 import shutil
+import stat
 
 import pakfire
 from pakfire.constants import (
@@ -507,7 +508,7 @@ class File(base.Object):
                self.data = data
 
        @property
-       def name(self):
+       def path(self):
                return self.data.path
 
        @property
@@ -516,7 +517,7 @@ class File(base.Object):
 
        @property
        def type(self):
-               return self.data.type
+               return stat.S_IFMT(self.mode)
 
        @property
        def config(self):
@@ -563,7 +564,7 @@ class File(base.Object):
                        Returns True if this file is downloadable
                """
                # All regular files are downloadable
-               return self.type == 0
+               return self.type == stat.S_IFREG
 
        def is_viewable(self):
                # Empty files cannot be viewed.
@@ -571,7 +572,7 @@ class File(base.Object):
                        return False
 
                for ext in FILE_EXTENSIONS_VIEWABLE:
-                       if self.name.endswith(ext):
+                       if self.path.endswith(ext):
                                return True
 
                return False
@@ -582,7 +583,7 @@ class File(base.Object):
                        The (guessed) MIME type of this file
                """
                # Guess the MIME type of the file.
-               type, encoding = mimetypes.guess_type(self.name)
+               type, encoding = mimetypes.guess_type(self.path)
 
                return type or "application/octet-stream"
 
@@ -596,7 +597,7 @@ class File(base.Object):
                p = await self.package.open()
 
                # Create a helper function to read the entire payload
-               func = lambda: p.read(self.name)
+               func = lambda: p.read(self.path)
 
                # Read the payload in a separate thread
                return await asyncio.to_thread(func)
index 73a8d42fe95373d6b6cc748fa81f6f046e44881c..8b3c10258c2926333efd5b9259ee0f0a73638437 100644 (file)
@@ -1,40 +1,37 @@
-<div class="table-responsive mb-2">
-       <table class="table table-striped table-hover">
-               <tbody>
-                       {% for file in filelist %}
-                               <tr>
-                                       <td>
-                                               {{ format_filemode(file.type, file.mode) }}
-                                       </td>
-                                       <td>
-                                               {{ file.user }}:{{ file.group }}
-                                       </td>
-                                       <td>
-                                               {% if file.size is None %}
-                                                       -
-                                               {% else %}
-                                                       {{ format_size(file.size) }}
-                                               {% end %}
-                                       </td>
-                                       <td>
-                                               {{ file.name }}
-                                       </td>
-                                       <td>
+{% import stat %}
+
+<table class="hover stacked">
+       <tbody>
+               {% for file in filelist %}
+                       <tr>
+                               <td>
+                                       {% set mode  = stat.filemode(file.mode) %}
+                                       {% set owner = "%6s:%-6s" % (file.user, file.group) %}
+                                       {% set size  = "%6s" % ("-" if file.size is None else format_size(file.size)) %}
+
+                                       <pre>{{ mode }} {{ owner }} {{ size }} {{ file.path }}</pre>
+                               </td>
+
+                               <td>
+                                       <ul class="simple menu align-right">
                                                {% if file.is_viewable() %}
-                                                       <a class="btn btn-light" href="/package/{{ pkg.uuid }}/view{{ file.name }}">
-                                                               <i class="icon-file"></i>{{ _("View file") }}
-                                                       </a>
+                                                       <li>
+                                                               <a class="btn btn-light" href="/package/{{ pkg.uuid }}/view{{ file.path }}">
+                                                                       <i class="fa-solid fa-magnifying-glass" title="{{ _("View File") }}"></i>
+                                                               </a>
+                                                       </li>
+                                               {% end %}
+
+                                               {% if file.is_downloadable() %}
+                                                       <li>
+                                                               <a href="/package/{{ pkg.uuid }}/download{{ file.path }}">
+                                                                       <i class="fa-solid fa-download" title="{{ _("Download" ) }}"></i>
+                                                               </a>
+                                                       </li>
                                                {% end %}
-                                       </td>
-                                       <td>
-                                       {% if file.is_downloadable() %}
-                                               <a class="btn btn-light" href="/package/{{ pkg.uuid }}/download{{ file.name }}">
-                                                       <i class="icon-download"></i>{{ _("Download") }}
-                                               </a>
-                                       {% end %}
-                                       </td>
-                               </tr>
-                       {% end %}
-               </tbody>
-       </table>
-</div>
+                                       </ul>
+                               </td>
+                       </tr>
+               {% end %}
+       </tbody>
+</table>
index 831b4d48ba2b7b5fa59ef1db8df70ec736ed683a..ff1077fd03f011ef7d1dcdfd3b925f0722d12001 100644 (file)
                                <a href="/packages/{{ package.uuid }}">{{ package }}</a>
                        </li>
                        <li>
-                               <span class="show-for-sr">{{ _("Current") }}: </span> {{ file.name }}
+                               <span class="show-for-sr">{{ _("Current") }}: </span> {{ file.path }}
                        </li>
                </ul>
        </nav>
 
        {% module Highlight(payload) %}
 
-       <a class="expanded primary button" href="/package/{{ package.uuid }}/download{{ file.name }}">
+       <a class="expanded primary button" href="/package/{{ package.uuid }}/download{{ file.path }}">
                {{ _("Download (%s)") % format_size(file.size) }}
        </a>
 {% end block %}
index 91fd7f5500a87f145ed212220757ca186bf2fe55..5b84eeddea4b8e3de3d487a2da45748393854482 100644 (file)
@@ -79,7 +79,6 @@ class BaseHandler(tornado.web.RequestHandler):
                        "format_date"     : self.format_date,
                        "format_size"     : misc.format_size,
                        "friendly_time"   : misc.friendly_time,
-                       "format_filemode" : misc.format_filemode,
                        "lang"            : self.locale.code[:2],
                        "session"         : self.session,
                        "version"         : __version__,