LMMS Project Packager

Anything that doesn't fit into other topics goes here!
Hi ! I have create a small python application for create LMMS projects package :
→ List all files from project
→ Compact all imported files into ZIP file (in data directory)
→ Update all import directory from projects

Usage : lmmspackager.py project.mmp [projectoutput.zip]

Code: Select all

#!/usr/bin/env python3
# -*- coding:utf-8 -*-

import xml.etree.ElementTree as ET
import os
import zipfile
import sys

print("""LazyOne Software LMMS Project Packager

Code is under GPLV3 license. \n\n""")


if len(sys.argv) < 2:
    print(""" 
    USAGE : %s <project File Name (mmp file)> <output zip file>
        """ % sys.argv[0])
    sys.exit(1)
    
filein = sys.argv[1]

if len(sys.argv) < 3:
    fileout = os.path.basename("".join(filein.split(".")[:-1])) + ".zip"
else:
    fileout = sys.argv[2]


if not os.path.isfile(filein):
    print("File not found : %s" % (filein))
    sys.exit(2)

zipout = zipfile.ZipFile(fileout, "w")


print("Packaging LMMS Project. Please wait ...\n")
print("[INFO] Opening project source ...")


filehandler = open(filein, "r")
dataread = "".join(filehandler.readlines())
filehandler.close()

tree = ET.fromstring(dataread)
#root = tree.getroot()
compressed = list()
notfound = 0
for e in tree.findall(".//*"):
    if "src" in e.attrib.keys():
        fromfile = e.attrib["src"]
        basename = os.path.basename(fromfile)
        if not basename in compressed:
            
            print("[INFO] Packaging : %s" % (fromfile))
            if not os.path.isfile(fromfile):
                print("ERROR : %s not found. Project Packager continue to try to ZIP other files into .zip")
                notfound =+ 1
            else:
                zipout.write(fromfile, "data/%s" % (basename))
            compressed.append(basename)
        e.set("src", "./data/%s" % (basename))
print("[INFO] Packaging updated project file ...")

zipout.writestr(os.path.basename(filein), ET.tostring(tree))
zipout.close()

print("[INFO] DONE.")
print("\n\nYour project has been packaged into %s !" % (fileout))
if notfound > 0:
    print("Therefore, %s file(s) has not packaged.")
For get code, copy/paste all content into .py file.

Tested under GNU/Linux system. Can you test on Windows computer ? :D

File can be download here : http://82.235.150.75:4080/share/Ff_Nv1J ... spackager/

Tested with SF2 and external audio files.
Couldn't get it working. Didn't understand where I would place the path name, if path's are even allowed, or if I should add ".mmpz". I am on Windows. Remember on Windows I use \ in the paths which you can allow by making the string raw

open(r'c:\tmp\junkpythonfile','w')

Nice drums in Harry Stead - 01 - Alexander Brandt Wilson Plan Explanation
So, I have test under Windows today. Is not work (into Zip File). I plan to support Windows in some days

So, I have post new update into main post (Fix : Try to zip file is not found). File has not been update into my Freebox for the moment.

So, Script don't generate .mmpz file. mmpz file don't embed external files (.sf2, external ogg files or wav file...). The file generated at the output is .zip. And last filename is optionnal :) You can just type lmmsprojectpackager.py "project.mmp", create a zip named « project.zip ». (So, script don't handle .mmpz for the moment).

Thank's for your feedback and thank's for musics :)
What a coincidence. I've written a similar tool with a very similar name in the same language :3

https://github.com/grejppi/lmmspackager

Feel free to examine it.
Lolwut ?
NEW ! I'm working on a GUI for LMMS Packager.

Image

For the moment, only list files from a project :)
That is really nice!

You know, the whole project could benefit from this. Ideally it should be included in the program itself, but python programs can run on all OS' if you have python installed so this can be a great program for collaborating.
You know, the whole project could benefit from this. Ideally it should be included in the program itself, but python programs can run on all OS' if you have python installed so this can be a great program for collaborating.
We'll certainly recommend it as a stop-gap solution (and it can start to set the stage in terms of file extension, structure), but it won't be included in the codebase unless it is ported to QT/C++. I would advise further work on this.is done in a language we can cherry-pick from. :)

-Tres