Skip to content

Commit

Permalink
Windows shortcut icon
Browse files Browse the repository at this point in the history
  • Loading branch information
lpsandaruwan committed Jan 29, 2017
1 parent 9eef5c4 commit 2a62472
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 123 deletions.
35 changes: 35 additions & 0 deletions Operation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
""" Operations
Common operations used by installer scripts
"""

import os
import shutil
import stat
import wget


class Operation:

def copy_file(self, source, destination):
print("Copying " + source)
shutil.copy(source, destination)

def download_file(self, url, out_dir="."):
print("downloading " + url)
wget.download(url, out=out_dir)

def execute_mode(self, file):
print("changing mode of " + file + " to group-execute ")
os.chmod(file, stat.S_IXGRP)

def extract_archive(self, file_name, dest, type='gztar'):
print("extracting " + file_name + " to " + dest)
shutil.unpack_archive(file_name, dest, type)

def make_directory(self, path):
print("create directory at " + path)
try:
os.makedirs(path)
except:
print("Directory already exists or Invalid path.")
Binary file added assets/fontman.ico
Binary file not shown.
64 changes: 64 additions & 0 deletions darwin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
""" mac installer
Install fontman on Mac platforms
"""

import os, shutil, stat, time, wget
from os.path import expanduser

from Operation import Operation
from artifacts import base_url, fms_darwin_64, fms_darwin_86, gui_darwin_64, \
gui_darwin_86, version
from install import arch, print_info


def install():
o = Operation()
time.sleep(1)
print_info()

# create fontman home directory
print("creating fontman directory... :-)")
home_dir = expanduser('~/')
fontman_dir = home_dir + 'applications/fontman'
o.make_directory(fontman_dir)

# determine system architecture and download artifacts and extract
print("make sure you have connected to the internet... :-)")

if '64bit' in arch:
print("downloading fontman artifacts for darwin x86_64")
o.download_file(base_url + fms_darwin_64)
o.download_file(base_url + gui_darwin_64)

print("extracting...")
o.extract_archive(fms_darwin_64, fontman_dir)
o.extract_archive(gui_darwin_64, fontman_dir)

else:
print("downloading fontman artifacts for darwin x86")
o.download_file(base_url + fms_darwin_86)
o.download_file(base_url + gui_darwin_86)

print("extracting...")
o.extract_archive(fms_darwin_86, fontman_dir)
o.extract_archive(gui_darwin_86, fontman_dir)

# change mode of artifacts to execute mode
o.execute_mode(fontman_dir + "/fms")

# initializing fontman data
print("initializing fontman data...")
os.system("cd " + fontman_dir + " && ./fms init")

print("starting fontman :-)")
os.system(
"nohup "+ fontman_dir + "/fms start &> " + fontman_dir+ "/fms.log &"
)
os.system(fontman_dir + "/fontman-gui")

print("\n\nall done ^_^\n you can now close this window.")


if __name__ == '__main__':
install()
2 changes: 1 addition & 1 deletion install.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self):
print('Starting process')

if "Windows" in system:
self.process.start('python', ['windows.py'])
self.process.start('python', ['win32.py'])
elif "Linux" in system:
self.process.start('python3', ['linux.py'])

