Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: ci

on:
push:
paths-ignore:
- '**.rst'
- LICENSE
pull_request:
types: [assigned, edited, opened, synchronize, reopened]

jobs:
build-checks:
runs-on: ubuntu-latest
container: 'alpine:3.20'

steps:
- uses: actions/checkout@v2

- id: install_deps
run: |
apk update
apk add python3 black make py3-coverage py3-pip

- id: linter
run: |
black --check --diff --color mupub/

- id: tests
run: |
pip3 install --break-system-packages -r requirements.txt
make dist
pip3 install --break-system-packages dist/mupub-1.0.8-py2.py3-none-any.whl
cd mupub
python -m unittest -v

- id: coverage
run: |
make coverage
26 changes: 15 additions & 11 deletions mupub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
"""

__all__ = (
'__title__', '__summary__', '__version__',
'__author__', '__license__', '__copyright__',
"__title__",
"__summary__",
"__version__",
"__author__",
"__license__",
"__copyright__",
)


__title__ = 'mupub'
__summary__ = 'Musical score publishing utility for the Mutopia Project'
__title__ = "mupub"
__summary__ = "Musical score publishing utility for the Mutopia Project"

"""Versioning:
This utility follows a MAJOR . MINOR . EDIT format. Upon a major
Expand All @@ -17,14 +21,14 @@
incremented.

"""
__version__ = '1.0.8'
__version__ = "1.0.8"

__author__ = 'Glen Larsen, Chris Sawer'
__author_email__= 'glenl.glx@gmail.com'
__uri__ = 'http://mutopiaproject.org/'
__author__ = "Glen Larsen, Chris Sawer"
__author_email__ = "glenl.glx@gmail.com"
__uri__ = "http://mutopiaproject.org/"

__license__ = 'MIT'
__copyright__ = 'Copyright 2018 The Mutopia Project'
__license__ = "MIT"
__copyright__ = "Copyright 2018 The Mutopia Project"

from .assets import collect_assets
from .commands.build import build
Expand All @@ -44,4 +48,4 @@
from .validate import Validator, DBValidator, in_repository
from .tagedit import tag_header, tag_file
from .rdfu import NS, MuRDF
from .utils import resolve_input,resolve_lysfile
from .utils import resolve_input, resolve_lysfile
2 changes: 1 addition & 1 deletion mupub/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ def main():
return dispatch(sys.argv[1:])


if __name__ == '__main__':
if __name__ == "__main__":
sys.exit(main())
69 changes: 35 additions & 34 deletions mupub/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

"""

__docformat__ = 'reStructuredText'
__docformat__ = "reStructuredText"


import glob
Expand All @@ -24,40 +24,41 @@
import zipfile
import mupub


def _collect_lyfile(basefnm):
dir_name = basefnm + '-lys'
dir_name = basefnm + "-lys"
if os.path.exists(dir_name):
zip_name = dir_name+'.zip'
with zipfile.ZipFile(zip_name, 'w') as lyzip:
zip_name = dir_name + ".zip"
with zipfile.ZipFile(zip_name, "w") as lyzip:
zip_list = mupub.utils.find_files(dir_name)
for zip_entry in zip_list:
lyzip.write(zip_entry)
return zip_name
else:
return basefnm + '.ly'
return basefnm + ".ly"


def _zip_maybe(basefnm, tail, ziptail):
files = glob.glob('*'+tail)
files = glob.glob("*" + tail)
if len(files) < 1:
return 'empty'
return "empty"
if len(files) == 1:
single_file = basefnm+tail
single_file = basefnm + tail
if files[0] != single_file:
os.rename(files[0], single_file)
# single ps files get compressed
if tail.endswith('.ps'):
gzipped_name = single_file+'.gz'
with open(single_file, 'rb') as ps_in:
with gzip.open(gzipped_name, 'wb') as gz_out:
if tail.endswith(".ps"):
gzipped_name = single_file + ".gz"
with open(single_file, "rb") as ps_in:
with gzip.open(gzipped_name, "wb") as gz_out:
shutil.copyfileobj(ps_in, gz_out)
os.unlink(single_file)
return gzipped_name
else:
return single_file
else:
zip_name = basefnm+ziptail
with zipfile.ZipFile(zip_name, 'w') as outzip:
zip_name = basefnm + ziptail
with zipfile.ZipFile(zip_name, "w") as outzip:
for file_to_zip in files:
outzip.write(file_to_zip)
for zipped_file in files:
Expand All @@ -84,36 +85,36 @@ def collect_assets(basefnm):

