From 4c29b05b53e0191bb0458f443849040354334275 Mon Sep 17 00:00:00 2001 From: ArtichOwO Date: Mon, 21 Jun 2021 19:34:26 +0200 Subject: [PATCH 1/4] [MPY/MOD/OS] Added "name" attribute, "getlogin()" function and "username" key in "uname()" "os.name" returns either "Omega" (only if OMEGA_VERSION is defined) or "Epsilon" "os.getlogin()" returns the calculator owner username "os.uname()" returns an object which has now the "username" attribute --- python/port/genhdr/qstrdefs.in.h | 2 ++ python/port/mod/os/modos.cpp | 11 +++++++++++ python/port/mod/os/modos.h | 1 + python/port/mod/os/modos_table.c | 13 +++++++++++++ 4 files changed, 27 insertions(+) diff --git a/python/port/genhdr/qstrdefs.in.h b/python/port/genhdr/qstrdefs.in.h index c580bcb8e..b385aa63b 100644 --- a/python/port/genhdr/qstrdefs.in.h +++ b/python/port/genhdr/qstrdefs.in.h @@ -537,11 +537,13 @@ Q(SEEK_END) // os QSTRs Q(os) Q(uname) +Q(getlogin) Q(sysname) Q(nodename) Q(release) Q(version) Q(machine) +Q(username) Q(rename) Q(listdir) diff --git a/python/port/mod/os/modos.cpp b/python/port/mod/os/modos.cpp index 6bf5124d1..b32d9a3d8 100644 --- a/python/port/mod/os/modos.cpp +++ b/python/port/mod/os/modos.cpp @@ -32,12 +32,19 @@ STATIC const MP_DEFINE_STR_OBJ(modos_uname_info_machine_obj, "NumWorks N0100"); STATIC const MP_DEFINE_STR_OBJ(modos_uname_info_machine_obj, "NumWorks Simulator"); #endif +#if defined(OMEGA_USERNAME) +STATIC const MP_DEFINE_STR_OBJ(modos_uname_info_username_obj, MP_STRINGIFY(OMEGA_USERNAME)); +#else +STATIC const MP_DEFINE_STR_OBJ(modos_uname_info_username_obj, ""); +#endif + STATIC const mp_rom_map_elem_t modos_uname_info_table[] = { { MP_ROM_QSTR(MP_QSTR_sysname), &modos_uname_info_sysname_obj }, { MP_ROM_QSTR(MP_QSTR_nodename), &modos_uname_info_nodename_obj }, { MP_ROM_QSTR(MP_QSTR_release), &modos_uname_info_release_obj }, { MP_ROM_QSTR(MP_QSTR_version), &modos_uname_info_version_obj }, { MP_ROM_QSTR(MP_QSTR_machine), &modos_uname_info_machine_obj }, + { MP_ROM_QSTR(MP_QSTR_username), &modos_uname_info_username_obj }, }; STATIC MP_DEFINE_CONST_DICT(modos_uname_info_obj, modos_uname_info_table); @@ -46,6 +53,10 @@ mp_obj_t modos_uname(void) { return (mp_obj_t)&modos_uname_info_obj; } +mp_obj_t modos_getlogin(void) { + return (mp_obj_t)&modos_uname_info_username_obj; +} + mp_obj_t modos_remove(mp_obj_t o_file_name) { size_t len; diff --git a/python/port/mod/os/modos.h b/python/port/mod/os/modos.h index 713c81309..0e9da4b98 100644 --- a/python/port/mod/os/modos.h +++ b/python/port/mod/os/modos.h @@ -1,6 +1,7 @@ #include mp_obj_t modos_uname(); +mp_obj_t modos_getlogin(); mp_obj_t modos_remove(mp_obj_t o_file_name); mp_obj_t modos_rename(mp_obj_t o_old_name, mp_obj_t o_new_name); mp_obj_t modos_listdir(); diff --git a/python/port/mod/os/modos_table.c b/python/port/mod/os/modos_table.c index 723720ce4..20106bb2d 100644 --- a/python/port/mod/os/modos_table.c +++ b/python/port/mod/os/modos_table.c @@ -1,16 +1,29 @@ #include "modos.h" +#include +#include +#include + MP_DEFINE_CONST_FUN_OBJ_0(modos_uname_obj, modos_uname); +MP_DEFINE_CONST_FUN_OBJ_0(modos_getlogin_obj, modos_getlogin); MP_DEFINE_CONST_FUN_OBJ_1(modos_remove_obj, modos_remove); MP_DEFINE_CONST_FUN_OBJ_2(modos_rename_obj, modos_rename); MP_DEFINE_CONST_FUN_OBJ_0(modos_listdir_obj, modos_listdir); +#ifdef OMEGA_VERSION +STATIC const MP_DEFINE_STR_OBJ(modos_sysname_obj, "Omega"); +#else +STATIC const MP_DEFINE_STR_OBJ(modos_sysname_obj, "Epsilon"); +#endif + STATIC const mp_rom_map_elem_t modos_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_os) }, { MP_ROM_QSTR(MP_QSTR_uname), &modos_uname_obj}, + { MP_ROM_QSTR(MP_QSTR_getlogin), &modos_getlogin_obj}, { MP_ROM_QSTR(MP_QSTR_remove), &modos_remove_obj}, { MP_ROM_QSTR(MP_QSTR_rename), &modos_rename_obj}, { MP_ROM_QSTR(MP_QSTR_listdir), &modos_listdir_obj}, + { MP_ROM_QSTR(MP_QSTR_name), &modos_sysname_obj} }; STATIC MP_DEFINE_CONST_DICT(modos_module_globals, modos_module_globals_table); From ba94c7db009411ce610bb844eb3dbcb8e21ecb18 Mon Sep 17 00:00:00 2001 From: ArtichOwO Date: Mon, 21 Jun 2021 23:24:50 +0200 Subject: [PATCH 2/4] [Code/Toolbox] Added "getlogin()" to code toolbox --- apps/code/catalog.de.i18n | 1 + apps/code/catalog.en.i18n | 1 + apps/code/catalog.es.i18n | 1 + apps/code/catalog.fr.i18n | 1 + apps/code/catalog.hu.i18n | 1 + apps/code/catalog.it.i18n | 1 + apps/code/catalog.nl.i18n | 1 + apps/code/catalog.pt.i18n | 1 + apps/code/catalog.universal.i18n | 1 + apps/code/python_toolbox.cpp | 1 + 10 files changed, 10 insertions(+) diff --git a/apps/code/catalog.de.i18n b/apps/code/catalog.de.i18n index 9cb321ab8..325dd7975 100644 --- a/apps/code/catalog.de.i18n +++ b/apps/code/catalog.de.i18n @@ -72,6 +72,7 @@ PythonImportMath = "math Modul importieren" PythonImportMatplotlibPyplot = "Import matplotlib.pyplot module" PythonImportOs = "os Modul importieren" PythonOsUname = "Informieren Sie sich über das System" +PythonOsGetlogin = "Get username" PythonOsRemove = "Datei namens Dateiname entfernen" PythonOsRename = "Datei mit altem Namen in neuen Namen umbenennen" PythonOsListdir = "Dateien im Speicher auflisten" diff --git a/apps/code/catalog.en.i18n b/apps/code/catalog.en.i18n index 819887dbb..a58ff5804 100644 --- a/apps/code/catalog.en.i18n +++ b/apps/code/catalog.en.i18n @@ -153,6 +153,7 @@ PythonUniform = "Floating point number in [a,b]" PythonImportTime = "Import time module" PythonImportOs = "Import os module" PythonOsUname = "Get infos about the system" +PythonOsGetlogin = "Get username" PythonOsRemove = "Remove file named filename" PythonOsRename = "Rename file oldname to newname" PythonOsListdir = "List files in memory" diff --git a/apps/code/catalog.es.i18n b/apps/code/catalog.es.i18n index 960dd7eb9..2dee2b928 100644 --- a/apps/code/catalog.es.i18n +++ b/apps/code/catalog.es.i18n @@ -153,6 +153,7 @@ PythonUniform = "Floating point number in [a,b]" PythonImportTime = "Import time module" PythonImportOs = "Import os module" PythonOsUname = " Información del sistema " +PythonOsGetlogin = "Get username" PythonOsRemove = "Eliminar un archivo" PythonOsRename = "Renombrar archivo" PythonOsListdir = "Archivos de la lista" diff --git a/apps/code/catalog.fr.i18n b/apps/code/catalog.fr.i18n index 756ef882e..4ac2560c9 100644 --- a/apps/code/catalog.fr.i18n +++ b/apps/code/catalog.fr.i18n @@ -153,6 +153,7 @@ PythonUniform = "Nombre décimal dans [a,b]" PythonImportTime = "Importation du module temps" PythonImportOs = "Importation du module os" PythonOsUname = "Donne des infos sur le système" +PythonOsGetlogin = "Donne le nom d'utilisateur" PythonOsRemove = "Supprime le fichier nommé filename" PythonOsRename = "Renomme oldname en newname" PythonOsListdir = "Liste les fichiers" diff --git a/apps/code/catalog.hu.i18n b/apps/code/catalog.hu.i18n index a837db91b..6959839aa 100644 --- a/apps/code/catalog.hu.i18n +++ b/apps/code/catalog.hu.i18n @@ -172,6 +172,7 @@ PythonFileReadable = "read-et lehete használni" PythonFileWritable = "write-ot lehete használni" PythonImportOs = "os modul importálása" PythonOsUname = "Rendszer informaciók" +PythonOsGetlogin = "Get username" PythonOsRemove = "Fájl törlése" PythonOsRename = "Fájl átnevezése" PythonOsListdir = "Fájlok listája" diff --git a/apps/code/catalog.it.i18n b/apps/code/catalog.it.i18n index 94eacc262..6c174b53c 100644 --- a/apps/code/catalog.it.i18n +++ b/apps/code/catalog.it.i18n @@ -74,6 +74,7 @@ PythonImportTurtle = "Importa del modulo turtle" PythonImportTime = "Importa del modulo time" PythonImportOs = "Importa modulo os" PythonOsUname = "Ottieni informazioni sul sistema" +PythonOsGetlogin = "Get username" PythonOsRemove = "Rimuovere un file" PythonOsRename = "Rinomina file" PythonOsListdir = "Elenca file" diff --git a/apps/code/catalog.nl.i18n b/apps/code/catalog.nl.i18n index 1ee1f667c..cc788ee13 100644 --- a/apps/code/catalog.nl.i18n +++ b/apps/code/catalog.nl.i18n @@ -73,6 +73,7 @@ PythonImportMatplotlibPyplot = "Importeer matplotlib.pyplot module" PythonImportTime = "Importeer time module" PythonImportOs = "Importeer os module" PythonOsUname = " Krijg systeeminfo" +PythonOsGetlogin = "Get username" PythonOsRemove = "Een bestand verwijderen" PythonOsRename = "Hernoem bestand" PythonOsListdir = "Lijstbestanden" diff --git a/apps/code/catalog.pt.i18n b/apps/code/catalog.pt.i18n index a17ea0ad5..d50630dda 100644 --- a/apps/code/catalog.pt.i18n +++ b/apps/code/catalog.pt.i18n @@ -153,6 +153,7 @@ PythonUniform = "Número decimal em [a,b]" PythonImportTime = "Import time module" PythonImportOs = "Import os module" PythonOsUname = " Obter informações do sistema" +PythonOsGetlogin = "Get username" PythonOsRemove = "Remover um ficheiro" PythonOsRename = "Renomear ficheiro" PythonOsListdir = "Listar ficheiros" diff --git a/apps/code/catalog.universal.i18n b/apps/code/catalog.universal.i18n index 39d1ff3b4..0c05ad6f4 100644 --- a/apps/code/catalog.universal.i18n +++ b/apps/code/catalog.universal.i18n @@ -216,6 +216,7 @@ PythonCommandUniform = "uniform(a,b)" PythonConstantE = "2.718281828459045" PythonConstantPi = "3.141592653589793" PythonOsCommandUname = "uname()" +PythonOsCommandGetlogin = "getlogin()" PythonOsCommandRemove = "remove(filename)" PythonOsCommandRename = "rename(oldname, newname)" PythonOsCommandRemoveWithoutArg = "remove(\x11)" diff --git a/apps/code/python_toolbox.cpp b/apps/code/python_toolbox.cpp index 568e1f22c..4adf62795 100644 --- a/apps/code/python_toolbox.cpp +++ b/apps/code/python_toolbox.cpp @@ -217,6 +217,7 @@ const ToolboxMessageTree OsModuleChildren[] = { ToolboxMessageTree::Leaf(I18n::Message::PythonCommandImportOs, I18n::Message::PythonImportOs, false), ToolboxMessageTree::Leaf(I18n::Message::PythonCommandImportFromOs, I18n::Message::PythonImportOs, false), ToolboxMessageTree::Leaf(I18n::Message::PythonOsCommandUname, I18n::Message::PythonOsUname, false), + ToolboxMessageTree::Leaf(I18n::Message::PythonOsCommandGetlogin, I18n::Message::PythonOsGetlogin, false), ToolboxMessageTree::Leaf(I18n::Message::PythonOsCommandRemove, I18n::Message::PythonOsRemove, false, I18n::Message::PythonOsCommandRemoveWithoutArg), ToolboxMessageTree::Leaf(I18n::Message::PythonOsCommandRename, I18n::Message::PythonOsRename, false, I18n::Message::PythonOsCommandRenameWithoutArg), ToolboxMessageTree::Leaf(I18n::Message::PythonOsCommandListdir, I18n::Message::PythonOsListdir, false) From 25b74ea2f8960ecfe7f6714cc358b36f9df11c3c Mon Sep 17 00:00:00 2001 From: ArtichOwO Date: Tue, 29 Jun 2021 20:40:19 +0200 Subject: [PATCH 3/4] Removed "Omega or Epsilon" check --- python/port/mod/os/modos_table.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/python/port/mod/os/modos_table.c b/python/port/mod/os/modos_table.c index 20106bb2d..a97009720 100644 --- a/python/port/mod/os/modos_table.c +++ b/python/port/mod/os/modos_table.c @@ -10,11 +10,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(modos_remove_obj, modos_remove); MP_DEFINE_CONST_FUN_OBJ_2(modos_rename_obj, modos_rename); MP_DEFINE_CONST_FUN_OBJ_0(modos_listdir_obj, modos_listdir); -#ifdef OMEGA_VERSION STATIC const MP_DEFINE_STR_OBJ(modos_sysname_obj, "Omega"); -#else -STATIC const MP_DEFINE_STR_OBJ(modos_sysname_obj, "Epsilon"); -#endif STATIC const mp_rom_map_elem_t modos_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_os) }, From 24f3ccf007c59eec4a352a746c87f5c55b7c10e5 Mon Sep 17 00:00:00 2001 From: ArtichOwO Date: Tue, 29 Jun 2021 20:41:12 +0200 Subject: [PATCH 4/4] Removed username from "uname()", and "getlogin()" now uses "Ion::username()" --- python/port/mod/os/modos.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/python/port/mod/os/modos.cpp b/python/port/mod/os/modos.cpp index b32d9a3d8..a8333006d 100644 --- a/python/port/mod/os/modos.cpp +++ b/python/port/mod/os/modos.cpp @@ -7,6 +7,7 @@ extern "C" { #include } +#include #include #ifndef OMEGA_VERSION @@ -32,19 +33,12 @@ STATIC const MP_DEFINE_STR_OBJ(modos_uname_info_machine_obj, "NumWorks N0100"); STATIC const MP_DEFINE_STR_OBJ(modos_uname_info_machine_obj, "NumWorks Simulator"); #endif -#if defined(OMEGA_USERNAME) -STATIC const MP_DEFINE_STR_OBJ(modos_uname_info_username_obj, MP_STRINGIFY(OMEGA_USERNAME)); -#else -STATIC const MP_DEFINE_STR_OBJ(modos_uname_info_username_obj, ""); -#endif - STATIC const mp_rom_map_elem_t modos_uname_info_table[] = { { MP_ROM_QSTR(MP_QSTR_sysname), &modos_uname_info_sysname_obj }, { MP_ROM_QSTR(MP_QSTR_nodename), &modos_uname_info_nodename_obj }, { MP_ROM_QSTR(MP_QSTR_release), &modos_uname_info_release_obj }, { MP_ROM_QSTR(MP_QSTR_version), &modos_uname_info_version_obj }, { MP_ROM_QSTR(MP_QSTR_machine), &modos_uname_info_machine_obj }, - { MP_ROM_QSTR(MP_QSTR_username), &modos_uname_info_username_obj }, }; STATIC MP_DEFINE_CONST_DICT(modos_uname_info_obj, modos_uname_info_table); @@ -54,7 +48,7 @@ mp_obj_t modos_uname(void) { } mp_obj_t modos_getlogin(void) { - return (mp_obj_t)&modos_uname_info_username_obj; + return mp_obj_new_str((const char *)Ion::username(), MIN(strlen((const char *)Ion::username()), 16)); } mp_obj_t modos_remove(mp_obj_t o_file_name) {