Skip to content

Commit

Permalink
several change sincluding now fully funcitonal skin swapping
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDuckCow committed Oct 2, 2016
1 parent 593e644 commit 344d307
Show file tree
Hide file tree
Showing 9 changed files with 874 additions and 164 deletions.
85 changes: 47 additions & 38 deletions MCprep_addon/addon_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,7 @@

"""
See documentation for usage
# Check for existing updates or any past versions
# option 1: backgorund, async check with callback function input
myUpdater.check_for_update_async(callback=None) # input callback function
# option 2: immediate, thread-blocking
(update_ready, version, link) = myUpdater.check_for_update()
# run the update
run_update(revert_tag=None)
# or, select a verion to install
tags = myUpdater.get_tag_names()
latest_tag = tags[0] # equivalent to using revert_tag = None
myUpdater.run_update(revert_tag=latest_tag) # e.g. latest_tag = "v1.0.0"
https://github.com/CGCookie/blender-addon-updater
"""

Expand Down Expand Up @@ -107,7 +92,6 @@ def __init__(self):
self._fake_install = False
self._async_checking = False # only true when async daemon started
self._update_ready = None
self._connection_failed = False
self._update_link = None
self._update_version = None
self._source_zip = None
Expand All @@ -120,6 +104,8 @@ def __init__(self):
self._addon+"_updater")
self._addon_root = os.path.dirname(__file__)
self._json = {}
self._error = None
self._error_msg = None


# -------------------------------------------------------------------------
Expand Down Expand Up @@ -180,10 +166,6 @@ def json(self):
self.set_updater_json()
return self._json

@property
def connection_failed(self):
return self._connection_failed

@property
def repo(self):
return self._repo
Expand Down Expand Up @@ -336,6 +318,14 @@ def check_interval(self):
def check_interval(self, value):
raise ValueError("Check frequency is read-only")

@property
def error(self):
return self._error

@property
def error_msg(self):
return self._error_msg


# -------------------------------------------------------------------------
# Parameter validation related functions
Expand Down Expand Up @@ -377,13 +367,20 @@ def form_repo_url(self):
def get_tags(self):
request = "/repos/"+self.user+"/"+self.repo+"/tags"
# print("Request url: ",request)
if self.verbose:print("Grabbing tags from server")
if self.verbose:print("Getting tags from server")

# do more error checking e.g. no connection here
self._tags = self.get_api(request)
if len(self._tags) == 0:
if self._tags == None:
# some error occured
self._tag_latest = None
if self.verbose:print("No tags found on this repository")
self._tags = []
return
elif len(self._tags) == 0:
self._tag_latest = None
self._error = "No releases found"
self._error_msg = "No releases or tags found on this repository"
if self.verbose:print("No releases or tags found on this repository")
else:
self._tag_latest = self._tags[0]
if self.verbose:print("Most recent tag found:",self._tags[0])
Expand All @@ -395,11 +392,14 @@ def get_api_raw(self, url):
try:
result = urllib.request.urlopen(request)
except urllib.error.HTTPError as e:
raise ValueError("HTTPError, code: ",e.code)
# return or raise error?
self._error = "HTTP error"
self._error_msg = str(e.code)
self._update_ready = None
except urllib.error.URLError as e:
raise ValueError("URLError, reason: ",e.reason)
# return or raise error?
self._error = "URL error, check internet connection"
self._error_msg = str(e.reason)
self._update_ready = None
return None
else:
result_string = result.read()
result.close()
Expand All @@ -412,7 +412,10 @@ def get_api(self, url):
# return the json version
get = None
get = self.get_api_raw(url) # this can fail by self-created error raising
return json.JSONDecoder().decode( get )
if get != None:
return json.JSONDecoder().decode( get )
else:
return None


# create a working directory and download the new files
Expand Down Expand Up @@ -444,7 +447,6 @@ def stage_repository(self, url):
if self._verbose: print("Error: Aborting update, "+error)
raise ValueError("Aborting update, "+error)

if self._verbose:print("Todo: create backup zip of current addon now")
if self._backup_current==True:
self.create_backup()
if self._verbose:print("Now retreiving the new source zip")
Expand Down Expand Up @@ -589,7 +591,6 @@ def reload_addon(self):
return



if self._verbose:print("Reloading addon...")
addon_utils.modules(refresh=True)
bpy.utils.refresh_script_paths()
Expand Down Expand Up @@ -652,6 +653,10 @@ def check_for_update_async(self, callback=None):
self.start_async_check_update(False, callback)

def check_for_update_now(self, callback=None):

self._error = None
self._error_msg = None

if self._verbose: print("Check update pressed, first getting current status")
if self._async_checking == True:
if self._verbose:print("Skipping async check, already started")
Expand All @@ -669,6 +674,10 @@ def check_for_update_now(self, callback=None):
def check_for_update(self, now=False):
if self._verbose:print("Checking for update function")

# clear the errors if any
self._error = None
self._error_msg = None

# avoid running again in if already run once in BG, just return past result
# but if force now check, then still do it
if self._update_ready != None and now == False:
Expand Down Expand Up @@ -706,7 +715,6 @@ def check_for_update(self, now=False):
if len(self._tags) == 0:
if self._verbose:print("No tag found on this repository")
self._update_ready = False
self._connection_failed = True
return (False, None, None)
new_version = self.version_tuple_from_text(self.tag_latest)

