|
2 | 2 | import functools |
3 | 3 | import json |
4 | 4 | import os |
| 5 | +import sys |
5 | 6 | import time |
6 | 7 |
|
7 | | -from constants import CLOUD_HERO_CACHE_OPTIONS, NotFound |
| 8 | +from lib.constants import CLOUD_HERO_CACHE_OPTIONS, CLOUD_HERO_HISTORY, NotFound |
8 | 9 |
|
9 | 10 |
|
10 | 11 | def write_to_file(content, file_path, is_json=False): |
@@ -68,14 +69,6 @@ def invalidate_cache(*file_paths): |
68 | 69 | def wrap(func): |
69 | 70 | @functools.wraps(func) |
70 | 71 | def wrapper(*args, **kwargs): |
71 | | - for file_path in file_paths: |
72 | | - expanded_file_path = os.path.expanduser(file_path) |
73 | | - try: |
74 | | - os.remove(expanded_file_path) |
75 | | - except OSError as exc: |
76 | | - if exc.errno == errno.ENOENT: |
77 | | - continue |
78 | | - raise |
79 | 72 | return func(*args, **kwargs) |
80 | 73 | return wrapper |
81 | 74 | return wrap |
@@ -124,3 +117,20 @@ def get_docker_ip_for_environment(node_details, environment_id): |
124 | 117 |
|
125 | 118 | if environment_found is False: |
126 | 119 | raise NotFound('Environment {} not found!'.format(environment_id)) |
| 120 | + |
| 121 | + |
| 122 | +def update_history(cloud_hero): |
| 123 | + user_command = ' '.join(sys.argv) |
| 124 | + timestamp = int(time.time()) |
| 125 | + content = read_from_file(CLOUD_HERO_HISTORY, is_json=True) |
| 126 | + |
| 127 | + command_history = (user_command, timestamp) |
| 128 | + if not content: |
| 129 | + content = [command_history] |
| 130 | + else: |
| 131 | + content.append(command_history) |
| 132 | + if len(content) > 10: |
| 133 | + cloud_hero.send_history(content) |
| 134 | + content = None |
| 135 | + |
| 136 | + write_to_file(content, CLOUD_HERO_HISTORY, is_json=True) |
0 commit comments