"""
assets = {}
assets['lyFile'] = _collect_lyfile(basefnm)
assets['midFile'] = _zip_maybe(basefnm, '.mid', '-mids.zip')
assets['psFileA4'] = _zip_maybe(basefnm, '-a4.ps', '-a4-pss.zip')
assets['psFileLet'] = _zip_maybe(basefnm, '-let.ps', '-let-pss.zip')
assets['pdfFileA4'] = _zip_maybe(basefnm, '-a4.pdf', '-a4-pdfs.zip')
assets['pdfFileLet'] = _zip_maybe(basefnm, '-let.pdf', '-let-pdfs.zip')
assets["lyFile"] = _collect_lyfile(basefnm)
assets["midFile"] = _zip_maybe(basefnm, ".mid", "-mids.zip")
assets["psFileA4"] = _zip_maybe(basefnm, "-a4.ps", "-a4-pss.zip")
assets["psFileLet"] = _zip_maybe(basefnm, "-let.ps", "-let-pss.zip")
assets["pdfFileA4"] = _zip_maybe(basefnm, "-a4.pdf", "-a4-pdfs.zip")
assets["pdfFileLet"] = _zip_maybe(basefnm, "-let.pdf", "-let-pdfs.zip")

# process the preview image
preview_name = ''
svgfiles = glob.glob('*.preview.svg')
preview_name = ""
svgfiles = glob.glob("*.preview.svg")
if len(svgfiles) > 0:
preview_name = basefnm+'-preview.svg'
preview_name = basefnm + "-preview.svg"
os.rename(svgfiles[0], preview_name)
assets['pngWidth'] = '0'
assets['pngHeight'] = '0'
assets["pngWidth"] = "0"
assets["pngHeight"] = "0"

if preview_name == '':
pngfiles = glob.glob('*.preview.png')
if preview_name == "":
pngfiles = glob.glob("*.preview.png")
if len(pngfiles) > 0:
preview_name = basefnm+'-preview.png'
preview_name = basefnm + "-preview.png"
os.rename(pngfiles[0], preview_name)
with open(preview_name, 'rb') as png_file:
with open(preview_name, "rb") as png_file:
png_reader = png.Reader(file=png_file)
width, height, _, _ = png_reader.read()
assets['pngWidth'] = str(width)
assets['pngHeight'] = str(height)
assets["pngWidth"] = str(width)
assets["pngHeight"] = str(height)

if preview_name == '':
raise mupub.IncompleteBuild('No preview image found.')
if preview_name == "":
raise mupub.IncompleteBuild("No preview image found.")

assets['pngFile'] = preview_name
assets["pngFile"] = preview_name

return assets
62 changes: 27 additions & 35 deletions mupub/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
import textwrap
import mupub

_FILEFMT = '%(asctime)s %(levelname)s %(name)s %(message)s'
_CONSOLEFMT = '%(levelname)-8s %(name)-12s %(message)s'
_DATEFMT = '%Y-%m-%d %H:%M:%S'
_FILEFMT = "%(asctime)s %(levelname)s %(name)s %(message)s"
_CONSOLEFMT = "%(levelname)-8s %(name)-12s %(message)s"
_DATEFMT = "%Y-%m-%d %H:%M:%S"

_LONG_DESCRIPTION="""
_LONG_DESCRIPTION = """
This is a command-line utility for managing the publication of
Mutopia Project contributions. All functionality is provided by
commands within this utility:

init - Initialize local data, syncbronize id's with mutopia site.
init - Initialize local data, synchronize id's with mutopia site.
check - Reviews the contributed piece for validity.
tag - Modifies the header with MutopiaProject fields.
build - Builds a complete set of output files for publication.
Expand All @@ -28,26 +28,23 @@


def _configure_logging(verbose):
if 'logging' not in mupub.CONFIG_DICT.sections():
if "logging" not in mupub.CONFIG_DICT.sections():
return
logdict = mupub.CONFIG_DICT['logging']
logdict = mupub.CONFIG_DICT["logging"]

# Set the module logger to the lowest reasonable level (DEBUG)
mupub_logger = logging.getLogger('mupub')
mupub_logger = logging.getLogger("mupub")
mupub_logger.setLevel(logging.DEBUG)

if logdict.getboolean('log_to_file', True):
if logdict.getboolean("log_to_file", True):
# Add a rotating logfile handler
logpath = os.path.join(mupub.CONFIG_DIR,
logdict.get('logfilename',
'mupub-errors.log'))
file_handler = RotatingFileHandler(logpath,
maxBytes=1024*100,
backupCount=3)
logpath = os.path.join(
mupub.CONFIG_DIR, logdict.get("logfilename", "mupub-errors.log")
)
file_handler = RotatingFileHandler(logpath, maxBytes=1024 * 100, backupCount=3)
# Logging is always INFO level
file_handler.setLevel(logging.INFO)
logform = logging.Formatter(fmt=_FILEFMT,
datefmt=_DATEFMT)
logform = logging.Formatter(fmt=_FILEFMT, datefmt=_DATEFMT)
file_handler.setFormatter(logform)
mupub_logger.addHandler(file_handler)

Expand All @@ -57,23 +54,22 @@ def _configure_logging(verbose):
n_level = logging.DEBUG
else:
# Check configuration for an alternate level.
level = logdict.get('loglevel', 'INFO')
level = logdict.get("loglevel", "INFO")
n_level = getattr(logging, level.upper(), None)
# Default to DEBUG in the event of a misspelled level
if not isinstance(n_level, int):
n_level = logging.DEBUG
mupub_logger.warning('%s is an invalid level. Check config.' % level)
mupub_logger.warning("%s is an invalid level. Check config." % level)

console = logging.StreamHandler()
console.setLevel(n_level)
console_form = logging.Formatter(fmt=_CONSOLEFMT,
datefmt=_DATEFMT)
console_form = logging.Formatter(fmt=_CONSOLEFMT, datefmt=_DATEFMT)
console.setFormatter(console_form)
mupub_logger.addHandler(console)


def _registered_commands(group='mupub.registered_commands'):
""" Get our registered commands.
def _registered_commands(group="mupub.registered_commands"):
"""Get our registered commands.

Iterates the entry points and returns the registered commands as a
dictionary.
Expand All @@ -98,29 +94,25 @@ def dispatch(argv):
"""
registered_commands = _registered_commands()
parser = argparse.ArgumentParser(
prog='mupub',
prog="mupub",
formatter_class=argparse.RawDescriptionHelpFormatter,
description=textwrap.dedent(_LONG_DESCRIPTION),
epilog='Use mupub <command> --help for specific command help',
epilog="Use mupub <command> --help for specific command help",
)

parser.add_argument(
'--version',
action='version',
version='%(prog)s version {0}'.format(mupub.__version__)
"--version",
action="version",
version="%(prog)s version {0}".format(mupub.__version__),
)
parser.add_argument("--verbose", action="store_true", help="louder")
parser.add_argument(
'--verbose',
action='store_true',
help='louder'
)
parser.add_argument(
'command',
"command",
choices=registered_commands.keys(),
)

parser.add_argument(
'args',
"args",
help=argparse.SUPPRESS,
nargs=argparse.REMAINDER,
)
Expand Down
Loading