Skip to content

Commit

Permalink
0.6.5 beta
Browse files Browse the repository at this point in the history
- Bug fixes
- Refactorings
  • Loading branch information
Ivan Titov committed Apr 29, 2020
1 parent 64d50e3 commit f86a82f
Show file tree
Hide file tree
Showing 25 changed files with 201 additions and 177 deletions.
3 changes: 2 additions & 1 deletion package.setup
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"name": "Package Manager",
"author": "Ivan Titov",
"version": "0.6.4-beta",
"version": "0.6.5-beta",
"version_type": "version",
"source": "Houdini-Packages/Houdini-Package-Manager",
"source_type": "github"
}
84 changes: 28 additions & 56 deletions python2.7libs/package_manager/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@
import hou
import requests

from .local_package import isPackage, NotPackageError, LocalPackage
from .local_package import NotPackageError, LocalPackage
from package_manager.package import isPackage
from .houdini_license import fullHoudiniLicenseName, HOUDINI_COMMERCIAL_LICENSE
from .version_dialog import VersionDialog
from .version import Version
from .web_package import WebPackage
from .package import Package


class RepoNotFound(Exception):
class RepoNotFound(IOError):
pass


Expand Down Expand Up @@ -47,7 +48,7 @@ def fromJson(cls, data):
return cls(data['data'], data.get('etag'), data.get('last_modified'))


class GitHubAPICache:
class API:
cache_data = {}

@staticmethod
Expand All @@ -63,96 +64,67 @@ def get(url, headers=None, timeout=5):
headers_data.update(headers)

try:
GitHubAPICache.loadFromFile()
API.loadFromFile()
except IOError:
pass

if url in GitHubAPICache.cache_data:
cached_item = GitHubAPICache.cache_data[url]
if url in API.cache_data:
cached_item = API.cache_data[url]
if cached_item.etag:
headers_data['If-None-Match'] = cached_item.etag
elif cached_item.last_modified:
headers_data['If-Modified-Since'] = cached_item.last_modified

r = requests.get(url, stream=True, headers=headers_data, timeout=timeout)

if os.getenv('username') == 'MarkWilson': # Debug only
print(r.headers.get('X-RateLimit-Remaining'))

if r.status_code == 200:
data = json.loads(r.text)
etag = r.headers.get('ETag')
last_modified = r.headers.get('Last-Modified')
GitHubAPICache.cache_data[url] = CacheItem(data, etag, last_modified)
GitHubAPICache.saveToFile()
API.cache_data[url] = CacheItem(data, etag, last_modified)
API.saveToFile()
return data
elif r.status_code == 304:
return GitHubAPICache.cache_data[url].data
return API.cache_data[url].data
elif r.status_code == 403:
raise ReachedAPILimit
elif r.status_code == 404:
raise RepoNotFound # Todo: explainable message

# @staticmethod
# def post(query):
# """Test only, don't use in production"""
# headers = {'Authorization': 'Bearer 008d86db69e83cef0e1df1d2d3691b6efcc28be6'}
# r = requests.post('https://api.github.com/graphql', json={'query': query}, headers=headers)
# print(r.text)

@staticmethod
def toJson():
return {url: item.toJson() for url, item in GitHubAPICache.cache_data.items()}
return {url: item.toJson() for url, item in API.cache_data.items()}

@staticmethod
def fromJson(data):
for url, item_data in data.items():
GitHubAPICache.cache_data[url] = CacheItem.fromJson(item_data)
API.cache_data[url] = CacheItem.fromJson(item_data)

@staticmethod
def saveToFile():
file_path = hou.expandString('$HOUDINI_USER_PREF_DIR/package_manager.github_api_cache')
with open(file_path, 'w') as file:
json.dump(GitHubAPICache.toJson(), file)
json.dump(API.toJson(), file)

@staticmethod
def loadFromFile():
file_path = hou.expandString('$HOUDINI_USER_PREF_DIR/package_manager.github_api_cache')
with open(file_path) as file:
GitHubAPICache.fromJson(json.load(file))
API.fromJson(json.load(file))

@staticmethod
def clear():
GitHubAPICache.cache_data = {}
GitHubAPICache.saveToFile()
API.cache_data = {}
API.saveToFile()

@staticmethod
def cacheSize():
raise NotImplementedError


# class Release:
# def __init__(self, release_data):
# self.__data = release_data
#
# @property
# def version(self):
# return self.__data.get('tag_name')
#
# @property
# def name(self):
# return self.__data.get('name')
#
# @property
# def changes(self):
# return self.__data.get('body')
#
# @property
# def is_stable(self):
# return not self.__data.get('prerelease')
#
# @property
# def zip_archive_url(self):
# return self.__data.get('zipball_url')


