Commit 7e2e6a51 authored by kliment's avatar kliment

Merge pull request #264 from iXce/experimental

Build system and CLI switch to request webinterface
parents 7e38278c 7da8a713
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -17,12 +17,10 @@ ...@@ -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,12 +29,13 @@ import threading ...@@ -31,12 +29,13 @@ 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:
try: try:
import stlview from printrun import stlview
glview = True glview = True
except: except:
pass pass
...@@ -245,7 +244,7 @@ class showstl(wx.Window): ...@@ -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))
......
...@@ -13,6 +13,9 @@ ...@@ -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): ...@@ -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', '')
......
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 lookup_file(filename, prefixes):
for prefix in prefixes:
candidate = os.path.join(prefix, filename)
if os.path.exists(candidate):
return candidate
return filename
def pixmapfile(filename):
return lookup_file(filename, ['/usr/local/share/pixmaps', '/usr/share/pixmaps'])
def sharedfile(filename):
return lookup_file(filename, ['/usr/local/share/pronterface', '/usr/share/pronterface'])
def configfile(filename):
return lookup_file(filename, [os.path.expanduser("~/.printrun/"),])
#!/usr/bin/python #!/usr/bin/python
import cherrypy, pronterface, re, ConfigParser, threading, sys import pronterface
import cherrypy, re, ConfigParser, threading, sys
import os.path import os.path
from printrun.printrun_utils import configfile, imagefile, sharedfile
users = {} users = {}
def PrintHeader(): def PrintHeader():
...@@ -238,7 +241,7 @@ class WebInterface(object): ...@@ -238,7 +241,7 @@ class WebInterface(object):
config = ConfigParser.SafeConfigParser(allow_no_value=True) config = ConfigParser.SafeConfigParser(allow_no_value=True)
else: else:
config = ConfigParser.SafeConfigParser() config = ConfigParser.SafeConfigParser()
config.read('auth.config') config.read(configfile(pface.web_auth_config or 'auth.config'))
users[config.get("user", "user")] = config.get("user", "pass") users[config.get("user", "user")] = config.get("user", "pass")
self.pface = pface self.pface = pface
global gPronterPtr global gPronterPtr
...@@ -358,19 +361,19 @@ def KillWebInterfaceThread(): ...@@ -358,19 +361,19 @@ def KillWebInterfaceThread():
def StartWebInterfaceThread(webInterface): def StartWebInterfaceThread(webInterface):
current_dir = os.path.dirname(os.path.abspath(__file__)) current_dir = os.path.dirname(os.path.abspath(__file__))
cherrypy.config.update({'engine.autoreload_on':False}) cherrypy.config.update({'engine.autoreload_on':False})
cherrypy.config.update("http.config") cherrypy.config.update(configfile(webInterface.pface.web_config or "http.config"))
conf = {'/css/style.css': {'tools.staticfile.on': True, conf = {'/css/style.css': {'tools.staticfile.on': True,
'tools.staticfile.filename': os.path.join(current_dir, 'css/style.css'), 'tools.staticfile.filename': sharedfile('css/style.css'),
}, },
'/images/control_xy.png': {'tools.staticfile.on': True, '/images/control_xy.png': {'tools.staticfile.on': True,
'tools.staticfile.filename': os.path.join(current_dir, 'images/control_xy.png'), 'tools.staticfile.filename': imagefile('control_xy.png'),
}, },
'/images/control_z.png': {'tools.staticfile.on': True, '/images/control_z.png': {'tools.staticfile.on': True,
'tools.staticfile.filename': os.path.join(current_dir, 'images/control_z.png'), 'tools.staticfile.filename': imagefile('control_z.png'),
}} }}
cherrypy.config.update("http.config") cherrypy.config.update(configfile(webInterface.pface.web_config or "http.config"))
cherrypy.quickstart(webInterface, '/', config=conf) cherrypy.quickstart(webInterface, '/', config=conf)
if __name__ == '__main__': if __name__ == '__main__':
cherrypy.config.update("http.config") cherrypy.config.update(configfile("http.config"))
cherrypy.quickstart(WebInterfaceStub()) cherrypy.quickstart(WebInterfaceStub())
...@@ -15,13 +15,7 @@ ...@@ -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
......
...@@ -15,14 +15,7 @@ ...@@ -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
......
...@@ -15,16 +15,15 @@ ...@@ -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:
...@@ -277,6 +276,9 @@ class pronsole(cmd.Cmd): ...@@ -277,6 +276,9 @@ class pronsole(cmd.Cmd):
self.helpdict["z_feedrate"] = _("Feedrate for Control Panel Moves in Z (default: 200mm/min)") self.helpdict["z_feedrate"] = _("Feedrate for Control Panel Moves in Z (default: 200mm/min)")
self.helpdict["final_command"] = _("Executable to run when the print is finished") self.helpdict["final_command"] = _("Executable to run when the print is finished")
self.commandprefixes='MGT$' self.commandprefixes='MGT$'
self.webrequested=False
self.web_config=None
self.web_auth_config=None
def set_temp_preset(self,key,value): def set_temp_preset(self,key,value):
if not key.startswith("bed"): if not key.startswith("bed"):
...@@ -1216,11 +1218,17 @@ class pronsole(cmd.Cmd): ...@@ -1216,11 +1218,17 @@ class pronsole(cmd.Cmd):
def parse_cmdline(self,args): def parse_cmdline(self,args):
import getopt import getopt
opts,args = getopt.getopt(args, "c:e:h", ["conf=","config=","help"]) opts,args = getopt.getopt(args, "c:e:hw", ["conf=","config=","help","web","web-config=", "web-auth-config="])
for o,a in opts: for o,a in opts:
#print repr((o,a)) #print repr((o,a))
if o in ("-c","--conf","--config"): if o in ("-c","--conf","--config"):
self.load_rc(a) self.load_rc(a)
elif o in ("-w","--web"):
self.webrequested = True
elif o == "--web-config":
self.web_config = a
elif o == "--web-auth-config":
self.web_auth_config = a
elif o in ("-h","--help"): elif o in ("-h","--help"):
print "Usage: "+sys.argv[0]+' [-c filename [-c filename2 ... ] ] [-e "command" ...]' print "Usage: "+sys.argv[0]+' [-c filename [-c filename2 ... ] ] [-e "command" ...]'
print " -c | --conf | --config - override startup .pronsolerc file" print " -c | --conf | --config - override startup .pronsolerc file"
......
This diff is collapsed.
#!/usr/bin/env python
# This file is part of the Printrun suite.
#
# Printrun is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Printrun is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Printrun. If not, see <http://www.gnu.org/licenses/>.
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))
extra_data_dirs = ["css"]
for extra_data_dir in extra_data_dirs:
for basedir, subdirs, files in os.walk(extra_data_dir):
files = map(lambda x: os.path.join(basedir, x), files)
destpath = os.path.join("share", "pronterface", basedir)
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", "printrun.svg"],
scripts = ["pronsole.py", "pronterface.py", "plater.py"],
cmdclass = {"uninstall" : uninstall,
"install" : install,
"install_data" : install_data}
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment