Initial work towards a setup.py build system

master
Guillaume Seguin 2012-07-31 10:51:17 +02:00
parent f63752d7fa
commit 888143be42
21 changed files with 189 additions and 44 deletions

View File

@ -17,12 +17,10 @@
# Set up Internationalization using gettext # Set up Internationalization using gettext
# searching for installed locales on /usr/share; uses relative folder if not found (windows) # searching for installed locales on /usr/share; uses relative folder if not found (windows)
import os, gettext, Queue, re import os, Queue, re
if os.path.exists('/usr/share/pronterface/locale'): from printrun.printrun_utils import install_locale
gettext.install('plater', '/usr/share/pronterface/locale', unicode=1) install_locale('plater')
else:
gettext.install('plater', './locale', unicode=1)
import wx import wx
import time import time
@ -31,7 +29,8 @@ import threading
import math import math
import sys import sys
import stltool from printrun import stltool
from printrun.printrun_utils import pixmapfile
glview = False glview = False
if "-nogl" not in sys.argv: if "-nogl" not in sys.argv:
@ -245,7 +244,7 @@ class showstl(wx.Window):
class stlwin(wx.Frame): class stlwin(wx.Frame):
def __init__(self, size=(800, 580), callback=None, parent=None): def __init__(self, size=(800, 580), callback=None, parent=None):
wx.Frame.__init__(self, parent, title=_("Plate building tool"), size=size) wx.Frame.__init__(self, parent, title=_("Plate building tool"), size=size)
self.SetIcon(wx.Icon("plater.ico", wx.BITMAP_TYPE_ICO)) self.SetIcon(wx.Icon(pixmapfile("plater.ico"), wx.BITMAP_TYPE_ICO))
self.mainsizer = wx.BoxSizer(wx.HORIZONTAL) self.mainsizer = wx.BoxSizer(wx.HORIZONTAL)
self.panel = wx.Panel(self, -1, size=(150, 600), pos=(0, 0)) self.panel = wx.Panel(self, -1, size=(150, 600), pos=(0, 0))
#self.panel.SetBackgroundColour((10, 10, 10)) #self.panel.SetBackgroundColour((10, 10, 10))

View File

