Arch: Added dxflib autoupdate mechanism - fixes #0001301

This commit is contained in:
Yorik van Havre 2013-11-10 16:45:34 -02:00
parent 23eb4c7a08
commit 40d5a5462f
2 changed files with 30 additions and 16 deletions

View File

@ -535,13 +535,13 @@ def mergeCells(objectslist):
FreeCAD.ActiveDocument.recompute()
return base
def download(url):
def download(url,force=False):
'''downloads a file from the given URL and saves it in the
user directory. Returns the path to the saved file'''
import urllib2, os
name = url.split('/')[-1]
filepath = os.path.join(FreeCAD.ConfigGet("UserAppData"),name)
if os.path.exists(filepath):
if os.path.exists(filepath) and not(force):
return filepath
try:
FreeCAD.Console.PrintMessage("downloading "+url+" ...\n")

View File

@ -40,6 +40,7 @@ texts, colors,layers (from groups)
'''
TEXTSCALING = 1.35 # scaling factor between autocad font sizes and coin font sizes
CURRENTDXFLIB = 1.35 # the minimal version of the dxfLibrary needed to run
import sys, FreeCAD, os, Part, math, re, string, Mesh, Draft, DraftVecUtils, DraftGeomUtils
from Draft import _Dimension, _ViewProviderDimension
@ -50,24 +51,37 @@ try:
draftui = FreeCADGui.draftToolBar
except:
draftui = None
files = ['dxfColorMap.py','dxfImportObjects.py','dxfLibrary.py','dxfReader.py']
baseurl = 'https://raw.github.com/yorikvanhavre/Draft-dxf-importer/master/'
for f in files:
p = os.path.join(FreeCAD.ConfigGet("UserAppData"),f)
if not os.path.exists(p):
import ArchCommands
# check dxfLibrary version
try:
import dxfLibrary
import dxfColorMap
import dxfReader
except:
libsok = False
FreeCAD.Console.PrintWarning("DXF libraries not found. Downloading...\n")
else:
if "v"+str(CURRENTDXFLIB) in dxfLibrary.__version__:
libsok = True
else:
FreeCAD.Console.PrintWarning("DXF libraries need to be updated. Downloading...\n")
libsok = False
if not libsok:
files = ['dxfColorMap.py','dxfImportObjects.py','dxfLibrary.py','dxfReader.py']
baseurl = 'https://raw.github.com/yorikvanhavre/Draft-dxf-importer/master/'
import ArchCommands
for f in files:
p = None
p = ArchCommands.download(baseurl+f)
p = ArchCommands.download(baseurl+f,force=True)
if not p:
FreeCAD.Console.PrintWarning("Download of dxf libraries failed. Please download them manually from https://github.com/yorikvanhavre/Draft-dxf-importer\n")
sys.path.append(FreeCAD.ConfigGet("UserAppData"))
try:
import dxfColorMap, dxfLibrary, dxfReader
except:
dxfReader = None
dxfLibrary = None
sys.path.append(FreeCAD.ConfigGet("UserAppData"))
try:
import dxfColorMap, dxfLibrary, dxfReader
except:
dxfReader = None
dxfLibrary = None
if open.__module__ == '__builtin__':
pythonopen = open # to distinguish python built-in open function from the one declared here