mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
Merge branch 'main' into refactor-sha2
This commit is contained in:
commit
bf15d7c803
9 changed files with 409 additions and 156 deletions
|
|
@ -465,6 +465,7 @@ perform the Xous firmware upgrade. This requires running manual update commands,
|
|||
- `sigchat` moved to its own repo with AGPL licensing: https://github.com/betrusted-io/sigchat
|
||||
- Formatting and contribution standards have been modified. Formatting with `rustfmt` and trailing white space removal is now mandatory for all Xous contributions, see [#477](https://github.com/betrusted-io/xous-core/pull/477) for a discussion of how we got there and why.
|
||||
- The repo has gone through a "flag day" where all the crates have been formatted, which means commits before the flag day may be more difficult to undo. The changes are committed on a crate-by-crate basis, so if something is really broken we can undo the formatting for the crate and add an exception to the rustfmt rules.
|
||||
- Implement #478: backlight should turn on automatically when a U2F/FIDO packet comes in from the host, allowing users in dark conditions to see the screen and know what they are approving.
|
||||
- the `sha2` API has been upgraded from 0.9.9 to 0.10.8. In the process of upgrading this, the `sha2` code is now domiciled in a fork of the `RustCrypto/hashes` repo. This should hopefully make tracking changes on RustCrypto somewhat easier, at the price of some difficulty in maintaining external crate pins (but I think that can be solved with some scripting). In the process of conversion, crates that depend on the 0.9.9 API for acceleration are now not accelerated. In particular, the ed25519-dalek signature check on the gateware at boot now runs with software SHA-512, which means that boot is much slower. This should be fixed before the release is live, but users testing the bleeding edge should be aware of this temporary regression in performance.
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,11 @@
|
|||
"context_name": "App Loader",
|
||||
"menu_name": {
|
||||
"appmenu.app-loader": {
|
||||
"en": "App Loader",
|
||||
"en-tts": "App Loader"
|
||||
"en": "App Loader",
|
||||
"en-tts": "App Loader",
|
||||
"fr": "App Loader *EN*",
|
||||
"ja": "App Loader *EN*",
|
||||
"zh": "App Loader *EN*"
|
||||
}
|
||||
},
|
||||
"submenu": 2
|
||||
|
|
@ -21,6 +24,19 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"chat-test": {
|
||||
"context_name": "Chat UI test",
|
||||
"menu_name": {
|
||||
"appmenu.chat-test": {
|
||||
"en": "Chat UI test",
|
||||
"en-tts": "Chat UI test",
|
||||
"fr": "Chat UI test *EN*",
|
||||
"ja": "Chat UI test *EN*",
|
||||
"zh": "Chat UI test *EN*"
|
||||
}
|
||||
},
|
||||
"submenu": 1
|
||||
},
|
||||
"hello": {
|
||||
"context_name": "Hello World",
|
||||
"menu_name": {
|
||||
|
|
@ -33,6 +49,19 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"mtxchat": {
|
||||
"context_name": "[matrix]",
|
||||
"menu_name": {
|
||||
"appmenu.mtxchat": {
|
||||
"en": "[matrix]",
|
||||
"en-tts": "[matrix]",
|
||||
"fr": "[matrix] *EN*",
|
||||
"ja": "[matrix] *EN*",
|
||||
"zh": "[matrix] *EN*"
|
||||
}
|
||||
},
|
||||
"submenu": 1
|
||||
},
|
||||
"mtxcli": {
|
||||
"context_name": "Matrix cli",
|
||||
"menu_name": {
|
||||
|
|
@ -45,24 +74,6 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"mtxchat": {
|
||||
"context_name": "[matrix]",
|
||||
"menu_name": {
|
||||
"appmenu.mtxchat": {
|
||||
"en": "[matrix]"
|
||||
}
|
||||
},
|
||||
"submenu": 1
|
||||
},
|
||||
"chat-test": {
|
||||
"context_name": "Chat UI test",
|
||||
"menu_name": {
|
||||
"appmenu.chat-test": {
|
||||
"en": "Chat UI test"
|
||||
}
|
||||
},
|
||||
"submenu": 1
|
||||
},
|
||||
"repl": {
|
||||
"context_name": "repl demo app",
|
||||
"menu_name": {
|
||||
|
|
@ -79,11 +90,27 @@
|
|||
"context_name": "signal",
|
||||
"menu_name": {
|
||||
"appmenu.sigchat": {
|
||||
"en": "Signal"
|
||||
"en": "Signal",
|
||||
"en-tts": "Signal",
|
||||
"fr": "Signal *EN*",
|
||||
"ja": "Signal *EN*",
|
||||
"zh": "Signal *EN*"
|
||||
}
|
||||
},
|
||||
"submenu": 1
|
||||
},
|
||||
"transientdisk": {
|
||||
"context_name": "Transient USB disk",
|
||||
"menu_name": {
|
||||
"appmenu.transientdisk": {
|
||||
"en": "Transient USB disk",
|
||||
"en-tts": "Transient USB disk",
|
||||
"fr": "Transient USB disk *EN*",
|
||||
"ja": "Transient USB disk *EN*",
|
||||
"zh": "Transient USB disk *EN*"
|
||||
}
|
||||
}
|
||||
},
|
||||
"vault": {
|
||||
"context_name": "Key Vault",
|
||||
"menu_name": {
|
||||
|
|
@ -96,13 +123,5 @@
|
|||
}
|
||||
},
|
||||
"submenu": 1
|
||||
},
|
||||
"transientdisk": {
|
||||
"context_name": "Transient USB disk",
|
||||
"menu_name": {
|
||||
"appmenu.transientdisk": {
|
||||
"en": "Transient USB disk"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,74 +1,128 @@
|
|||
{
|
||||
"tls.check_trust_prompt": {
|
||||
"en": "Please select trusted certificate authorities.",
|
||||
"en-tts": "Please select trusted certificate authorities."
|
||||
"en-tts": "Please select trusted certificate authorities.",
|
||||
"fr": "Please select trusted certificate authorities. *EN*",
|
||||
"ja": "Please select trusted certificate authorities. *EN*",
|
||||
"zh": "Please select trusted certificate authorities. *EN*"
|
||||
},
|
||||
"tls.cmd": {
|
||||
"en": "net tls <sub-command>",
|
||||
"en-tts": "net tls <sub-command>",
|
||||
"fr": "net tls <sub-command> *EN*",
|
||||
"ja": "net tls <sub-command> *EN*",
|
||||
"zh": "net tls <sub-command> *EN*"
|
||||
},
|
||||
"tls.cmd_help": {
|
||||
"en": "Establishing an encrypted tls connection requires the host to provide a signed Certificate of identity. Each Certificate is signed for authenticity by a Certificate Authority. The CA's Certificate will in-turn be signed by yet another CA. These signed Certificates link into a chain of trust back to a trusted Root CA.\n\nTypically, this all happens automagically because many OS's & browsers incorporate a long list of trusted Root CA Certiicates. And this is OK because you trust the CA's that your OS trusts, right!\n\nOn Precursor, you must explicitly trust one or more root CA Certificates. You can:\nnet tls inspect <host>\n\tto trust a specific CA Certificate, or\nnet tls mozilla\n\tto trust all of the CA Certificates incporporated in the Firefox browser.",
|
||||
"en-tts": "Establishing an encrypted tls connection requires the host to provide a signed Certificate of identity. Each Certificate is signed for authenticity by a Certificate Authority. The CA's Certificate will in-turn be signed by yet another CA. These signed Certificates link into a chain of trust back to a trusted Root CA.\n\nTypically, this all happens automagically because many OS's & browsers incorporate a long list of trusted Root CA Certiicates. And this is OK because you trust the CA's that your OS trusts, right!\n\nOn Precursor, you must explicitly trust one or more root CA Certificates. You can:\nnet tls inspect <host>\n\tto trust a specific CA Certificate, or\nnet tls mozilla\n\tto trust all of the CA Certificates incporporated in the Firefox browser."
|
||||
},
|
||||
"tls.cmd": {
|
||||
"en": "net tls <sub-command>",
|
||||
"en-tts": "net tls <sub-command>"
|
||||
"en-tts": "Establishing an encrypted tls connection requires the host to provide a signed Certificate of identity. Each Certificate is signed for authenticity by a Certificate Authority. The CA's Certificate will in-turn be signed by yet another CA. These signed Certificates link into a chain of trust back to a trusted Root CA.\n\nTypically, this all happens automagically because many OS's & browsers incorporate a long list of trusted Root CA Certiicates. And this is OK because you trust the CA's that your OS trusts, right!\n\nOn Precursor, you must explicitly trust one or more root CA Certificates. You can:\nnet tls inspect <host>\n\tto trust a specific CA Certificate, or\nnet tls mozilla\n\tto trust all of the CA Certificates incporporated in the Firefox browser.",
|
||||
"fr": "Establishing an encrypted tls connection requires the host to provide a signed Certificate of identity. Each Certificate is signed for authenticity by a Certificate Authority. The CA's Certificate will in-turn be signed by yet another CA. These signed Certificates link into a chain of trust back to a trusted Root CA.\n\nTypically, this all happens automagically because many OS's & browsers incorporate a long list of trusted Root CA Certiicates. And this is OK because you trust the CA's that your OS trusts, right!\n\nOn Precursor, you must explicitly trust one or more root CA Certificates. You can:\nnet tls inspect <host>\n\tto trust a specific CA Certificate, or\nnet tls mozilla\n\tto trust all of the CA Certificates incporporated in the Firefox browser. *EN*",
|
||||
"ja": "Establishing an encrypted tls connection requires the host to provide a signed Certificate of identity. Each Certificate is signed for authenticity by a Certificate Authority. The CA's Certificate will in-turn be signed by yet another CA. These signed Certificates link into a chain of trust back to a trusted Root CA.\n\nTypically, this all happens automagically because many OS's & browsers incorporate a long list of trusted Root CA Certiicates. And this is OK because you trust the CA's that your OS trusts, right!\n\nOn Precursor, you must explicitly trust one or more root CA Certificates. You can:\nnet tls inspect <host>\n\tto trust a specific CA Certificate, or\nnet tls mozilla\n\tto trust all of the CA Certificates incporporated in the Firefox browser. *EN*",
|
||||
"zh": "Establishing an encrypted tls connection requires the host to provide a signed Certificate of identity. Each Certificate is signed for authenticity by a Certificate Authority. The CA's Certificate will in-turn be signed by yet another CA. These signed Certificates link into a chain of trust back to a trusted Root CA.\n\nTypically, this all happens automagically because many OS's & browsers incorporate a long list of trusted Root CA Certiicates. And this is OK because you trust the CA's that your OS trusts, right!\n\nOn Precursor, you must explicitly trust one or more root CA Certificates. You can:\nnet tls inspect <host>\n\tto trust a specific CA Certificate, or\nnet tls mozilla\n\tto trust all of the CA Certificates incporporated in the Firefox browser. *EN*"
|
||||
},
|
||||
"tls.deleteall_cmd": {
|
||||
"en": "delete ALL trusted Certificates",
|
||||
"en-tts": "delete ALL trusted Certificates"
|
||||
"en-tts": "delete ALL trusted Certificates",
|
||||
"fr": "delete ALL trusted Certificates *EN*",
|
||||
"ja": "delete ALL trusted Certificates *EN*",
|
||||
"zh": "delete ALL trusted Certificates *EN*"
|
||||
},
|
||||
"tls.deleteall_done": {
|
||||
"en": "deleted Certificates",
|
||||
"en-tts": "deleted Certificates"
|
||||
},
|
||||
"tls.list_cmd": {
|
||||
"en": "list trusted CA certificates",
|
||||
"en-tts": "list trusted CA certificates"
|
||||
},
|
||||
"tls.mozilla_cmd": {
|
||||
"en": "trust all Root CA's in webpki-roots",
|
||||
"en-tts": "trust all Root CA's in webpki-roots"
|
||||
},
|
||||
"tls.mozilla_progress": {
|
||||
"en": "trusting Mozilla Root CA's",
|
||||
"en-tts": "trusting Mozilla Root CA's"
|
||||
},
|
||||
"tls.mozilla_done": {
|
||||
"en": "trusted Root CA's",
|
||||
"en-tts": "trusted Root CA's"
|
||||
"en-tts": "deleted Certificates",
|
||||
"fr": "deleted Certificates *EN*",
|
||||
"ja": "deleted Certificates *EN*",
|
||||
"zh": "deleted Certificates *EN*"
|
||||
},
|
||||
"tls.inspect_cmd": {
|
||||
"en": "save host CA'a if trusted",
|
||||
"en-tts": "save host CA'a if trusted"
|
||||
},
|
||||
"tls.inspect_fail_servername": {
|
||||
"en": "failed to create server name from",
|
||||
"en-tts": "failed to create server name from"
|
||||
},
|
||||
"tls.probe_invalid_certificate": {
|
||||
"en": "Invalid certificate : ",
|
||||
"en-tts": "Invalid certificate : "
|
||||
},
|
||||
"tls.probe_help_not_valid_yet": {
|
||||
"en": "error maybe caused by an improperly set clock",
|
||||
"en-tts": "error maybe caused by an improperly set clock"
|
||||
"en-tts": "save host CA'a if trusted",
|
||||
"fr": "save host CA'a if trusted *EN*",
|
||||
"ja": "save host CA'a if trusted *EN*",
|
||||
"zh": "save host CA'a if trusted *EN*"
|
||||
},
|
||||
"tls.inspect_done": {
|
||||
"en": "trusted CA's",
|
||||
"en-tts": "trusted CA's"
|
||||
"en-tts": "trusted CA's",
|
||||
"fr": "trusted CA's *EN*",
|
||||
"ja": "trusted CA's *EN*",
|
||||
"zh": "trusted CA's *EN*"
|
||||
},
|
||||
"tls.inspect_fail_servername": {
|
||||
"en": "failed to create server name from",
|
||||
"en-tts": "failed to create server name from",
|
||||
"fr": "failed to create server name from *EN*",
|
||||
"ja": "failed to create server name from *EN*",
|
||||
"zh": "failed to create server name from *EN*"
|
||||
},
|
||||
"tls.list_cmd": {
|
||||
"en": "list trusted CA certificates",
|
||||
"en-tts": "list trusted CA certificates",
|
||||
"fr": "list trusted CA certificates *EN*",
|
||||
"ja": "list trusted CA certificates *EN*",
|
||||
"zh": "list trusted CA certificates *EN*"
|
||||
},
|
||||
"tls.mozilla_cmd": {
|
||||
"en": "trust all Root CA's in webpki-roots",
|
||||
"en-tts": "trust all Root CA's in webpki-roots",
|
||||
"fr": "trust all Root CA's in webpki-roots *EN*",
|
||||
"ja": "trust all Root CA's in webpki-roots *EN*",
|
||||
"zh": "trust all Root CA's in webpki-roots *EN*"
|
||||
},
|
||||
"tls.mozilla_done": {
|
||||
"en": "trusted Root CA's",
|
||||
"en-tts": "trusted Root CA's",
|
||||
"fr": "trusted Root CA's *EN*",
|
||||
"ja": "trusted Root CA's *EN*",
|
||||
"zh": "trusted Root CA's *EN*"
|
||||
},
|
||||
"tls.mozilla_progress": {
|
||||
"en": "trusting Mozilla Root CA's",
|
||||
"en-tts": "trusting Mozilla Root CA's",
|
||||
"fr": "trusting Mozilla Root CA's *EN*",
|
||||
"ja": "trusting Mozilla Root CA's *EN*",
|
||||
"zh": "trusting Mozilla Root CA's *EN*"
|
||||
},
|
||||
"tls.probe_help_not_valid_yet": {
|
||||
"en": "error maybe caused by an improperly set clock",
|
||||
"en-tts": "error maybe caused by an improperly set clock",
|
||||
"fr": "error maybe caused by an improperly set clock *EN*",
|
||||
"ja": "error maybe caused by an improperly set clock *EN*",
|
||||
"zh": "error maybe caused by an improperly set clock *EN*"
|
||||
},
|
||||
"tls.probe_invalid_certificate": {
|
||||
"en": "Invalid certificate : ",
|
||||
"en-tts": "Invalid certificate : ",
|
||||
"fr": "Invalid certificate : *EN*",
|
||||
"ja": "Invalid certificate : *EN*",
|
||||
"zh": "Invalid certificate : *EN*"
|
||||
},
|
||||
"tls.test_cmd": {
|
||||
"en": "make tls connection to host",
|
||||
"en-tts": "make tls connection to host"
|
||||
},
|
||||
"tls.test_success_tcp": {
|
||||
"en": "tcp connected\n",
|
||||
"en-tts": "tcp connected"
|
||||
},
|
||||
"tls.test_success_get": {
|
||||
"en": "tls accepted GET\n",
|
||||
"en-tts": "tls accepted GET"
|
||||
"en-tts": "make tls connection to host",
|
||||
"fr": "make tls connection to host *EN*",
|
||||
"ja": "make tls connection to host *EN*",
|
||||
"zh": "make tls connection to host *EN*"
|
||||
},
|
||||
"tls.test_success_bytes": {
|
||||
"en": "tls received bytes",
|
||||
"en-tts": "tls received bytes"
|
||||
"en-tts": "tls received bytes",
|
||||
"fr": "tls received bytes *EN*",
|
||||
"ja": "tls received bytes *EN*",
|
||||
"zh": "tls received bytes *EN*"
|
||||
},
|
||||
"tls.test_success_get": {
|
||||
"en": "tls accepted GET\n",
|
||||
"en-tts": "tls accepted GET",
|
||||
"fr": "tls accepted GET\n *EN*",
|
||||
"ja": "tls accepted GET\n *EN*",
|
||||
"zh": "tls accepted GET\n *EN*"
|
||||
},
|
||||
"tls.test_success_tcp": {
|
||||
"en": "tcp connected\n",
|
||||
"en-tts": "tcp connected",
|
||||
"fr": "tcp connected\n *EN*",
|
||||
"ja": "tcp connected\n *EN*",
|
||||
"zh": "tcp connected\n *EN*"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -18,16 +18,30 @@ type Locale = String;
|
|||
type Value = String;
|
||||
type Translations = HashMap<Key, HashMap<Locale, Value>>;
|
||||
|
||||
macro_rules! build_debug {
|
||||
($($tokens: tt)*) => {
|
||||
println!("cargo:warning={}", format!($($tokens)*))
|
||||
}
|
||||
}
|
||||
|
||||
fn read_locales() -> Translations {
|
||||
let mut translations: Translations = HashMap::new();
|
||||
|
||||
let project_dir = project_root();
|
||||
let mut project_dir = project_root();
|
||||
let build_directory = project_dir.to_str().unwrap();
|
||||
let locales = format!("{}/**/i18n.json", build_directory);
|
||||
println!("Reading {}", &locales);
|
||||
|
||||
for entry in glob(&locales).expect("Failed to read glob pattern") {
|
||||
build_debug!("Reading {}", &locales);
|
||||
// TODO: once this works, get from external directory/location arguments from xtask script
|
||||
project_dir.pop(); //sibling directory
|
||||
project_dir.push("sigchat");
|
||||
let external_directory = project_dir.to_str().unwrap();
|
||||
let external_locales = format!("{}/**/i18n.json", external_directory);
|
||||
build_debug!("Reading external {}", &external_locales);
|
||||
let paths = glob(&locales).expect("Failed to read glob pattern for in tree fiels");
|
||||
let external_paths = glob(&external_locales).expect("Filed to read glob pattern for external files");
|
||||
for entry in paths.chain(external_paths) {
|
||||
let entry = entry.unwrap();
|
||||
build_debug!("{:?}",entry);
|
||||
println!("cargo:rerun-if-changed={}", entry.display());
|
||||
let file = File::open(entry).expect("Failed to open the file");
|
||||
let mut reader = std::io::BufReader::new(file);
|
||||
|
|
|
|||
|
|
@ -223,8 +223,10 @@ fn wrapped_main() -> ! {
|
|||
// ------------------ lay out our public API infrastructure
|
||||
// ok, now that we have a GID, we can continue on with our merry way
|
||||
let status_gid: Gid = Gid::new(canvas_gid);
|
||||
// allow only one connection, from keyboard to us.
|
||||
let status_sid = xns.register_name(SERVER_NAME_STATUS, Some(1)).unwrap();
|
||||
// Expected connections:
|
||||
// - from keyboard
|
||||
// - from USB HID
|
||||
let status_sid = xns.register_name(SERVER_NAME_STATUS, Some(2)).unwrap();
|
||||
// create a connection for callback hooks
|
||||
let cb_cid = xous::connect(status_sid).unwrap();
|
||||
unsafe { CB_TO_MAIN_CONN = Some(cb_cid) };
|
||||
|
|
@ -395,6 +397,9 @@ fn wrapped_main() -> ! {
|
|||
kbd.lock()
|
||||
.unwrap()
|
||||
.register_observer(SERVER_NAME_STATUS, StatusOpcode::Keypress.to_u32().unwrap() as usize);
|
||||
// register the USB U2F event listener - point to the same handler as key press since our intention is to
|
||||
// just toggle the backlight
|
||||
usb_hid.register_u2f_observer(SERVER_NAME_STATUS, StatusOpcode::Keypress.to_u32().unwrap() as usize);
|
||||
|
||||
let autobacklight_enabled = Arc::new(Mutex::new(true));
|
||||
let (tx, rx): (Sender<BacklightThreadOps>, Receiver<BacklightThreadOps>) = unbounded();
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ pub(crate) enum Opcode {
|
|||
DebugUsbOp = 9,
|
||||
/// Set autotype rate
|
||||
SetAutotypeRate = 10,
|
||||
/// Register a USB event observer
|
||||
RegisterUsbObserver = 11,
|
||||
|
||||
/// Send a U2F message
|
||||
U2fTx = 128,
|
||||
|
|
@ -139,3 +141,10 @@ pub struct UsbSerialBinary {
|
|||
pub d: [u8; SERIAL_BINARY_BUFLEN],
|
||||
pub len: usize,
|
||||
}
|
||||
|
||||
/// this structure is used to register a USB listener.
|
||||
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone)]
|
||||
pub(crate) struct UsbListenerRegistration {
|
||||
pub server_name: xous_ipc::String<64>,
|
||||
pub listener_op_id: usize,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -370,6 +370,16 @@ impl UsbHid {
|
|||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
pub fn register_u2f_observer(&self, server_name: &str, action_opcode: usize) {
|
||||
let kr = UsbListenerRegistration {
|
||||
server_name: xous_ipc::String::<64>::from_str(server_name),
|
||||
listener_op_id: action_opcode,
|
||||
};
|
||||
let buf = Buffer::into_buf(kr).unwrap();
|
||||
buf.lend(self.conn, Opcode::RegisterUsbObserver.to_u32().unwrap())
|
||||
.expect("couldn't register listener");
|
||||
}
|
||||
}
|
||||
|
||||
use core::sync::atomic::{AtomicU32, Ordering};
|
||||
|
|
|
|||
|
|
@ -294,6 +294,10 @@ pub(crate) fn main_hw() -> ! {
|
|||
let mut was_suspend = true;
|
||||
let mut autotype_delay_ms = 30;
|
||||
|
||||
// event observer connection
|
||||
let mut observer_conn: Option<xous::CID> = None;
|
||||
let mut observer_op: Option<usize> = None;
|
||||
|
||||
#[cfg(feature = "minimal")]
|
||||
std::thread::spawn(move || {
|
||||
// this keeps the watchdog alive in minimal mode; if there's no event, eventually the watchdog times
|
||||
|
|
@ -492,6 +496,15 @@ pub(crate) fn main_hw() -> ! {
|
|||
xous::return_scalar(msg.sender, 1).expect("couldn't return compatibility status")
|
||||
}),
|
||||
Some(Opcode::U2fRxDeferred) => {
|
||||
// notify the event listener, if any
|
||||
if observer_conn.is_some() && observer_op.is_some() {
|
||||
xous::try_send_message(
|
||||
observer_conn.unwrap(),
|
||||
xous::Message::new_scalar(observer_op.unwrap(), 0, 0, 0, 0),
|
||||
)
|
||||
.ok();
|
||||
}
|
||||
|
||||
if fido_listener_pid.is_none() {
|
||||
fido_listener_pid = msg.sender.pid();
|
||||
}
|
||||
|
|
@ -1537,6 +1550,23 @@ pub(crate) fn main_hw() -> ! {
|
|||
serial_trng_interval.store(TRNG_REFILL_DELAY_MS, Ordering::SeqCst);
|
||||
}
|
||||
}
|
||||
Some(Opcode::RegisterUsbObserver) => {
|
||||
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||
let ur = buffer.as_flat::<UsbListenerRegistration, _>().unwrap();
|
||||
if observer_conn.is_none() {
|
||||
match xns.request_connection_blocking(ur.server_name.as_str()) {
|
||||
Ok(cid) => {
|
||||
observer_conn = Some(cid);
|
||||
observer_op = Some(ur.listener_op_id as usize);
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("couldn't connect to observer: {:?}", e);
|
||||
observer_conn = None;
|
||||
observer_op = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(Opcode::Quit) => {
|
||||
log::warn!("Quit received, goodbye world!");
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -8,42 +8,72 @@ import os.path
|
|||
import pwd
|
||||
import re
|
||||
|
||||
class Main(object):
|
||||
|
||||
class Main(object):
|
||||
def __init__(self):
|
||||
parser = argparse.ArgumentParser(description="Xous i18n Helper")
|
||||
parser.add_argument('-v', '--verbose',
|
||||
help='Prints details of each action',
|
||||
action='store_true', required=False)
|
||||
parser.add_argument('-l', '--list-languages',
|
||||
help='Lists current translations',
|
||||
action='store_true', required=False)
|
||||
parser.add_argument('-i', '--list-i18n-files',
|
||||
help='Lists i18n files',
|
||||
action='store_true', required=False)
|
||||
parser.add_argument('-m', '--missing',
|
||||
help='Shows missing translations',
|
||||
action='store_true', required=False)
|
||||
parser.add_argument('-o', '--show-ok',
|
||||
help='Shows OK translations',
|
||||
action='store_true', required=False)
|
||||
parser.add_argument('-n', '--new-lang',
|
||||
help='Add support for a new lang',
|
||||
required=False)
|
||||
parser.add_argument('-f', '--from-lang',
|
||||
help='Copy this existing lang for the new lang',
|
||||
required=False)
|
||||
parser.add_argument(
|
||||
"-v",
|
||||
"--verbose",
|
||||
help="Prints details of each action",
|
||||
action="store_true",
|
||||
required=False,
|
||||
)
|
||||
parser.add_argument(
|
||||
"-l",
|
||||
"--list-languages",
|
||||
help="Lists current translations",
|
||||
action="store_true",
|
||||
required=False,
|
||||
)
|
||||
parser.add_argument(
|
||||
"-i",
|
||||
"--list-i18n-files",
|
||||
help="Lists i18n files",
|
||||
action="store_true",
|
||||
required=False,
|
||||
)
|
||||
parser.add_argument(
|
||||
"-m",
|
||||
"--missing",
|
||||
help="Shows missing translations",
|
||||
action="store_true",
|
||||
required=False,
|
||||
)
|
||||
parser.add_argument(
|
||||
"-o",
|
||||
"--show-ok",
|
||||
help="Shows OK translations",
|
||||
action="store_true",
|
||||
required=False,
|
||||
)
|
||||
parser.add_argument(
|
||||
"-n", "--new-lang", help="Add support for a new lang", required=False
|
||||
)
|
||||
parser.add_argument(
|
||||
"-f",
|
||||
"--from-lang",
|
||||
help="Copy this existing lang for the new lang",
|
||||
required=False,
|
||||
)
|
||||
parser.add_argument(
|
||||
"-s",
|
||||
"--stub",
|
||||
help="fills in all missing translation with stub from EN",
|
||||
action="store_true",
|
||||
required=False,
|
||||
)
|
||||
self.args = parser.parse_args()
|
||||
self.args.program = sys.argv[0]
|
||||
if self.args.program[0] != '/':
|
||||
if self.args.program[0] != "/":
|
||||
self.args.program = os.path.join(os.getcwd(), self.args.program)
|
||||
self.args.pdir = os.path.normpath(os.path.dirname(self.args.program))
|
||||
self.args.xousdir = os.path.normpath(os.path.dirname(self.args.pdir))
|
||||
self.args.program = os.path.basename(self.args.program)
|
||||
self.errfile = sys.stderr
|
||||
# if end of string matches ' *EN*' (or some other lang)
|
||||
self.temp_regex = re.compile('^.* \*[a-zA-Z]{2}\*$')
|
||||
self.mt_regex = re.compile('^.* \*MT\*$')
|
||||
self.temp_regex = re.compile("^.* \*[a-zA-Z]{2}\*$")
|
||||
self.mt_regex = re.compile("^.* \*MT\*$")
|
||||
|
||||
def out(self, *objects):
|
||||
print(*objects)
|
||||
|
|
@ -56,15 +86,19 @@ class Main(object):
|
|||
self.err(*objects)
|
||||
|
||||
def get_languages(self):
|
||||
self.verr('-- get languages --')
|
||||
self.verr("-- get languages --")
|
||||
# services/root-keys/locales/i18n.json
|
||||
root_keys = os.path.join(self.args.xousdir, 'services', 'root-keys', 'locales', 'i18n.json')
|
||||
root_keys = os.path.join(
|
||||
self.args.xousdir, "services", "root-keys", "locales", "i18n.json"
|
||||
)
|
||||
if not os.path.exists(root_keys):
|
||||
self.err('cannot find: %s' % root_keys);
|
||||
self.err("cannot find: %s" % root_keys)
|
||||
return 1
|
||||
# read keys in "rootkeys.backup_key":
|
||||
essential = 'rootkeys.backup_key'
|
||||
f = open(root_keys,)
|
||||
essential = "rootkeys.backup_key"
|
||||
f = open(
|
||||
root_keys,
|
||||
)
|
||||
obj = json.load(f)
|
||||
self.languages = []
|
||||
if essential in obj:
|
||||
|
|
@ -76,34 +110,37 @@ class Main(object):
|
|||
def list_languages(self):
|
||||
if self.get_languages() != 0:
|
||||
return 1
|
||||
self.verr('-- list languages --')
|
||||
self.verr("-- list languages --")
|
||||
for lang in self.languages:
|
||||
self.out(lang)
|
||||
return 0
|
||||
|
||||
def get_i18n_files(self):
|
||||
self.verr('-- get i18n files --')
|
||||
self.verr("-- get i18n files --")
|
||||
self.i18n_files = []
|
||||
topdirs = ['apps', 'services']
|
||||
topdirs = ["apps", "services", "libs"]
|
||||
# TODO: use glob to replicate exactly how rust looks for them.
|
||||
for top in topdirs:
|
||||
topdir = os.path.join(self.args.xousdir, top)
|
||||
if os.path.exists(topdir):
|
||||
if top == 'apps':
|
||||
manifest = os.path.join(topdir, 'manifest.json')
|
||||
if top == "apps":
|
||||
manifest = os.path.join(topdir, "manifest.json")
|
||||
if os.path.exists(manifest):
|
||||
self.i18n_files.append(manifest[len(self.args.xousdir)+1:])
|
||||
self.i18n_files.append(manifest[len(self.args.xousdir) + 1 :])
|
||||
for thing in os.listdir(topdir):
|
||||
thingdir = os.path.join(topdir, thing)
|
||||
if os.path.isdir(thingdir):
|
||||
i18n_path = os.path.join(thingdir, 'locales', 'i18n.json')
|
||||
i18n_path = os.path.join(thingdir, "locales", "i18n.json")
|
||||
if os.path.exists(i18n_path):
|
||||
self.i18n_files.append(i18n_path[len(self.args.xousdir)+1:])
|
||||
self.i18n_files.append(
|
||||
i18n_path[len(self.args.xousdir) + 1 :]
|
||||
)
|
||||
return 0
|
||||
|
||||
def list_i18n_files(self):
|
||||
if self.get_i18n_files() != 0:
|
||||
return 1
|
||||
self.verr('-- list i18n files --')
|
||||
self.verr("-- list i18n files --")
|
||||
for pathname in self.i18n_files:
|
||||
self.out(pathname)
|
||||
return 0
|
||||
|
|
@ -113,36 +150,88 @@ class Main(object):
|
|||
# other TAG
|
||||
def show_missing(self, i18n, is_manifest):
|
||||
i18n_path = os.path.join(self.args.xousdir, i18n)
|
||||
f = open(i18n_path,)
|
||||
f = open(
|
||||
i18n_path,
|
||||
)
|
||||
obj = json.load(f)
|
||||
f.close()
|
||||
jqpath = None
|
||||
translation = None
|
||||
for tag in obj.keys():
|
||||
if is_manifest:
|
||||
appmenu = 'appmenu.' + tag
|
||||
jqpath = tag + '.menu_name.' + appmenu
|
||||
translation = obj[tag]['menu_name'][appmenu]
|
||||
appmenu = "appmenu." + tag
|
||||
jqpath = tag + ".menu_name." + appmenu
|
||||
translation = obj[tag]["menu_name"][appmenu]
|
||||
else:
|
||||
jqpath = tag
|
||||
translation = obj[tag]
|
||||
for lang in self.languages:
|
||||
lang_path = jqpath + '.' + lang
|
||||
status = 'OK'
|
||||
lang_path = jqpath + "." + lang
|
||||
status = "OK"
|
||||
if lang in translation:
|
||||
t = translation[lang]
|
||||
# to print translation
|
||||
# print('%s\t%s\t%s' % (i18n, lang_path, t))
|
||||
if t == '🔇':
|
||||
status = 'MISSING'
|
||||
if t == "🔇":
|
||||
status = "MISSING"
|
||||
elif self.mt_regex.fullmatch(t):
|
||||
status = 'MACHINE_TRANSLATION'
|
||||
status = "MACHINE_TRANSLATION"
|
||||
elif self.temp_regex.fullmatch(t):
|
||||
status = 'TEMPORARY'
|
||||
status = "TEMPORARY"
|
||||
else:
|
||||
status = 'ABSENT'
|
||||
if self.args.show_ok or status != 'OK':
|
||||
print('%s\t%s\t%s' % (i18n, lang_path, status))
|
||||
status = "ABSENT"
|
||||
if self.args.show_ok or status != "OK":
|
||||
print("%s\t%s\t%s" % (i18n, lang_path, status))
|
||||
return 0
|
||||
|
||||
def stub_missing(self, i18n, is_manifest):
|
||||
i18n_path = os.path.join(self.args.xousdir, i18n)
|
||||
f = open(
|
||||
i18n_path,
|
||||
)
|
||||
obj = json.load(f)
|
||||
f.close()
|
||||
jqpath = None
|
||||
translation = None
|
||||
for tag in obj.keys():
|
||||
if is_manifest:
|
||||
appmenu = "appmenu." + tag
|
||||
jqpath = tag + ".menu_name." + appmenu
|
||||
translation = obj[tag]["menu_name"][appmenu]
|
||||
else:
|
||||
jqpath = tag
|
||||
translation = obj[tag]
|
||||
for lang in self.languages:
|
||||
lang_path = jqpath + "." + lang
|
||||
if not lang in translation:
|
||||
if lang == "en-tts":
|
||||
stub = translation['en']}
|
||||
else:
|
||||
stub = f"{translation['en']} *EN*"
|
||||
print(f"In {i18n}, at {lang_path} with en stub: {stub}")
|
||||
translation[lang] = stub
|
||||
# blow 'em away. That's what git is for after all.
|
||||
with open(i18n_path, "w") as f:
|
||||
json.dump(
|
||||
obj,
|
||||
f,
|
||||
ensure_ascii=False,
|
||||
check_circular=False,
|
||||
sort_keys=True,
|
||||
indent=4,
|
||||
)
|
||||
return 0
|
||||
|
||||
def fill_missing_with_en_stub(self):
|
||||
if self.get_languages() != 0:
|
||||
return 1
|
||||
if self.get_i18n_files() != 0:
|
||||
return 1
|
||||
self.verr("-- filling missing --")
|
||||
for i18n in self.i18n_files:
|
||||
is_manifest = os.path.basename(i18n) == "manifest.json"
|
||||
if self.stub_missing(i18n, is_manifest) != 0:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
def missing(self):
|
||||
|
|
@ -150,9 +239,9 @@ class Main(object):
|
|||
return 1
|
||||
if self.get_i18n_files() != 0:
|
||||
return 1
|
||||
self.verr('-- missing --')
|
||||
self.verr("-- missing --")
|
||||
for i18n in self.i18n_files:
|
||||
is_manifest = os.path.basename(i18n) == 'manifest.json'
|
||||
is_manifest = os.path.basename(i18n) == "manifest.json"
|
||||
if self.show_missing(i18n, is_manifest) != 0:
|
||||
return 1
|
||||
return 0
|
||||
|
|
@ -162,38 +251,49 @@ class Main(object):
|
|||
# other TAG
|
||||
def add_new_lang(self, i18n, is_manifest):
|
||||
i18n_path = os.path.join(self.args.xousdir, i18n)
|
||||
i18n_path_orig = i18n_path + '.orig'
|
||||
i18n_path_orig = i18n_path + ".orig"
|
||||
if not os.path.exists(i18n_path_orig):
|
||||
os.rename(i18n_path, i18n_path_orig)
|
||||
self.verr('adding "%s" to %s' % (self.args.new_lang, i18n))
|
||||
orig_file = open(i18n_path_orig,)
|
||||
orig_file = open(
|
||||
i18n_path_orig,
|
||||
)
|
||||
obj = json.load(orig_file)
|
||||
orig_file.close()
|
||||
new_file = open(i18n_path,'w')
|
||||
new_file = open(i18n_path, "w")
|
||||
translation = None
|
||||
for tag in obj.keys():
|
||||
if is_manifest:
|
||||
appmenu = 'appmenu.' + tag
|
||||
translation = obj[tag]['menu_name'][appmenu]
|
||||
appmenu = "appmenu." + tag
|
||||
translation = obj[tag]["menu_name"][appmenu]
|
||||
else:
|
||||
translation = obj[tag]
|
||||
t_from = translation[self.args.from_lang]
|
||||
t_new = t_from
|
||||
if t_from != '🔇':
|
||||
if t_from != "🔇":
|
||||
t_new += self.from_hint
|
||||
translation[self.args.new_lang] = t_new
|
||||
json.dump(obj, new_file, ensure_ascii=False, check_circular=False,
|
||||
sort_keys=True, indent=4)
|
||||
json.dump(
|
||||
obj,
|
||||
new_file,
|
||||
ensure_ascii=False,
|
||||
check_circular=False,
|
||||
sort_keys=True,
|
||||
indent=4,
|
||||
)
|
||||
new_file.close()
|
||||
return 0
|
||||
|
||||
def new_lang(self):
|
||||
if self.get_i18n_files() != 0:
|
||||
return 1
|
||||
self.from_hint = ' *%s*' % self.args.from_lang.upper()
|
||||
self.verr('-- adding new lang "%s" from "%s" by appending "%s" --' % (self.args.new_lang, self.args.from_lang, self.from_hint))
|
||||
self.from_hint = " *%s*" % self.args.from_lang.upper()
|
||||
self.verr(
|
||||
'-- adding new lang "%s" from "%s" by appending "%s" --'
|
||||
% (self.args.new_lang, self.args.from_lang, self.from_hint)
|
||||
)
|
||||
for i18n in self.i18n_files:
|
||||
is_manifest = os.path.basename(i18n) == 'manifest.json'
|
||||
is_manifest = os.path.basename(i18n) == "manifest.json"
|
||||
if self.add_new_lang(i18n, is_manifest) != 0:
|
||||
return 1
|
||||
return 0
|
||||
|
|
@ -201,7 +301,7 @@ class Main(object):
|
|||
def run(self):
|
||||
rc = 0
|
||||
if self.args.verbose:
|
||||
self.err('verbose mode')
|
||||
self.err("verbose mode")
|
||||
self.err('xous dir: "%s"' % self.args.xousdir)
|
||||
self.err('program dir: "%s"' % self.args.pdir)
|
||||
self.err('program: "%s"' % self.args.program)
|
||||
|
|
@ -209,27 +309,38 @@ class Main(object):
|
|||
if self.args.list_languages:
|
||||
rc = self.list_languages()
|
||||
elif self.args.list_i18n_files:
|
||||
rc = self.list_i18n_files()
|
||||
rc = self.list_i18n_files()
|
||||
elif self.args.missing:
|
||||
rc = self.missing()
|
||||
elif self.args.stub:
|
||||
rc = self.fill_missing_with_en_stub()
|
||||
elif self.args.new_lang:
|
||||
if not self.args.from_lang:
|
||||
self.err('error: you must specify both --from-lang en --to-lang fr')
|
||||
self.err("error: you must specify both --from-lang en --to-lang fr")
|
||||
rc = 1
|
||||
else:
|
||||
self.get_languages()
|
||||
if not self.args.from_lang in self.languages:
|
||||
self.err('error: --from-lang %s is not one of the existing langs: %s' % (self.args.from_lang, self.languages))
|
||||
self.err(
|
||||
"error: --from-lang %s is not one of the existing langs: %s"
|
||||
% (self.args.from_lang, self.languages)
|
||||
)
|
||||
rc = 1
|
||||
elif self.args.new_lang in self.languages:
|
||||
self.err('error: --new-lang %s must not be one of the existing langs: %s' % (self.args.from_lang, self.languages))
|
||||
self.err(
|
||||
"error: --new-lang %s must not be one of the existing langs: %s"
|
||||
% (self.args.from_lang, self.languages)
|
||||
)
|
||||
rc = 1
|
||||
elif not re.fullmatch('^[a-z-]{2,6}$', self.args.new_lang):
|
||||
self.err('error: --new-lang %s is not valid lang' % self.args.new_lang)
|
||||
elif not re.fullmatch("^[a-z-]{2,6}$", self.args.new_lang):
|
||||
self.err(
|
||||
"error: --new-lang %s is not valid lang" % self.args.new_lang
|
||||
)
|
||||
rc = 1
|
||||
else:
|
||||
rc = self.new_lang()
|
||||
return rc
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(Main().run())
|
||||
|
|
|
|||
Loading…
Reference in a new issue