@ -13,6 +13,9 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Printrun. If not, see <http://www.gnu.org/licenses/>. # along with Printrun. If not, see <http://www.gnu.org/licenses/>.
import wx,time import wx,time
from printrun_utils import imagefile
ID_ABOUT = 101 ID_ABOUT = 101
ID_EXIT = 110 ID_EXIT = 110
class window(wx.Frame): class window(wx.Frame):
@ -22,11 +25,11 @@ class window(wx.Frame):
vbox = wx.BoxSizer(wx.VERTICAL) vbox = wx.BoxSizer(wx.VERTICAL)
toolbar = wx.ToolBar(self, -1, style=wx.TB_HORIZONTAL | wx.NO_BORDER) toolbar = wx.ToolBar(self, -1, style=wx.TB_HORIZONTAL | wx.NO_BORDER)
toolbar.AddSimpleTool(1, wx.Image('./images/zoom_in.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap(), 'Zoom In [+]', '') toolbar.AddSimpleTool(1, wx.Image(imagefile('zoom_in.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), 'Zoom In [+]', '')
toolbar.AddSimpleTool(2, wx.Image('./images/zoom_out.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap(), 'Zoom Out [-]', '') toolbar.AddSimpleTool(2, wx.Image(imagefile('zoom_out.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), 'Zoom Out [-]', '')
toolbar.AddSeparator() toolbar.AddSeparator()
toolbar.AddSimpleTool(3, wx.Image('./images/arrow_up.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap(), 'Move Up a Layer [U]', '') toolbar.AddSimpleTool(3, wx.Image(imagefile('arrow_up.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), 'Move Up a Layer [U]', '')
toolbar.AddSimpleTool(4, wx.Image('./images/arrow_down.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap(), 'Move Down a Layer [D]', '') toolbar.AddSimpleTool(4, wx.Image(imagefile('arrow_down.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(), 'Move Down a Layer [D]', '')
toolbar.AddSimpleTool(5, wx.EmptyBitmap(16,16), 'Reset view', '') toolbar.AddSimpleTool(5, wx.EmptyBitmap(16,16), 'Reset view', '')
toolbar.AddSeparator() toolbar.AddSeparator()
#toolbar.AddSimpleTool(5, wx.Image('./images/inject.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap(), 'Insert Code at start of this layer', '') #toolbar.AddSimpleTool(5, wx.Image('./images/inject.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap(), 'Insert Code at start of this layer', '')

View File

@ -0,0 +1,28 @@
import os
import gettext
def install_locale(domain):
if os.path.exists('/usr/share/pronterface/locale'):
gettext.install(domain, '/usr/share/pronterface/locale', unicode=1)
elif os.path.exists('/usr/local/share/pronterface/locale'):
gettext.install(domain, '/usr/local/share/pronterface/locale', unicode=1)
else:
gettext.install(domain, './locale', unicode=1)
def imagefile(filename):
for prefix in ['/usr/local/share/pronterface/images', '/usr/share/pronterface/images']:
candidate = os.path.join(prefix, filename)
if os.path.exists(candidate):
return candidate
local_candidate = os.path.join(os.path.dirname(__file__), "images", filename)
if os.path.exists(local_candidate):
return local_candidate
else:
return os.path.join(os.path.split(os.path.split(__file__)[0])[0], "images", filename)
def pixmapfile(filename):
for prefix in ['/usr/local/share/pixmaps', '/usr/share/pixmaps']:
candidate = os.path.join(prefix, filename)
if os.path.exists(candidate):
return candidate
return filename

View File

@ -15,13 +15,7 @@
import wx, os, math import wx, os, math
from bufferedcanvas import * from bufferedcanvas import *
from printrun_utils import *
def imagefile(filename):
if os.path.exists(os.path.join(os.path.dirname(__file__), "images", filename)):
return os.path.join(os.path.dirname(__file__), "images", filename)
else:
return os.path.join(os.path.split(os.path.split(__file__)[0])[0], "images", filename)
def sign(n): def sign(n):
if n < 0: return -1 if n < 0: return -1

View File

@ -15,14 +15,7 @@
import wx, os, math import wx, os, math
from bufferedcanvas import * from bufferedcanvas import *
from printrun_utils import *
def imagefile(filename):
if os.path.exists(os.path.join(os.path.dirname(__file__), "images", filename)):
return os.path.join(os.path.dirname(__file__), "images", filename)
else:
return os.path.join(os.path.split(os.path.split(__file__)[0])[0], "images", filename)
def sign(n): def sign(n):
if n < 0: return -1 if n < 0: return -1

View File

@ -15,16 +15,15 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Printrun. If not, see <http://www.gnu.org/licenses/>. # along with Printrun. If not, see <http://www.gnu.org/licenses/>.
import cmd, printcore, sys import cmd, sys
import glob, os, time import glob, os, time
import sys, subprocess import sys, subprocess
import math, codecs import math, codecs
from math import sqrt from math import sqrt
import gettext
if os.path.exists('/usr/share/pronterface/locale'): from printrun import printcore
gettext.install('pronterface', '/usr/share/pronterface/locale', unicode=1) from printrun.printrun_utils import install_locale
else: install_locale('pronterface')
gettext.install('pronterface', './locale', unicode=1)
if os.name=="nt": if os.name=="nt":
try: try:

View File

@ -17,19 +17,17 @@
# Set up Internationalization using gettext # Set up Internationalization using gettext
# searching for installed locales on /usr/share; uses relative folder if not found (windows) # searching for installed locales on /usr/share; uses relative folder if not found (windows)
import os, gettext, Queue, re import os, Queue, re
if os.path.exists('/usr/share/pronterface/locale'): from printrun.printrun_utils import install_locale
gettext.install('pronterface', '/usr/share/pronterface/locale', unicode=1) install_locale('pronterface')
else:
gettext.install('pronterface', './locale', unicode=1)
try: try:
import wx import wx
except: except:
print _("WX is not installed. This program requires WX to run.") print _("WX is not installed. This program requires WX to run.")
raise raise
import printcore, sys, glob, time, threading, traceback, gviz, traceback, cStringIO, subprocess import sys, glob, time, threading, traceback, cStringIO, subprocess
try: try:
os.chdir(os.path.split(__file__)[0]) os.chdir(os.path.split(__file__)[0])
except: except:
@ -49,16 +47,17 @@ if os.name=="nt":
pass pass
from printrun import printcore, gviz
from xybuttons import XYButtons from printrun.xybuttons import XYButtons
from zbuttons import ZButtons from printrun.zbuttons import ZButtons
from graph import Graph from printrun.graph import Graph
from printrun.printrun_utils import pixmapfile
import pronsole import pronsole
webavail = False webavail = False
try : try :
if webavail: if webavail:
import cherrypy, webinterface import cherrypy, printrun.webinterface
from threading import Thread from threading import Thread
except: except:
print _("CherryPy is not installed. Web Interface Disabled.") print _("CherryPy is not installed. Web Interface Disabled.")
@ -109,7 +108,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
self.filename=filename self.filename=filename
os.putenv("UBUNTU_MENUPROXY","0") os.putenv("UBUNTU_MENUPROXY","0")
wx.Frame.__init__(self,None,title=_("Printer Interface"),size=size); wx.Frame.__init__(self,None,title=_("Printer Interface"),size=size);
self.SetIcon(wx.Icon("P-face.ico",wx.BITMAP_TYPE_ICO)) self.SetIcon(wx.Icon(pixmapfile("P-face.ico"),wx.BITMAP_TYPE_ICO))
self.panel=wx.Panel(self,-1,size=size) self.panel=wx.Panel(self,-1,size=size)
self.statuscheck=False self.statuscheck=False

130
setup.py Executable file
View File

@ -0,0 +1,130 @@
#!/usr/bin/env python
import sys, os, glob
import subprocess
from stat import *
from distutils.core import setup
from distutils.command.install import install as _install
from distutils.command.install_data import install_data as _install_data
INSTALLED_FILES = "installed_files"
class install (_install):
def run (self):
_install.run (self)
outputs = self.get_outputs ()
length = 0
if self.root:
length += len (self.root)
if self.prefix:
length += len (self.prefix)
if length:
for counter in xrange (len (outputs)):
outputs[counter] = outputs[counter][length:]
data = "\n".join (outputs)
try:
file = open (INSTALLED_FILES, "w")
except:
self.warn ("Could not write installed files list %s" % \
INSTALLED_FILES)
return
file.write (data)
file.close ()
class install_data (_install_data):
def run (self):
def chmod_data_file (file):
try:
os.chmod (file, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
except:
self.warn ("Could not chmod data file %s" % file)
_install_data.run (self)
map (chmod_data_file, self.get_outputs ())
class uninstall (_install):
def run (self):
try:
file = open (INSTALLED_FILES, "r")
except:
self.warn ("Could not read installed files list %s" % \
INSTALLED_FILES)
return
files = file.readlines ()
file.close ()
prepend = ""
if self.root:
prepend += self.root
if self.prefix:
prepend += self.prefix
if len (prepend):
for counter in xrange (len (files)):
files[counter] = prepend + files[counter].rstrip ()
for file in files:
print "Uninstalling %s" % file
try:
os.unlink (file)
except:
self.warn ("Could not remove file %s" % file)
ops = ("install", "build", "sdist", "uninstall", "clean")
if len (sys.argv) < 2 or sys.argv[1] not in ops:
print "Please specify operation : %s" % " | ".join (ops)
raise SystemExit
prefix = None
if len (sys.argv) > 2:
i = 0
for o in sys.argv:
if o.startswith ("--prefix"):
if o == "--prefix":
if len (sys.argv) >= i:
prefix = sys.argv[i + 1]
sys.argv.remove (prefix)
elif o.startswith ("--prefix=") and len (o[9:]):
prefix = o[9:]
sys.argv.remove (o)
i += 1
if not prefix and "PREFIX" in os.environ:
prefix = os.environ["PREFIX"]
if not prefix or not len (prefix):
prefix = "/usr/local"
if sys.argv[1] in ("install", "uninstall") and len (prefix):
sys.argv += ["--prefix", prefix]
target_images_path = "share/pronterface/images/"
data_files = [('share/pixmaps/', ['P-face.ico','plater.ico'])]
for basedir, subdirs, files in os.walk("images"):
images = []
for filename in files:
if filename.find(".svg") or filename.find(".png"):
file_path = os.path.join(basedir, filename)
images.append(file_path)
data_files.append((target_images_path + basedir[len("images/"):], images))
for basedir, subdirs, files in os.walk("locale"):
if not basedir.endswith("LC_MESSAGES"):
continue
destpath = os.path.join("share", "pronterface", basedir)
files = filter(lambda x: x.endswith(".mo"), files)
files = map(lambda x: os.path.join(basedir, x), files)
data_files.append ((destpath, files))
setup (
name = "Printrun",
description = "Host software for 3D printers",
author = "Kliment Yanev",
url = "http://github.com/kliment/Printrun/",
license = "GPLv3",
data_files = data_files,
packages = ["printrun"],
scripts = ["pronsole.py", "pronterface.py", "plater.py"],
cmdclass = {"uninstall" : uninstall,
"install" : install,
"install_data" : install_data}
)