Merge branch 'develop' into 2.0/sync_from_1.0

This commit is contained in:
Milan Kolar 2019-04-09 22:38:28 +02:00
commit 6c0bba1168
58 changed files with 2788 additions and 675 deletions

View file

@ -0,0 +1,49 @@
from avalon import api, io
from pype.api import Logger
try:
from pype.clockify import ClockifyAPI
except Exception:
pass
log = Logger.getLogger(__name__, "clockify_start")
class ClockifyStart(api.Action):
name = "clockify_start_timer"
label = "Clockify - Start Timer"
icon = "clockify_icon"
order = 500
exec("try: clockapi = ClockifyAPI()\nexcept: clockapi = None")
def is_compatible(self, session):
"""Return whether the action is compatible with the session"""
if self.clockapi is None:
return False
if "AVALON_TASK" in session:
return True
return False
def process(self, session, **kwargs):
project_name = session['AVALON_PROJECT']
asset_name = session['AVALON_ASSET']
task_name = session['AVALON_TASK']
description = asset_name
asset = io.find_one({
'type': 'asset',
'name': asset_name
})
if asset is not None:
desc_items = asset.get('data', {}).get('parents', [])
desc_items.append(asset_name)
desc_items.append(task_name)
description = '/'.join(desc_items)
project_id = self.clockapi.get_project_id(project_name)
tag_ids = []
tag_ids.append(self.clockapi.get_tag_id(task_name))
self.clockapi.start_time_entry(
description, project_id, tag_ids=tag_ids
)

View file

@ -0,0 +1,65 @@
from avalon import api, io
try:
from pype.clockify import ClockifyAPI
except Exception:
pass
from pype.api import Logger
log = Logger.getLogger(__name__, "clockify_sync")
class ClockifySync(api.Action):
name = "sync_to_clockify"
label = "Sync to Clockify"
icon = "clockify_white_icon"
order = 500
exec(
"try:\n\tclockapi = ClockifyAPI()"
"\n\thave_permissions = clockapi.validate_workspace_perm()"
"\nexcept:\n\tclockapi = None"
)
def is_compatible(self, session):
"""Return whether the action is compatible with the session"""
if self.clockapi is None:
return False
return self.have_permissions
def process(self, session, **kwargs):
project_name = session.get('AVALON_PROJECT', None)
projects_to_sync = []
if project_name.strip() == '' or project_name is None:
for project in io.projects():
projects_to_sync.append(project)
else:
project = io.find_one({'type': 'project'})
projects_to_sync.append(project)
projects_info = {}
for project in projects_to_sync:
task_types = [task['name'] for task in project['config']['tasks']]
projects_info[project['name']] = task_types
clockify_projects = self.clockapi.get_projects()
for project_name, task_types in projects_info.items():
if project_name not in clockify_projects:
response = self.clockapi.add_project(project_name)
if 'id' not in response:
self.log.error('Project {} can\'t be created'.format(
project_name
))
continue
project_id = response['id']
else:
project_id = clockify_projects[project_name]
clockify_workspace_tags = self.clockapi.get_tags()
for task_type in task_types:
if task_type not in clockify_workspace_tags:
response = self.clockapi.add_tag(task_type)
if 'id' not in response:
self.log.error('Task {} can\'t be created'.format(
task_type
))
continue