def ownerAndRepoName(source):
return source.strip('/').split('/')[-2:]

Expand All @@ -164,7 +136,7 @@ def repoURL(owner, repo_name):
def isPackageRepo(source):
repo_owner, repo_name = ownerAndRepoName(source)
api_repo_url = 'https://api.github.com/repos/{0}/{1}/contents'.format(repo_owner, repo_name)
repo_content = GitHubAPICache.get(api_repo_url)
repo_content = API.get(api_repo_url)
items = tuple(file_data['name'] for file_data in repo_content)
return isPackage(items)

Expand All @@ -188,15 +160,15 @@ def extractRepoZip(file_path, repo_data, dst_location='$HOUDINI_USER_PREF_DIR',


def ownerName(login):
return GitHubAPICache.get('https://api.github.com/users/' + login).get('name', login)
return API.get('https://api.github.com/users/' + login).get('name', login)


def repoDescription(package_or_link):
if isinstance(package_or_link, Package):
repo_owner, repo_name = ownerAndRepoName(package_or_link.source)
else: # package_or_link is link
repo_owner, repo_name = ownerAndRepoName(package_or_link)
return GitHubAPICache.get('https://api.github.com/repos/{0}/{1}'.format(repo_owner, repo_name)).get('description')
return API.get('https://api.github.com/repos/{0}/{1}'.format(repo_owner, repo_name)).get('description')


def updatePackageDataFile(repo_data, package, package_location,
Expand Down Expand Up @@ -229,8 +201,8 @@ def updatePackageDataFile(repo_data, package, package_location,
fullHoudiniLicenseName(HOUDINI_COMMERCIAL_LICENSE)
if not data.get('status') or update:
data['status'] = package.status or 'Stable'
if not data.get('setup_scheme') or update:
data['setup_scheme'] = package.setup_scheme
if not data.get('setup_schema') or update:
data['setup_schema'] = package.setup_schema
with open(data_file_path, 'w') as file:
json.dump(data, file, indent=4, encoding='utf-8')

Expand All @@ -256,12 +228,12 @@ def installFromRepo(package_or_link, dst_location='$HOUDINI_USER_PREF_DIR', upda
package = None

repo_api_url = 'https://api.github.com/repos/{0}/{1}'.format(repo_owner, repo_name)
repo_data = GitHubAPICache.get(repo_api_url)
repo_data = API.get(repo_api_url)

version = None
releases_api_url = repo_api_url + '/releases'
versions = []
for release_data in GitHubAPICache.get(releases_api_url):
for release_data in API.get(releases_api_url):
if only_stable and release_data['prerelease']:
continue
versions.append(Version(release_data['tag_name']))
Expand Down Expand Up @@ -301,13 +273,13 @@ def repoHasUpdate(link, version, version_type, only_stable=True):

repo_api_url = 'https://api.github.com/repos/{0}/{1}'.format(repo_owner, repo_name)
if version_type == 'time_github':
repo_data = GitHubAPICache.get(repo_api_url)
repo_data = API.get(repo_api_url)
latest_version = parseTimestamp(repo_data['pushed_at'])
version = parseTimestamp(version)
# Todo: support only_stable
else:
releases_api_url = repo_api_url + '/releases'
releases_data = GitHubAPICache.get(releases_api_url)
releases_data = API.get(releases_api_url)

if not releases_data:
return False
Expand Down
2 changes: 2 additions & 0 deletions python2.7libs/package_manager/houdini_license.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import print_function

import hou

HOUDINI_COMMERCIAL_LICENSE = hou.licenseCategoryType.Commercial
Expand Down
8 changes: 5 additions & 3 deletions python2.7libs/package_manager/install_local.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import print_function

import os

try:
Expand Down Expand Up @@ -71,9 +73,9 @@ def __init__(self, parent=None):
self.folder_path_field = FolderField()
form_layout.addRow('Folder Path', self.folder_path_field)

self.setup_scheme_combo = QComboBox()
self.setup_scheme_combo.setDisabled(True)
form_layout.addRow('Setup Scheme', self.setup_scheme_combo)
self.setup_schema_combo = QComboBox()
self.setup_schema_combo.setDisabled(True)
form_layout.addRow('Setup Schema', self.setup_schema_combo)

buttons_layout = QHBoxLayout()
main_layout.addLayout(buttons_layout)
Expand Down
8 changes: 5 additions & 3 deletions python2.7libs/package_manager/install_web.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import print_function

try:
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
Expand Down Expand Up @@ -36,9 +38,9 @@ def __init__(self, parent=None):
self.web_link_field.setPlaceholderText('https://github.com/Houdini-Packages/Houdini-Package-Manager')
form_layout.addRow('Web Link', self.web_link_field)

self.setup_scheme_combo = QComboBox()
self.setup_scheme_combo.setDisabled(True)
form_layout.addRow('Setup Scheme', self.setup_scheme_combo)
self.setup_schema_combo = QComboBox()
self.setup_schema_combo.setDisabled(True)
form_layout.addRow('Setup Schema', self.setup_schema_combo)

buttons_layout = QHBoxLayout()
main_layout.addLayout(buttons_layout)
Expand Down
2 changes: 2 additions & 0 deletions python2.7libs/package_manager/link_label.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import print_function

import webbrowser

try:
Expand Down
97 changes: 4 additions & 93 deletions python2.7libs/package_manager/local_package.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from __future__ import print_function

import json
import os

import hou

from .houdini_license import fullHoudiniLicenseName
from .package_status import fullPackageStatusName
from .package import Package
from .package import Package, isPackage


class NotPackageError(IOError):
Expand All @@ -20,97 +22,6 @@ class AlreadyInstalledError(IOError):
pass


def isPackage(items, level=2):
XML_NAMES = ('AnimationEditorDopesheetContextMenu',
'AnimationEditorDopesheetMenu',
'AnimationEditorGraphContextMenu',
'AnimationEditorGraphMenu',
'AnimationEditorMenu',
'AnimationEditorTableContextMenu',
'AnimationEditorTableMenu',
'ChannelListMenu',
'CHGmenu',
'DesktopsMenu',
'ExampleMenu',
'GEOclassicXlate',
'KeyframesMenu',
'MainMenuARecord',
'MainMenuCommon',
'MainMenuEscape',
'MainMenuGPlay',
'MainMenuHKey',
'MainMenuHOTLView',
'MainMenuMaster',
'MainMenuMPlay',
'MainMenuPDG',
'MotionEffectsMenu',
'NetworkViewMenu',
'NetworkViewMenuPDG',
'NetworkViewMenuTOP',
'OPmenu',
'PaneTabTypeMenu',
'PaneTabTypeMenuPDG',
'ParmGearMenu',
'PARMmenu',
'PlaybarMenu',
'ShelfMenu',
'ShelfSetMenu',
'ShelfSetPlusMenu',
'ShelfToolMenu',
'TakeListMenu',
'UsdStagePrimMenu',
'VOPFXmenu')
scores = 0
if 'bin' in items:
scores += 1
if 'config' in items:
scores += 1
if 'presets' in items:
scores += 1
if 'desktop' in items:
scores += 1
if 'radialmenu' in items:
scores += 2
if 'dso' in items:
scores += 1
if 'inlinecpp' in items:
scores += 1
if 'otls' in items:
scores += 2
if 'help' in items:
scores += 1
if 'python_panels' in items:
scores += 2
if 'scripts' in items:
scores += 1
if 'toolbar' in items:
scores += 1
if 'ocl' in items:
scores += 1
if 'vex' in items:
scores += 2
if 'vop' in items:
scores += 2
if 'python2.7libs' in items:
scores += 1
if 'python3.7libs' in items:
scores += 1
if 'viewer_states' in items:
scores += 2
for item in items:
if item.endswith('.xml') and item.split('.')[0] in XML_NAMES:
scores += 2
if 'OPcustomize' in items:
scores += 2
if 'Expressions.txt' in items:
scores += 1
if 'VEXpressions.txt' in items:
scores += 2
if 'PythonScripts.txt' in items:
scores += 1
return scores >= level


def isPackageFolder(path):
if not os.path.isdir(path):
return None
Expand Down Expand Up @@ -172,7 +83,7 @@ def __init__(self, package_file):
self.hversion = data.get(u'hversion')
self.hlicense = fullHoudiniLicenseName(data.get(u'hlicense'))
self.status = fullPackageStatusName(data.get(u'status'))
self.setup_scheme = data.get(u'setup_scheme')
self.setup_schema = data.get(u'setup_schema')

def files(self, extensions, root='', ignore_folders=True, recursive=False):
if not os.path.isdir(self.content_path):
Expand Down
Loading

0 comments on commit f86a82f

Please sign in to comment.