Expand Down
52 changes: 19 additions & 33 deletions linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,68 +3,53 @@
Install fontman on Linux platforms
"""

import os, shutil, stat, time, wget
import os, time
from os.path import expanduser

from artifacts import base_url, fms_linux_64, fms_linux_86, gui_linux_64, \
gui_linux_86, version
from install import arch, print_info


def download_file(url):
print("downloading " + url)
wget.download(url)


def execute_mode(file):
print("changing mode of " + file + " to group-execute ")
os.chmod(file, stat.S_IXGRP)


def extract_archive(file_name, dest, type='gztar'):
print("extracting " + file_name + " to " + dest)
shutil.unpack_archive(file_name, dest, type)


def make_directory(path):
print("create directory at " + path)
os.makedirs(path)
from Operation import Operation


def install():
o = Operation()
time.sleep(1)
print_info()

# create fontman home directory
print("creating fontman directory... :-)")
home_dir = expanduser('~/')
fontman_dir = home_dir + '.config/fontman'
make_directory(fontman_dir)
fontman_dir = home_dir + '.fontman'
o.make_directory(fontman_dir)

# determine system architecture and download artifacts and extract
print("make sure you have connected to the internet... :-)")

if '64bit' in arch:
print("downloading fontman artifacts for Linux x86_64")
download_file(base_url + fms_linux_64)
download_file(base_url + gui_linux_64)
o.download_file(base_url + fms_linux_64)
o.download_file(base_url + gui_linux_64)

print("extracting...")
extract_archive(fms_linux_64, fontman_dir)
extract_archive(gui_linux_64, fontman_dir)
o.extract_archive(fms_linux_64, fontman_dir)
o.extract_archive(gui_linux_64, fontman_dir)

else:
print("downloading fontman artifacts for Linux x86")
download_file(base_url + fms_linux_86)
download_file(base_url + gui_linux_86)
o.download_file(base_url + fms_linux_86)
o.download_file(base_url + gui_linux_86)

print("extracting...")
extract_archive(fms_linux_86, fontman_dir)
extract_archive(gui_linux_86, fontman_dir)
o.extract_archive(fms_linux_86, fontman_dir)
o.extract_archive(gui_linux_86, fontman_dir)

# copy fontman assets
o.copy_file("assets/fontman.ico", fontman_dir)

# change mode of artifacts to execute mode
execute_mode(fontman_dir + "/fms")
execute_mode(fontman_dir + "/fontman-gui")
o.execute_mode(fontman_dir + "/fms")
o.execute_mode(fontman_dir + "/fontman-gui")

# initializing fontman data
print("initializing fontman data...")
Expand All @@ -86,6 +71,7 @@ def install():
shortcut.write("[Desktop Entry]\n")
shortcut.write("Encoding=UTF-8\n")
shortcut.write("Version=" + version + "\n")
shortcut.write("Icon=" + fontman_dir + "/fontman.ico\n")
shortcut.write("Exec=" + fontman_dir + "/fontman-gui\n")
shortcut.write("Terminal=False\n")
shortcut.write("Type=Application\n")
Expand Down
76 changes: 76 additions & 0 deletions win32.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
""" windows installer
Install fontman on Windows platforms
"""

import os, time, winshell
from os.path import expanduser
from win32com.client import Dispatch

from Operation import Operation
from artifacts import base_url, fms_win_32, fms_win_86, gui_win_32,\
gui_win_86, version
from install import arch, print_info


def install():
o = Operation()
time.sleep(1)
print_info()

# create fontman home directory
print("creating fontman directory... :-)")
home_dir = expanduser('~/AppData\\Local')
fontman_dir = home_dir + '\\Fontman'
temp_dir = fontman_dir + '\\temp'

o.make_directory(fontman_dir)
o.make_directory(temp_dir)

# determine system architecture and download artifacts and extract
print("make sure you have connected to the internet... :-)")

if '64bit' in arch:
print("downloading fontman artifacts for Windows x86_64")
o.download_file(base_url + fms_win_32, temp_dir)
o.download_file(base_url + gui_win_32, temp_dir)

print("extracting...")
o.extract_archive(temp_dir + "\\" + fms_win_32, fontman_dir)
o.extract_archive(temp_dir + "\\" + gui_win_32, fontman_dir)

else:
print("downloading fontman artifacts for Windows x86")
o.download_file(base_url + fms_win_86, temp_dir)
o.download_file(base_url + gui_win_86, temp_dir)

print("extracting...")
o.extract_archive(temp_dir + "\\" + fms_win_86, fontman_dir)
o.extract_archive(temp_dir + "\\" + gui_win_86, fontman_dir)

# copy fontman assets
o.copy_file("assets/fontman.ico", fontman_dir)
o.copy_file("assets/run.bat", fontman_dir)

# initializing fontman data
print("initializing fontman data...")
os.system("cd " + fontman_dir + " && fms.exe init")

# creating shortcut
desktop = winshell.desktop()
path = os.path.join(desktop, "Fontman.lnk")
target = fontman_dir + "\\run.bat"
wDir = fontman_dir
icon = fontman_dir + "\\fontman.ico"

shell = Dispatch('WScript.Shell')
shortcut = shell.CreateShortCut(path)
shortcut.Targetpath = target
shortcut.WorkingDirectory = wDir
shortcut.IconLocation = icon
shortcut.save()

print("\n\nall done ^_^\n you can now close this window.")

if __name__ == '__main__':
install()
89 changes: 0 additions & 89 deletions windows.py

This file was deleted.

0 comments on commit 2a62472

Please sign in to comment.