Skip to content

Commit

Permalink
py3: AddonManager: use urllib.request insted of urllib2
Browse files Browse the repository at this point in the history
issue 0000995
  • Loading branch information
looooo authored and wwmayer committed May 11, 2017
1 parent b77d8ca commit b07075d
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/Mod/AddonManager/AddonManager.py
Expand Up @@ -38,7 +38,12 @@
'''

from PySide import QtCore, QtGui
import FreeCAD,urllib2,re,os,shutil
import sys, os, re, shutil
import FreeCAD
if sys.version_info.major < 3:
import urllib2
else:
import urllib.request as urllib2

NOGIT = False # for debugging purposes, set this to True to always use http downloads

Expand Down Expand Up @@ -304,6 +309,8 @@ def run(self):
self.progressbar_show.emit(True)
u = urllib2.urlopen("https://github.com/FreeCAD/FreeCAD-addons")
p = u.read()
if isinstance(p, bytes):
p = p.decode("utf-8")
u.close()
p = p.replace("\n"," ")
p = re.findall("octicon-file-submodule(.*?)message",p)
Expand Down Expand Up @@ -346,6 +353,8 @@ def run(self):
url = repo[1]
u = urllib2.urlopen(url)
p = u.read()
if isinstance(p, bytes):
p = p.decode("utf-8")
u.close()
desc = re.findall("<meta name=\"description\" content=\"(.*?)\">",p)
if desc:
Expand Down Expand Up @@ -374,6 +383,8 @@ def run(self):
macropath = FreeCAD.ParamGet('User parameter:BaseApp/Preferences/Macro').GetString("MacroPath",os.path.join(FreeCAD.ConfigGet("UserAppData"),"Macro"))
u = urllib2.urlopen("http://www.freecadweb.org/wiki/Macros_recipes")
p = u.read()
if isinstance(p, bytes):
p = p.decode("utf-8")
u.close()
macros = re.findall("title=\"(Macro.*?)\"",p)
macros = [mac for mac in macros if (not("translated" in mac))]
Expand Down Expand Up @@ -414,6 +425,8 @@ def run(self):
self.info_label.emit(translate("AddonsInstaller", "Retrieving info from ") + str(url))
u = urllib2.urlopen(url)
p = u.read()
if isinstance(p, bytes):
p = p.decode("utf-8")
u.close()
desc = re.findall("<meta name=\"description\" content=\"(.*?)\">",p)
if desc:
Expand Down Expand Up @@ -456,6 +469,8 @@ def run(self):
self.info_label.emit("Retrieving info from " + str(url))
u = urllib2.urlopen(url)
p = u.read()
if isinstance(p, bytes):
p = p.decode("utf-8")
u.close()
code = re.findall("<pre>(.*?)<\/pre>",p.replace("\n","--endl--"))
if code:
Expand Down Expand Up @@ -559,7 +574,8 @@ def run(self):

def download(self,giturl,clonedir):
"downloads and unzip from github"
import StringIO,zipfile
import zipfile
import io
bakdir = None
if os.path.exists(clonedir):
bakdir = clonedir+".bak"
Expand All @@ -573,7 +589,7 @@ def download(self,giturl,clonedir):
u = urllib2.urlopen(zipurl)
except:
return translate("AddonsInstaller", "Error: Unable to download") + " " + zipurl
zfile = StringIO.StringIO()
zfile = io.StringIO()
zfile.write(u.read())
zfile = zipfile.ZipFile(zfile)
master = zfile.namelist()[0] # github will put everything in a subfolder
Expand Down

0 comments on commit b07075d

Please sign in to comment.