Skip to content

Commit

Permalink
Merge pull request #39 from VitaliyaIoffe/VitaliyaIoffe/fix_flake8
Browse files Browse the repository at this point in the history
Flake8 improvements
  • Loading branch information
knazarov authored Jan 16, 2022
2 parents e6cd31a + 4433b1c commit 127311a
Show file tree
Hide file tree
Showing 15 changed files with 131 additions and 59 deletions.
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 100
max-doc-length = 100
22 changes: 22 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: flake8

on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements-test.txt ]; then pip install -r requirements-test.txt; fi
- name: Make lint
run: |
make lint
2 changes: 2 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[settings]
force_single_line=True
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
index.html : README.md static/skeleton.css static/box.svg static/template.html
pandoc -s README.md -o index.html -c static/skeleton.css --template static/template.html -T mkrepo

.PHONY: lint
lint: flake8 isort

.PHONY: flake8
flake8:
flake8 .

.PHONY: isort
isort:
isort . -c

test :
PYTHONPATH=$(PWD)/test python -m unittest discover -v

Expand Down
39 changes: 21 additions & 18 deletions debrepo.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#!/usr/bin/env python

import bz2
import collections
import mimetypes
import datetime
import email
import gzip
import bz2
import subprocess
import re
import hashlib
import mimetypes
import os
import re
import subprocess
import sys
import tempfile
from io import BytesIO
import hashlib
import time
import datetime
import email
import sys
from io import BytesIO


def file_checksum(file_name, checksum_type):
h = hashlib.new(checksum_type)
Expand Down Expand Up @@ -139,7 +140,7 @@ def __eq__(self, other):
other.fields['Version']))

def __ne__(self, other):
return not(self == other)
return not (self == other)


class Package(IndexUnit):
Expand Down Expand Up @@ -471,8 +472,11 @@ def split_control_file_path(path, ctrl_type):
# The package management system will break the version number apart at the last hyphen
# in the string (if there is one) to determine the upstream_version and debian_revision.
# The absence of a debian_revision is equivalent to a debian_revision of 0.
expr2 = r'^(?P<package_name>[a-z0-9][-a-z0-9.+]+)_(?P<upstream_version>[a-zA-Z0-9.+:~]+)'\
r'_(?P<arch>[^\.]+)\.deb$'
expr2 = (
r'^(?P<package_name>[a-z0-9][-a-z0-9.+]+)_'
r'(?P<upstream_version>[a-zA-Z0-9.+:~]+)_'
r'(?P<arch>[^\.]+)\.deb$'
)
match_package = re.match(expr2, os.path.basename(path))

if not match_package:
Expand Down Expand Up @@ -526,7 +530,7 @@ def process_index_file(repo_info, path, dist, component, arch, index_type):
elif index_type == 'sources':
index = SourceIndex()
else:
raise(RuntimeError('Unknown index type: ' + index_type))
raise RuntimeError('Unknown index type: ' + index_type)

index.parse_string(repo_info.storage.read_file(path).decode('utf-8'))
if index_type == 'packages':
Expand Down Expand Up @@ -641,7 +645,7 @@ def process_index_units(repo_info, tempdir, index_type, force=False):
expr = r'^.*\.dsc$'
tmp_filename = 'source.dsc'
else:
raise(RuntimeError('Unknown index type: ' + index_type))
raise RuntimeError('Unknown index type: ' + index_type)

mtimes = get_mtimes(index_list)
tmpdir = tempfile.mkdtemp('', 'tmp', tempdir)
Expand Down Expand Up @@ -736,7 +740,7 @@ def update_index_files(repo_info, index_type):
index_filename = 'Sources'
index_list = repo_info.source_index_list
else:
raise(RuntimeError('Unknown index type: ' + index_type))
raise RuntimeError('Unknown index type: ' + index_type)

for key in index_list:
dist, component, arch = key
Expand Down Expand Up @@ -806,8 +810,7 @@ def update_release_files(repo_info, sign):
release['Date'] = creation_date
release['Architectures'] = ' '.join(repo_info.architectures[dist])
release['Components'] = ' '.join(repo_info.components[dist])
release['Description'] = os.getenv('MKREPO_DEB_DESCRIPTION')\
or 'Repo generator'
release['Description'] = os.getenv('MKREPO_DEB_DESCRIPTION') or 'Repo generator'

checksum_lines = collections.defaultdict(list)
checksum_names = {'md5': 'MD5Sum', 'sha1': 'SHA1', 'sha256': 'SHA256'}
Expand All @@ -826,7 +829,7 @@ def update_release_files(repo_info, sign):

release_str = release.dump_string()
repo_info.storage.write_file('dists/%s/Release' % dist,
release_str.encode('utf-8'))
release_str.encode('utf-8'))

if sign:
sign_release_file(repo_info.storage, release_str, dist)
Expand Down
3 changes: 2 additions & 1 deletion mkrepo
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python

import mkrepo
mkrepo.main()

mkrepo.main()
5 changes: 3 additions & 2 deletions mkrepo.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python

import argparse
import storage
import os

import debrepo
import rpmrepo
import os
import storage


def is_deb_repo(stor):
Expand Down
2 changes: 2 additions & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
flake8>=3.7.9
isort>=5.9.3
57 changes: 32 additions & 25 deletions rpmrepo.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
#!/usr/bin/env python

import datetime
import gzip
import hashlib
import os
import sys
import re

