import random
import re
import string
-import tarfile
import unicodedata
from .constants import *
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
import mimetypes
import os
import shutil
+import stat
import pakfire
from pakfire.constants import (
self.data = data
@property
- def name(self):
+ def path(self):
return self.data.path
@property
@property
def type(self):
- return self.data.type
+ return stat.S_IFMT(self.mode)
@property
def config(self):
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.
return False
for ext in FILE_EXTENSIONS_VIEWABLE:
- if self.name.endswith(ext):
+ if self.path.endswith(ext):
return True
return False
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"
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)
-<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>
<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 %}
"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__,