Expand Down Expand Up @@ -754,6 +762,10 @@ def run_update(self, force=False, revert_tag=None, clean=False, callback=None):
self.set_tag(revert_tag)
self._update_ready = True

# clear the errors if any
self._error = None
self._error_msg = None


if self.verbose:print("Running update")

Expand Down Expand Up @@ -914,19 +926,16 @@ def async_check_update(self, now, callback=None):
self._async_checking = False
self._check_thread = None

def end_async_check_update():
# could return popup if condition met

return True

def stop_async_check_update():
def stop_async_check_update(self):
if self._check_thread != None:
try:
print("need to end the thread here..")
print("Thread will end in normal course.")
# however, "There is no direct kill method on a thread object."
#self._check_thread.stop()
except:
pass
self._async_checking = False


# -----------------------------------------------------------------------------
Expand Down
62 changes: 51 additions & 11 deletions MCprep_addon/addon_updater_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def target_version(self, context):

@classmethod
def poll(cls, context):
return updater.update_ready != None
return updater.update_ready != None and len(updater.tags)>0

def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self)
Expand Down Expand Up @@ -316,6 +316,24 @@ def execute(self, context):
updater.ignore_update()
return {'FINISHED'}


class addon_updater_end_background(bpy.types.Operator):
"""Stop checking for update in the background"""
bl_label = "End background check"
bl_idname = updater.addon+".end_background_check"
bl_description = "Stop checking for update in the background"

# @classmethod
# def poll(cls, context):
# if updater.async_checking == True:
# return True
# else:
# return False

def execute(self, context):
updater.stop_async_check_update()
return {'FINISHED'}

# -----------------------------------------------------------------------------
# Handler related, to create popups
# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -522,19 +540,40 @@ def update_settings_ui(self, context):
row = box.row()
col = row.column()
movemosue = False
if updater.update_ready == None and updater.async_checking == False:
if updater.error != None:
subcol = col.row(align=True)
subcol.scale_y = 1
split = subcol.split(align=True)
split.enabled = False
split.scale_y = 2
split.operator(addon_updater_check_now.bl_idname,
updater.error)
split = subcol.split(align=True)
split.scale_y = 2
split.operator(addon_updater_check_now.bl_idname,
text = "", icon="FILE_REFRESH")

elif updater.update_ready == None and updater.async_checking == False:
col.scale_y = 2
col.operator(addon_updater_check_now.bl_idname)
elif updater.update_ready == None: # async is running
col.scale_y = 2
col.enabled = False
col.operator(addon_updater_check_now.bl_idname, "Checking for update....")
movemosue = True # tell user to move mouse, trigger re-draw on background check
elif updater.update_ready == True and updater.update_version != updater.current_version:
subcol = col.row(align=True)
subcol.scale_y = 1
split = subcol.split(align=True)
split.enabled = False
split.scale_y = 2
split.operator(addon_updater_check_now.bl_idname,
"Checking...")
split = subcol.split(align=True)
split.scale_y = 2
split.operator(addon_updater_end_background.bl_idname,
text = "", icon="X")

elif updater.update_ready == True:# and updater.update_version != updater.current_version:
col.scale_y = 2
col.operator(addon_updater_update_now.bl_idname,
"Update now to "+str(updater.update_version))
else:
else: # ie that updater.update_ready == False
subcol = col.row(align=True)
subcol.scale_y = 1
split = subcol.split(align=True)
Expand Down Expand Up @@ -563,7 +602,9 @@ def update_settings_ui(self, context):

row = box.row()
lastcheck = updater.json["last_check"]
if movemosue == True:
if updater.error != None and updater.error_msg != None:
row.label(updater.error_msg)
elif movemosue == True:
row.label("Move mouse if button doesn't update")
elif lastcheck != "" and lastcheck != None:
lastcheck = lastcheck[0: lastcheck.index(".") ]
Expand All @@ -573,7 +614,6 @@ def update_settings_ui(self, context):




# -----------------------------------------------------------------------------
# Register, should be run in the register module itself
# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -605,7 +645,7 @@ def register(bl_info):

# optional, consider turning off for production or allow as an option
# This will print out additional debugging info to the console
updater.verbose = True
updater.verbose = False

# optional, customize where the addon updater processing subfolder is,
# needs to be within the same folder as the addon itself
Expand Down
24 changes: 20 additions & 4 deletions MCprep_addon/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
# ADDON GLOBAL VARIABLES AND INITIAL SETTINGS
# -----------------------------------------------------------------------------

import bpy

def init():

Expand Down Expand Up @@ -72,7 +73,7 @@ def init():
global json_data # mcprep_data.json
json_data = None # later will load addon information etc

global joson_user # mcprep_user.json
global json_user # mcprep_user.json
json_user = None # later will load user saved information


Expand Down Expand Up @@ -122,9 +123,9 @@ def init():
assets_installed = False


#
# Updates and stat tracking
#
# -----------------------------------------------
# For installing assets
# -----------------------------------------------

global update_ready
update_ready = False
Expand All @@ -134,3 +135,18 @@ def init():
# or force users to decide after 5 uses, ie blocking the panels


# -----------------------------------------------
# For cross-addon lists
# -----------------------------------------------
global skin_list
global rig_list
skin_list = [] # each is: [ basename, path ]
rig_list = [] # each is: [ verify this ]



def register():
pass

def unregister():
pass
Loading

0 comments on commit 344d307

Please sign in to comment.