From 5ba6a45dd4d7166a68f2ebd66fbc1e7aec50451f Mon Sep 17 00:00:00 2001 From: Daniel Alfaro Date: Fri, 12 Apr 2024 13:15:51 -0700 Subject: [PATCH 1/2] Update URL's to use software-app --- Default.sublime-commands | 6 +----- Default.sublime-keymap | 4 ++-- Main.sublime-menu | 6 +----- Software.py | 7 ------- lib/SlackManager.py | 7 +------ lib/SoftwareHttp.py | 13 ++++++------- lib/SoftwareUserStatus.py | 4 ++-- lib/SoftwareUtil.py | 2 +- lib/TrackerManager.py | 12 ++++++------ lib/TreePanel.py | 18 +++++++----------- 10 files changed, 27 insertions(+), 52 deletions(-) diff --git a/Default.sublime-commands b/Default.sublime-commands index 279e825..d063c06 100644 --- a/Default.sublime-commands +++ b/Default.sublime-commands @@ -11,10 +11,6 @@ "command": "edit_preferences", "caption": "Code Time: Settings" }, - { - "command": "go_to_software", - "caption": "Code Time: More data at Software.com" - }, { "command": "show_tree_view", "caption": "Code Time: Menu" @@ -35,4 +31,4 @@ "command": "toggle_status_bar_metrics", "caption": "Code Time: Toggle Status Bar Metrics" } -] \ No newline at end of file +] diff --git a/Default.sublime-keymap b/Default.sublime-keymap index 3fa6178..34761df 100644 --- a/Default.sublime-keymap +++ b/Default.sublime-keymap @@ -1,3 +1,3 @@ [ - { "keys": ["ctrl+alt+o"], "command": "go_to_software" } -] \ No newline at end of file + { "keys": ["ctrl+alt+o"], "command": "view_dashboard" } +] diff --git a/Main.sublime-menu b/Main.sublime-menu index 8ec0e50..e66b088 100644 --- a/Main.sublime-menu +++ b/Main.sublime-menu @@ -21,10 +21,6 @@ "command": "edit_preferences", "caption": "Settings" }, - { - "command": "go_to_software", - "caption": "More data at Software.com" - }, { "command": "show_tree_view", "caption": "Menu" @@ -41,4 +37,4 @@ } ] } -] \ No newline at end of file +] diff --git a/Software.py b/Software.py index 31d3c5e..83ff828 100644 --- a/Software.py +++ b/Software.py @@ -47,13 +47,6 @@ def run(self, edit): def is_enabled(self): return True -class GoToSoftware(sublime_plugin.TextCommand): - def run(self, edit): - launchWebDashboardUrl() - - def is_enabled(self): - return True - class SwitchAccount(sublime_plugin.TextCommand): def run(self, edit): switchAccount() diff --git a/lib/SlackManager.py b/lib/SlackManager.py index 0b9b665..50cacb9 100644 --- a/lib/SlackManager.py +++ b/lib/SlackManager.py @@ -42,10 +42,7 @@ def connectSlackWorkspace(): t.start() def launchSlackSettings(): - scheme = "https" - if('localhost' in getApiEndpoint()): - scheme = "http" - url = scheme + "://" + getWebUrl() + "data_sources/integration_types/slack" + url = getWebUrl() + "/data_sources/integration_types/slack" webbrowser.open(url) ####################################################################################### @@ -69,5 +66,3 @@ def getSlackAuth(): curentUser = getUser(True) return hasSlackWorkspaces() - - diff --git a/lib/SoftwareHttp.py b/lib/SoftwareHttp.py index eb17de1..f1a1fd4 100644 --- a/lib/SoftwareHttp.py +++ b/lib/SoftwareHttp.py @@ -58,8 +58,8 @@ def isUnauthenticated(response): def requestIt(method, api, payload, token=None): return apiRequest(method, api, payload, getApiEndpoint(), token) -def appRequestIt(method, api, payload): - return apiRequest(method, api, payload, getAppEndpoint()) +def appRequestIt(method, api, payload, token=None): + return apiRequest(method, api, payload, getAppEndpoint(), token) def apiRequest(method, api, payload, api_endpoint, token=None): @@ -73,7 +73,7 @@ def apiRequest(method, api, payload, api_endpoint, token=None): # try to update kpm data. try: if jwt is None: - jwt = getItem('jwt') + jwt = getJwt() headers = {'Content-Type': 'application/json', 'User-Agent': USER_AGENT} connection = None @@ -188,12 +188,11 @@ def getUser(refreshUser=True): jwt = getItem("jwt") if (jwt): - api = "/users/me" - response = requestIt("GET", api, None) + api = "/api/v1/user" + response = appRequestIt("GET", api, None) if (isResponseOk(response)): try: - responseObj = json.loads(response.read().decode('utf-8')) - currentUser = responseObj.get("data", None) + currentUser = json.loads(response.read().decode('utf-8')) return currentUser except Exception as ex: logIt("Code Time: Unable to retrieve user: %s" % ex) diff --git a/lib/SoftwareUserStatus.py b/lib/SoftwareUserStatus.py index 796b8d0..6829d0d 100644 --- a/lib/SoftwareUserStatus.py +++ b/lib/SoftwareUserStatus.py @@ -145,10 +145,10 @@ def launchWebDashboardUrl(): webbrowser.open(getWebUrl()) def launchCodeTimeDashboard(): - webbrowser.open(getWebUrl() + "/dashboard/code_time?view=summary") + webbrowser.open(getWebUrl() + "/dashboard/code_time") def launchUpdatePreferences(): - webbrowser.open(getWebUrl() + "/preferences") + webbrowser.open(getWebUrl() + "/dashboard/code_time/settings") def switchAccount(): keys = ['Google', 'GitHub', 'Email'] diff --git a/lib/SoftwareUtil.py b/lib/SoftwareUtil.py index a98907d..113929c 100644 --- a/lib/SoftwareUtil.py +++ b/lib/SoftwareUtil.py @@ -300,7 +300,7 @@ def initializeUserPreferences(): user = getUser() if(user): - session_threshold_in_sec = user.get("preferences", {}).get("sessionThresholdInSec", getSessionThresholdSeconds()) + session_threshold_in_sec = user.get("preferences_parsed", {}).get("sessionThresholdInSec", getSessionThresholdSeconds()) # update values config setItem("sessionThresholdInSec", session_threshold_in_sec) diff --git a/lib/TrackerManager.py b/lib/TrackerManager.py index 0544dee..fa7c5cb 100644 --- a/lib/TrackerManager.py +++ b/lib/TrackerManager.py @@ -20,7 +20,7 @@ def swdc_tracker(event_json, context): global cached_tracker if cached_tracker is None: - response = requestIt('GET', '/plugins/config', None, None) + response = appRequestIt('GET', '/api/v1/plugins/config', None) if response is not None and isResponseOk(response): config = json.loads(response.read().decode('utf-8')) e = Emitter(config['tracker_api']) @@ -216,15 +216,15 @@ def hash_value(value, data_type, jwt): def fetch_user_hashed_values(): try: - response = requestIt('GET', '/hashed_values', None, getJwt()) + response = appRequestIt('GET', '/api/v1/user/hashed_values', None) user_hashed_values = json.loads(response.read().decode('utf-8')) global cached_hashed_values cached_hashed_values = user_hashed_values storeHashedValues(user_hashed_values) except Exception as ex: - print("ERROR FETCHING HASHED VALUES") - print(ex) + logIt("ERROR FETCHING HASHED VALUES") + logIt(ex) def encrypt_and_save(value, hashed_value, data_type, jwt): params = { @@ -233,9 +233,9 @@ def encrypt_and_save(value, hashed_value, data_type, jwt): 'data_type': data_type } - response = requestIt('POST', '/user_encrypted_data', json.dumps(params), jwt) + response = appRequestIt('POST', '/api/v1/user/encrypted_data', json.dumps(params)) if response and isResponseOk(response): return True else: - print("error POSTing to /user_encrypted_data for value: " + hashed_value) + logIt("error POSTing to /api/v1/user/encrypted_data for value: " + hashed_value) return False diff --git a/lib/TreePanel.py b/lib/TreePanel.py index 61fa822..07edc4e 100644 --- a/lib/TreePanel.py +++ b/lib/TreePanel.py @@ -36,7 +36,6 @@ UPDATE_PREFERENCES_LABEL = 'Settings' LEARN_MORE_LABEL = 'Learn more' VIEW_DASHBOARD_LABEL = 'View dashboard' -SEE_ADVANCED_METRICS = 'More data at Software.com' TODAY_VS_AVG_LABEL = 'Today vs.' SLACK_WORKSPACES_LABEL = 'Slack workspaces' ADD_SLACK_WORKSPACE_LABEL = 'Add workspace' @@ -71,13 +70,12 @@ def create_tree(self): self.keys.append('%s%s' % (firstChildDepth, UPDATE_PREFERENCES_LABEL)) self.keys.append('%s%s' % (firstChildDepth, VIEW_DASHBOARD_LABEL)) - self.keys.append('%s%s' % (firstChildDepth, SEE_ADVANCED_METRICS)) data = getSessionSummaryData() # active code time - activeCodeTimeStr = humanizeMinutes(data["currentDayMinutes"]).strip() - activeCodeTimeAvg = data["averageDailyMinutes"] + activeCodeTimeStr = humanizeMinutes(data.get("currentDayMinutes", 0)).strip() + activeCodeTimeAvg = data.get("averageDailyMinutes", 0) activeCodeTimeAvgStr = humanizeMinutes(activeCodeTimeAvg).strip() self.keys.append('%s%s' % (firstChildDepth, "Active code time: " + activeCodeTimeStr)) @@ -103,7 +101,7 @@ def create_tree(self): if (len(workspaces) > 0): for i in range(len(workspaces)): workspace = workspaces[i] - team_info = json.loads(workspace['meta']).get('team', { 'name': 'slack workspace' }) + team_info = workspace['meta'].get('team', { 'name': 'slack workspace' }) self.keys.append('%s%s' % (secondChildDepth, team_info.get('name'))) else: self.keys.append('%s%s' % (secondChildDepth, '')) @@ -111,7 +109,7 @@ def create_tree(self): self.keys.append('%s%s' % (secondChildDepth, ADD_SLACK_WORKSPACE_LABEL)) def buildTopFilesNode(self, fileChangeInfoMap): - + filesChanged = len(fileChangeInfoMap.keys()) if fileChangeInfoMap else 0 if filesChanged > 0: @@ -121,7 +119,7 @@ def buildTopFilesNode(self, fileChangeInfoMap): def topFilesMetricsNode(self, fileChangeInfos, sortBy, id): if not fileChangeInfos or len(fileChangeInfos) == 0: - return None + return None sortedArr = [] if sortBy == 'duration_seconds' or sortBy == 'kpm' or sortBy == 'keystrokes': @@ -146,8 +144,8 @@ def topFilesMetricsNode(self, fileChangeInfos, sortBy, id): label = '{} | {}'.format(fileName, val) childrenNodes.append(label) - - return childrenNodes + + return childrenNodes def itemSelectionHandler(self, idx): if (idx is not None and idx >= 0): @@ -165,8 +163,6 @@ def itemSelectionHandler(self, idx): launchCodeTimeDashboard() elif (key == UPDATE_PREFERENCES_LABEL): launchUpdatePreferences() - elif (key == SEE_ADVANCED_METRICS): - launchWebDashboardUrl() elif (key == ENABLE_FLOW_MODE): enableFlowMode() elif (key == EXIT_FLOW_MODE): From 928a29a855e774274683be7f8016327a42970abb Mon Sep 17 00:00:00 2001 From: Daniel Alfaro Date: Fri, 12 Apr 2024 13:34:24 -0700 Subject: [PATCH 2/2] Make indentation and tabs consistent --- lib/TrackerManager.py | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/TrackerManager.py b/lib/TrackerManager.py index fa7c5cb..2ab8c0c 100644 --- a/lib/TrackerManager.py +++ b/lib/TrackerManager.py @@ -79,18 +79,18 @@ def codetime_payload(**kwargs): 'iglu:com.software/codetime/jsonschema/1-0-2', { 'keystrokes': kwargs['keystrokes'], - 'lines_added': kwargs['lines_added'], - 'lines_deleted': kwargs['lines_deleted'], - 'characters_added': kwargs['characters_added'], - 'characters_deleted': kwargs['characters_deleted'], - 'single_deletes': kwargs['single_deletes'], - 'multi_deletes': kwargs['multi_deletes'], - 'single_adds': kwargs['single_adds'], - 'multi_adds': kwargs['multi_adds'], - 'auto_indents': kwargs['auto_indents'], - 'replacements': kwargs['replacements'], - 'is_net_change': kwargs['is_net_change'], - 'start_time': datetime.utcfromtimestamp(int(kwargs['start_time'])).isoformat(), + 'lines_added': kwargs['lines_added'], + 'lines_deleted': kwargs['lines_deleted'], + 'characters_added': kwargs['characters_added'], + 'characters_deleted': kwargs['characters_deleted'], + 'single_deletes': kwargs['single_deletes'], + 'multi_deletes': kwargs['multi_deletes'], + 'single_adds': kwargs['single_adds'], + 'multi_adds': kwargs['multi_adds'], + 'auto_indents': kwargs['auto_indents'], + 'replacements': kwargs['replacements'], + 'is_net_change': kwargs['is_net_change'], + 'start_time': datetime.utcfromtimestamp(int(kwargs['start_time'])).isoformat(), 'end_time': datetime.utcfromtimestamp(int(kwargs['end_time'])).isoformat() } ) @@ -117,23 +117,23 @@ def auth_payload(**kwargs): 'iglu:com.software/auth/jsonschema/1-0-0', { 'jwt': kwargs['jwt'] - } - ) + } + ) def file_payload(**kwargs): hashed_name = hash_value(kwargs['file_name'].replace("\\", "/"), 'file_name', kwargs['jwt']) hashed_path = hash_value(kwargs['file_path'], 'file_path', kwargs['jwt']) return SelfDescribingJson( - 'iglu:com.software/file/jsonschema/1-0-1', - { + 'iglu:com.software/file/jsonschema/1-0-1', + { 'file_name': hashed_name, 'file_path': hashed_path, 'syntax': kwargs['syntax'], 'line_count': kwargs['line_count'], 'character_count': kwargs['character_count'] - } - ) + } + ) def plugin_payload(**kwargs): plugin_id = kwargs["plugin_id"] or getPluginId() @@ -176,8 +176,8 @@ def repo_payload(**kwargs): 'owner_id': hashed_owner_id, 'git_branch': hashed_git_branch, 'git_tag': hashed_git_tag - } - ) + } + ) def ui_element_payload(**kwargs): return SelfDescribingJson(