1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
#!/usr/bin/env python3
"""
Writes out a desktop file for this project.
Suggested location: $XDG_DATA_HOME/applications/antimony.desktop
"""
import argparse
import os
import subprocess
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('filename', nargs='?',
help='where to write the desktop file')
TEMPLATE = """[Desktop Entry]
Type=Application
Version=1.0
Name=Antimony
Comment=Tree-based Modeler
GenericName=CAD Application
Exec={exec} %f
Icon={icon}
Terminal=false
Categories=Graphics;Science;Engineering;
MimeType=application/x-extension-sb;application/x-antimony;
StartupWMClass=antimony
"""
def get_default_file():
"""
Divine the default filename to write to.
"""
if 'XDG_DATA_HOME' in os.environ:
return os.path.join(os.environ['XDG_DATA_HOME'], 'applications/antimony.desktop')
else:
return os.path.expanduser('~/.local/share/applications/antimony.desktop')
def project():
"""
Get the directory name of the project
"""
return os.path.dirname( # .../antimony
os.path.dirname( # .../deploy
os.path.dirname( # .../linux
os.path.abspath(__file__) # .../mkdesktop
)
)
)
def find_antimony(usepath=False):
"""
Track down the antimony binary
"""
proanti = os.path.join(project(), 'build', 'app', 'antimony')
if usepath:
for path in os.environ['PATH'].split(':'):
pathanti = os.path.join(path, 'antimony')
if os.path.exists(pathanti):
return 'antimony'
else:
return proanti
def find_icon():
"""
Locate the antimony icon
"""
return os.path.join(project(), 'deploy', 'icon.svg')
if __name__ == '__main__':
args = parser.parse_args()
fn = args.filename or get_default_file()
print("Project:", project())
with open(fn, 'w') as desktop:
desktop.write(TEMPLATE.format(exec=find_antimony(), icon=find_icon()))
subprocess.check_call(['xdg-desktop-menu', 'forceupdate'])
|