import shutil
import subprocess
import sys
import tempfile
import shutil
import storage
import gzip
from io import BytesIO
import rpmfile
import hashlib
import json
import itertools

import datetime
import time

from io import BytesIO
from xml.sax.saxutils import escape

import rpmfile
import storage

try:
import xml.etree.cElementTree as ET
except ImportError:
Expand Down Expand Up @@ -98,13 +94,16 @@ def gpg_sign_string(data, keyname=None, inline=False):


def sign_metadata(repomdfile):
"""Requires a proper ~/.rpmmacros file. See <http://fedoranews.org/tchung/gpg/>"""
"""Requires a proper ~/.rpmmacros file.
See <http://fedoranews.org/tchung/gpg/>
"""
cmd = ["gpg", "--detach-sign", "--armor", "--digest-algo SHA256", repomdfile]
try:
subprocess.check_call(cmd)
print ("Successfully signed repository metadata file")
except subprocess.CalledProcessError as e:
print ("Unable to sign repository metadata '%s'" % (repomdfile))
print("Successfully signed repository metadata file")
except subprocess.CalledProcessError:
print("Unable to sign repository metadata '%s'" % repomdfile)
exit(1)


Expand Down Expand Up @@ -439,8 +438,11 @@ def dump_primary(primary):
res = ""

res += '<?xml version="1.0" encoding="UTF-8"?>\n'
res += '<metadata xmlns="http://linux.duke.edu/metadata/common" xmlns:rpm="http://linux.duke.edu/metadata/rpm" packages="%d">\n' % len(
primary)
res += (
'<metadata xmlns="http://linux.duke.edu/metadata/common" '
'xmlns:rpm="http://linux.duke.edu/metadata/rpm" '
'packages="%d">\n' % len(primary)
)

for package in primary.values():
res += '<package type="rpm">\n'
Expand All @@ -453,8 +455,8 @@ def dump_primary(primary):
for c in ['epoch', 'ver', 'rel'] if ver[c]])
res += '%s/>\n' % components

res += ' <checksum type="sha256" pkgid="YES">%s</checksum>\n' % \
package['checksum']
res += ' <checksum type="sha256" pkgid="YES">%s</checksum>\n' % (
package['checksum'])

res += ' <summary>%s</summary>\n' % escape(package['summary'] or '')
res += ' <description>%s</description>\n' % escape(
Expand Down Expand Up @@ -546,7 +548,7 @@ def parse_ver_str(ver_str):
epoch = match.group(1)[:-1] if match.group(1) else "0"
ver = match.group(2)
rel = match.group(3)[1:] if match.group(3) else None
return (epoch, ver, rel)
return epoch, ver, rel


def header_to_other(header, sha256):
Expand Down Expand Up @@ -897,13 +899,17 @@ def generate_repomd(filelists_str, filelists_gz,
res = ""

res += '<?xml version="1.0" encoding="UTF-8"?>\n'
res += '<repomd xmlns="http://linux.duke.edu/metadata/repo" xmlns:rpm="http://linux.duke.edu/metadata/rpm">\n'
res += (
'<repomd xmlns="http://linux.duke.edu/metadata/repo" '
'xmlns:rpm="http://linux.duke.edu/metadata/rpm">\n'
)

res += ' <revision>%s</revision>\n' % revision

res += ' <data type="filelists">\n'
res += ' <checksum type="sha256">%s</checksum>\n' % filelists_gz_sha256
res += ' <open-checksum type="sha256">%s</open-checksum>\n' % filelists_str_sha256
res += ' <open-checksum type="sha256">%s</open-checksum>\n' % (
filelists_str_sha256)
res += ' <location href="%s"/>\n' % filelists_name
res += ' <timestamp>%s</timestamp>\n' % int(nowtimestamp)
res += ' <size>%s</size>\n' % len(filelists_gz)
Expand All @@ -912,7 +918,8 @@ def generate_repomd(filelists_str, filelists_gz,

res += ' <data type="primary">\n'
res += ' <checksum type="sha256">%s</checksum>\n' % primary_gz_sha256
res += ' <open-checksum type="sha256">%s</open-checksum>\n' % primary_str_sha256
res += ' <open-checksum type="sha256">%s</open-checksum>\n' % (
primary_str_sha256)
res += ' <location href="%s"/>\n' % primary_name
res += ' <timestamp>%s</timestamp>\n' % int(nowtimestamp)
res += ' <size>%s</size>\n' % len(primary_gz)
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
from distutils.core import setup

setup(
name='mkrepo',
packages=[''],
Expand Down
7 changes: 4 additions & 3 deletions storage.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/usr/bin/env python

import os
import errno
import os
import shutil
import time
import urllib
import boto3
from io import BytesIO
import time

import boto3


class Storage:
Expand Down
2 changes: 1 addition & 1 deletion test/dummy_storage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from io import BytesIO
import time
from io import BytesIO

from storage import Storage

Expand Down
2 changes: 1 addition & 1 deletion test/test_debrepo.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env python3

import os
import sys
import unittest

import debrepo


class TestVersionParsing(unittest.TestCase):
def test_versions(self):
versions = [
Expand Down
3 changes: 1 addition & 2 deletions test/test_dummy_storage.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import os
import sys
import unittest

from dummy_storage import DummyStorage


class TestDummyStorage(unittest.TestCase):
def test_base_functionality(self):
"""Tests the basic functionality of DummyStorage."""
Expand Down
Loading

0 comments on commit 127311a

Please sign in to comment.