make script to automatically patch script for packaging

This commit is contained in:
Swee 2024-09-10 16:15:24 -07:00
parent d12a8385f3
commit c61e9a504d
2 changed files with 17 additions and 4 deletions

View file

@ -1,9 +1,9 @@
#!/usr/bin/python3 #!/usr/bin/env python3
import gi, os, sys, sweecrypt as sc import gi, os, sys, sweecrypt as sc
gi.require_version("Gtk", "3.0") gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, GdkPixbuf, Gdk from gi.repository import Gtk, GdkPixbuf, Gdk
UI_FILE = os.path.dirname(os.path.realpath(__file__)) + "/sweecrypt-gtk.ui"
UI_FILE = "/opt/sweecrypt-gtk.ui" UI_FILE = "/opt/sweecrypt-gtk.ui"
class GUI:
def __init__(self): def __init__(self):
self.builder = Gtk.Builder() self.builder = Gtk.Builder()
self.builder.add_from_file(UI_FILE) self.builder.add_from_file(UI_FILE)
@ -33,4 +33,4 @@ def main():
app = GUI() app = GUI()
Gtk.main() Gtk.main()
if __name__ == "__main__": if __name__ == "__main__":
sys.exit(main()) sys.exit(main())

View file

@ -1,3 +1,16 @@
#!/usr/bin/python3 #!/usr/bin/python3
import os import os
file = open("sweecrypt-gtk.py").read() print("Creating Debian package...")
if os.name != "posix":
print("WARNING: Machine is not running Linux (value of os.name is not \"posix\"), the script will not try to auto-build the .deb file. You might need to manually `chmod 1777` the binary.")
file = open("sweecrypt-gtk.py").read().split("\n")
open("dpkg/opt/sweecrypt-gtk.ui",'w').write(open("sweecrypt-gtk.ui").read())
file[4] = 'UI_FILE = "/opt/sweecrypt-gtk.ui"'
file.insert(0, "#!/usr/bin/env python3")
file = "\n".join(file)
open("dpkg/usr/bin/sweecrypt-gtk",'w').write(file)
os.chmod("dpkg/usr/bin/sweecrypt-gtk", 1777)
if os.name == "posix":
os.chmod("dpkg/DEBIAN/control", 1777)
os.system("dpkg-deb --root-owner-group --build dpkg")
os.rename("dpkg.deb", "sweecrypt-gtk.deb")