forked from microsoft/vscode-python-devicesimulator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
67 lines (45 loc) · 1.63 KB
/
Copy pathutils.py
File metadata and controls
67 lines (45 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from . import constants as CONSTANTS
import json
import copy
import time
import sys
previous_state = {}
abs_path_to_user_file = ""
debug_mode = False
def update_state_with_device_name(state, device_name):
updated_state = dict(state)
state_ext = {
"device_name": device_name,
}
updated_state.update(state_ext)
return updated_state
def create_message(msg, send_type="state"):
if isinstance(msg, dict):
msg = json.dumps(msg)
message = {"type": send_type, "data": msg}
return message
def send_to_simulator(state, device_name):
global previous_state
updated_state = update_state_with_device_name(state, device_name)
message = create_message(updated_state)
if updated_state != previous_state:
previous_state = copy.deepcopy(updated_state)
print(json.dumps(message) + "\0", end="", file=sys.__stdout__, flush=True)
time.sleep(CONSTANTS.TIME_DELAY)
def send_print_to_simulator(raw_msg):
data_str = str(raw_msg)
message = create_message(data_str, "print")
print(json.dumps(message) + "\0", file=sys.__stdout__, flush=True)
time.sleep(CONSTANTS.TIME_DELAY)
def remove_leading_slashes(string):
string = string.lstrip("\\/")
return string
def escape_if_OSX(file_name):
if sys.platform == CONSTANTS.MAC_OS:
file_name = file_name.replace(" ", "%20")
return file_name
def print_for_unimplemented_functions(function_name):
msg = f"'{function_name}' is not implemented in the simulator but it will work on the actual device!\n"
send_print_to_simulator(msg)