Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
Nuovo sito
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
16
Issues
16
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gruppo Web
Nuovo sito
Commits
483cbbba
Commit
483cbbba
authored
Oct 18, 2023
by
shadMod
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
replaced pkg_resources with os.path with quick code clenaup
Fixes:
https://code.ubuntu-it.org/ubuntu-it-web/www/-/issues/13
parent
4d70476e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
27 additions
and
34 deletions
+27
-34
uitwww/auth.py
uitwww/auth.py
+8
-9
uitwww/db.py
uitwww/db.py
+0
-3
uitwww/download.py
uitwww/download.py
+9
-10
uitwww/navbar.py
uitwww/navbar.py
+5
-5
uitwww/pages.py
uitwww/pages.py
+0
-3
uitwww/redirects.py
uitwww/redirects.py
+5
-4
No files found.
uitwww/auth.py
View file @
483cbbba
...
...
@@ -14,18 +14,16 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import
functools
import
time
import
uuid
import
yaml
import
flask
import
functools
import
flask_openid
import
pkg_resources
import
time
import
yaml
from
.constants
import
UITWWW_DIR
from
uitwww.third_party
import
openid_teams
SESSION_EXPIRES_AFTER
=
86400
...
...
@@ -148,8 +146,8 @@ class Sessions:
class
Permissions
:
def
__init__
(
self
):
raw
=
pkg_resources
.
resource_string
(
"uitwww"
,
"data/permissions.yml"
)
self
.
config
=
yaml
.
safe_load
(
raw
.
decode
(
"utf-8"
))
with
open
(
UITWWW_DIR
+
"/data/permissions.yml"
)
as
fn
:
self
.
config
=
yaml
.
safe_load
(
fn
.
read
(
))
def
allowed_teams
(
self
):
"""Return a list of teams allowed to log in"""
...
...
@@ -177,6 +175,7 @@ class Permissions:
def
permission
(
perms
):
"""Process the endpoint only if the user has permission"""
def
decorator
(
func
):
@
functools
.
wraps
(
func
)
def
wrapper
(
*
args
,
**
kwargs
):
...
...
@@ -200,6 +199,7 @@ def permission(perms):
return
flask
.
abort
(
403
)
return
wrapper
return
decorator
...
...
@@ -277,7 +277,6 @@ def prepare_blueprint(app):
flask
.
flash
(
"La sessione è stata terminata correttamente."
,
"success"
)
return
flask
.
redirect
(
flask
.
url_for
(
"pages.index"
))
@
bp
.
route
(
"/sessions"
)
@
permission
(
"auth.sessions.manage"
)
def
sessions_list
():
...
...
uitwww/db.py
View file @
483cbbba
...
...
@@ -17,9 +17,6 @@
import
threading
import
sqlite3
import
pkg_resources
_LOCAL
=
threading
.
local
()
...
...
uitwww/download.py
View file @
483cbbba
...
...
@@ -22,15 +22,14 @@ import random
import
collections
import
flask
import
itsdangerous
import
requests
import
pkg_resource
s
import
itsdangerou
s
from
.
import
cache
from
.
import
launchpad
from
.constants
import
UITWWW_DIR
CONFIG_FILE
=
"data/downloads.toml"
CONFIG_FILE
=
"/data/downloads.toml"
CACHE_FILE
=
"download-cache.json"
CACHE_FILE_VERSION
=
1
...
...
@@ -39,16 +38,16 @@ class Downloads:
def
__init__
(
self
,
data_path
):
# Load the configuration
raw
=
pkg_resources
.
resource_string
(
"uitwww"
,
CONFIG_FILE
)
self
.
config
=
toml
.
loads
(
raw
.
decode
(
"utf-8"
),
_dict
=
collections
.
OrderedDict
,
path
=
UITWWW_DIR
+
CONFIG_FILE
self
.
config
=
toml
.
load
(
path
,
_dict
=
collections
.
OrderedDict
,
)
self
.
_strip_non_lts_releases
()
# Save the hash of the configuration
self
.
_config_hash
=
"sha1=%s"
%
hashlib
.
sha1
(
raw
).
hexdigest
()
with
open
(
path
,
"rb"
)
as
raw
:
self
.
_config_hash
=
"sha1=%s"
%
hashlib
.
sha1
(
raw
.
read
()).
hexdigest
()
self
.
_cache_file
=
os
.
path
.
join
(
data_path
,
CACHE_FILE
)
...
...
@@ -69,7 +68,7 @@ class Downloads:
self
.
_mirrors
=
{}
for
distro
in
self
.
config
[
"mirrors"
][
"for"
]:
found_mirrors
=
list
(
sorted
(
launchpad
.
get_cdimage_mirrors
(
distro
,
self
.
config
[
"mirrors"
][
"country"
]
distro
,
self
.
config
[
"mirrors"
][
"country"
]
)))
if
found_mirrors
:
self
.
_mirrors
[
distro
]
=
found_mirrors
...
...
uitwww/navbar.py
View file @
483cbbba
...
...
@@ -14,10 +14,10 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import
flask
import
json
import
pkg_resources
import
yaml
import
flask
from
.constants
import
UITWWW_DIR
class
Navbar
:
...
...
@@ -55,8 +55,8 @@ class Navbar:
def
install
(
self
,
app
):
"""Install this navbar on the app"""
raw
=
pkg_resources
.
resource_string
(
"uitwww"
,
"data/navbar.yml"
)
config
=
yaml
.
load
(
raw
.
decode
(
"utf-8"
))
with
open
(
UITWWW_DIR
+
"/data/navbar.yml"
)
as
fn
:
config
=
yaml
.
safe_load
(
fn
.
read
(
))
self
.
_prepare_navbar_cache
(
config
,
[])
# Add the _navbars variable to the templates
...
...
uitwww/pages.py
View file @
483cbbba
...
...
@@ -15,10 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import
os
import
json
import
flask
import
pkg_resources
from
uitwww
import
cache
...
...
uitwww/redirects.py
View file @
483cbbba
...
...
@@ -14,16 +14,17 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import
flask
import
pkg_resources
import
yaml
import
flask
import
hashlib
from
.constants
import
UITWWW_DIR
def
prepare_blueprint
(
app
):
"""Prepare a blueprint containing all the redirects"""
raw
=
pkg_resources
.
resource_string
(
"uitwww"
,
"data/redirects.yml"
)
config
=
yaml
.
safe_load
(
raw
.
decode
(
"utf-8"
))
with
open
(
UITWWW_DIR
+
"/data/redirects.yml"
)
as
fn
:
config
=
yaml
.
safe_load
(
fn
.
read
(
))
bp
=
flask
.
Blueprint
(
"redirects"
,
__name__
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment