What the heck is a dbus argument of type a{sa{sv}} in the Network Manager API? - format

I'm looking through the dbus api for Network Manager and there are methods with inputs of type a{sa{sv}}.
I'm still new to dbus but if I'm interpreting the definition of signature specifiers in https://www.freedesktop.org/software/systemd/man/sd_bus_message_read.html# correctly this is:
A variable-length array
Of named variable arrays
Of named "variants" (which I guess are tagged unions)
What practically is this for? A name-paginated list of named settings? I'm seeing it all over the place in this API.

s is std::string.
v is variant.
a{} is std::map.
a{sv} is std::map<std::string, Variant>
Finally: a{sa{sv}} is std::map<std::string, std::map<std::string, Variant>>
Variant can hold value of any D-Bus-supported type, if you are using c++ I recommend you to check it at
sdbus-cpp

It turns out this is what I guess should be called a "Settings" in Network Manager. For several methods instead of building a connection setting by setting an entire set of settings are added all at once. Here's a tabbed and commented version of the settings of my current connection as queried for example:
5
"connection" 5
"id" s "Profile 1"
"permissions" as o //<empty array of strings>
"timestamp" t 1661376049
"type" s "802-3-ethernet"
"uuid" s <not posting for privacy>
"802-3-ethernet" 3
"auto-negotiate" b false
"mac-address-blacklist" as 0
"s390-options" a{ss} 0
"ipv4" 6
"address-data" aa{sv} 0
"addresses" aau 0
"dns-search" as 0
"method" s "auto"
"route-data" aa{sv} 0
"routes" aau 0
"ipv6" 7
"addr-gen-mode" i 1
"address-data" aa{sv} 0
"addresses" a(ayuay) 0
"dns-search" as 0
"method" s "auto"
"route-data" aa{sv} 0
"routes" a(ayuayu) 0
"proxy" 0
I think most of these are defaults so the real settings you might set when creating a connection are probably something like:
4
"connection" 4
"id" s "Profile Foo"
"timestamp" t <whatever, maybe this is autogenerated>
"type" s "802-3-ethernet"
"uuid" s <might be auto generated too>
"802-3-ethernet" 0
"ipv4" 1
"method" s "auto"
"ipv6" 1
"addr-gen-mode" i 1
"method" s "auto"

Related

Initializing a matrix using a list with a string in it

Here is my code:
extensions [matrix]
..
sources-own[keyword1 keyword2 keyword3 keyword4 extrinsic-fitness visits]
..
to setup
create-sources
ask source 0 [
set keyword1 (matrix:from-row-list [["cat"][2]])
]
...
..
.
Now, when I click on SETUP and inspect "source 0", it shows the matrix to be initialized as the following:
{{matrix: [ [ 0 ][ 2 ] ]}}
Try as I might, I cannot get it to accept the string "cat" in place of the "0" in the first column.
OK, I got it.
A matrix in Netlogo can only hold numbers. One needs to use a "list" instead.

In windows, how do I find out a folders sort by parameters

I am building an image viewing app in Node.js. I noticed that in Windows, the pictures in a folder can be sorted by name, size, status, type, date and tags etc, and grouped after sorting by the same list and more.
Is there a way of getting the sort parameters or maybe just retrieving the sorted list of files, matching the regular expression /\.(jpg|jpg_large|jpeg|jpe|jfif|jif|jfi|jpe|gif|png|ico|bmp|webp|svg)$/i, as an array (ex: ['c:\man.jpg', 'c:\woman.jpg'] using Powershell?
EDIT:
This article got me closer to a solution. https://cyberforensicator.com/2019/02/03/shellbags-forensics-directory-viewing-preferences/
Unfortunately it doesn't explain how to get the nodelist value for a given folder so I used an app called shellbagsview from nirsoft to get this value. In any case, if the value is found the rest is easy. I have included a sample python script which explains how this is done here.
from winreg import *
# Registry is of the form:
# HKEY_CURRENT_USER\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\Bags\1375\Shell\{5C4F28B5-F869-4E84-8E60-F11DB97C5CC7}
# where 1375 is a value called the NodeList, and {5C4F28B5-F869-4E84-8E60-F11DB97C5CC7} is a value under Shell chosen based on creation date. It is a good idea to look at the registry after getting the nodelist from shellbagsview
folder_reg_path = "Software\\Classes\\Local Settings\\Software\\Microsoft\\Windows\Shell\\Bags\\1375\\Shell\\{5C4F28B5-F869-4E84-8E60-F11DB97C5CC7}"
# the size of icons used by the folder
def get_folder_icon_size(reg_key):
with OpenKey(HKEY_CURRENT_USER, reg_key) as key:
value = QueryValueEx(key, 'IconSize')
return '%d pixels' % (value[0])
# the folder view. details, list, tiles e.t.c
def get_logical_view_mode(reg_key):
with OpenKey(HKEY_CURRENT_USER, reg_key) as key:
value = QueryValueEx(key, 'LogicalViewMode')
logical_view_mode_dict = {1 : "Details view", 2 : "Tiles view", 3 : "Icons view", 4 : "List view", 5 : "Content view"}
return logical_view_mode_dict[value[0]]
# folder view is based on view mode. so you can have a logical view mode of icons view with a view mode of large icons for instance
def get_folder_view_mode(reg_key):
with OpenKey(HKEY_CURRENT_USER, reg_key) as key:
value = QueryValueEx(key, 'Mode')
# view_mode 7 is only available on xp. A dead os
view_mode_dict = {1 : "Medium icons", 2 : "Small icons", 3 : "List", 4 : "Details", 5 : "Thumbnail icons", 6 : "Large icons", 8 : "Content"}
return view_mode_dict[value[0]]
# how is the folder being sorted
def get_folder_sort_by(reg_key):
with OpenKey(HKEY_CURRENT_USER, reg_key) as key:
value = QueryValueEx(key, 'Sort')
folder_sort_dict = {"0E000000" : "Date Modified", "10000000" : "Date Accessed", "0F000000" : "Date Created", "0B000000" : "Type", "0C000000" : "Size", "0A000000" : "Name", "02000000" : "Title", "05000000" : "Tags"}
# we get a byte value which we will hexify and get a rather long string
# similar to : 000000000000000000000000000000000100000030f125b7ef471a10a5f102608c9eebac0c000000ffffffff
reg_value = value[0].hex()
# now for this string, we need to get the last 16 strings. then we now get the first 8 out of it. so we will have
folder_sort_dict_key = (reg_value[-16:][:8]).upper()
return folder_sort_dict[folder_sort_dict_key]
# in what order is the folder being sorted. ascending or descending???
def get_folder_sort_by_order(reg_key):
with OpenKey(HKEY_CURRENT_USER, reg_key) as key:
value = QueryValueEx(key, 'Sort')
folder_sort_dict = {"01000000" : "Ascending", "FFFFFFFF" : "Descending"}
# we get a byte value which we will hexify and get a rather long string
# similar to : 000000000000000000000000000000000100000030f125b7ef471a10a5f102608c9eebac0c000000ffffffff
reg_value = value[0].hex()
# now for this string, we need to get the last 16 strings. then we now get the last 8 out of it. so we will have
folder_sort_dict_key = (reg_value[-16:][-8:]).upper()
return folder_sort_dict[folder_sort_dict_key]
icon_size = get_folder_icon_size(folder_reg_path)
logical_view_mode = get_logical_view_mode(folder_reg_path)
view_mode = get_folder_view_mode(folder_reg_path)
sorted_by = get_folder_sort_by(folder_reg_path)
sorted_by_order = get_folder_sort_by_order(folder_reg_path)
print ('The folder icon size is %s' % icon_size)
print('The folder logical view mode is %s' % logical_view_mode)
print('The folder view mode is %s' % view_mode)
print('The folder is sorted by %s in %s order' % (sorted_by, sorted_by_order))
The question itself and
the environment to run this in is unclear.
As you reference PowerShell and a RegEx to limit to specific extensions,
With this sample tree:
> tree /f a:\
A:\
└───Test
boy.bmp
child.ico
girl.gif
man.jpg
woman.jpg
this script:
Get-ChildItem -Path A:\Test -File |
Where-Object Extension -match '\.(jpg|jpg_large|jpeg|jpe|jfif|jif|jfi|jpe|gif|png|ico|bmp|webp|svg)$' |
Sort-Object Name |
Select-Object -ExpandProperty FullName |
ConvertTo-Json -Compress
yields:
["A:\\Test\\boy.bmp","A:\\Test\\child.ico","A:\\Test\\girl.gif","A:\\Test\\man.jpg","A:\\Test\\woman.jpg"]
The IShellView implementation (the file list part of Explorer) asks its IShellBrowser for a stream when it needs to load/save its state. My suggestion would be to host a IExplorerBrowser instance "browsed to the folder" and ask the view for its items. I don't know if you can ask it about which column it has sorted by but just getting the items in sorted order should be enough for your needs.
I don't know how to this in a scripting language but I assume PS supports enough COM for it to be possible.

How to import angle values from a catalog into GalSim

I'm trying to import galaxy values (Sersic index, half light radius, etc) from an external ascii file in to GalSim. I'm having trouble reading in the position angle value 'beta', and would like to know if this is possible using the YAML format.
When I try I get the error message:
galsim.errors.GalSimConfigValueError: Invalid value_type specified for parameter beta with type=Catalog. Value <class 'coord.angle.Angle'> not in (<class 'float'>, <class 'int'>, <class 'bool'>, <class 'str'>)
I realise that I'm getting this error message because I'm unable to append the string 'deg' after the input to specify that the units of this input are in degrees.
I've tried adding 'deg' directly in to the input catalogue (inside "" speech marks), with no success. I've also tried adding 'deg' after the catalogue read statement directly in the code, also to no success.
A minimum working example is below. This relies on a file named 'input.dat' in the same directory with a single number inside (45, for example). Then, save the code below as 'test.yaml' and run on the command line as $ galsim test.yaml:
gal :
type : Sersic
n : 1
half_light_radius : 1
flux : 1
ellip :
type : QBeta
q : 0.5
beta : { type : Catalog , col : 0 }
input :
catalog :
file_name : input.dat
I expect to be able to read in beta position angle arguments from an input ascii catalogue and have them replicated in the output galaxy profiles. The above MWE should produce a small postage stamp image of a moderately elliptical galaxy at a position angle of 45 degrees (or whatever number is placed inside 'input.dat'.
Thank you in advance for any help or advice on this front.
Try this:
gal :
type : Sersic
n : 1
half_light_radius : 1
flux : 1
ellip :
type : QBeta
q : 0.5
beta :
type: Radians
theta: { type : Catalog , col : 0 }
input :
catalog :
file_name : input.dat
There is also a Degrees type that works the same way if your catalog columns list the angle in degrees.

Constraint Error warning using Enum in ADA

I'd like to know why constraint Errors warnings are prompted in Ada when enums are used as in the example below. As I've been using Enums I can replace them for a better implementation.
type Uart_Instance_Type is (COM1, COM2, COM3);
for Uart_Instance_Type use
( COM1 => 16#0001# ,
COM2 => 16#0002# ,
COM3 => 16#0003#
);
type UART_Register_Type is record
SR : Half_Word; -- USART Status register
Reserved_0 : Half_Word;
DR : Half_Word; -- USART Data register
Reserved_1 : Half_Word;
BRR : Half_Word; -- USART Baud rate register
Reserved_2 : Half_Word;
end record
with volatile;
for UART_Register_Type use record
SR at 0 range 0 .. 15;
Reserved_0 at 2 range 0 .. 15;
DR at 4 range 0 .. 15;
Reserved_1 at 6 range 0 .. 15;
BRR at 8 range 0 .. 15;
Reserved_2 at 10 range 0 .. 15;
end record;
type UART_Register_Access is access all UART_Register_Type;
UARTs: array (Uart_Instance_Type range COM1 .. COM3) of aliased UART_Register_Access;
The compiler prompt at the last line ("UARTs: ...) and shows:
warning: "Constraint Error" may call Last_Chance_Handler
Is there a better implementation to avoid these warnings when using Enums?
Thanks in advance! :)
I think you must be compiling for a restricted (Ravenscar?) runtime, which is why any exception will result in a call to Last_Chance_Handler.
I encountered a lot of irritating warnings like this, and eventually traced it to compiling with
-gnatwa (“turn on all info/warnings marked below with +”) which enables
-gnatw.x ("turn on warnings for non-local exception”).
You can suppress the warnings with -gnatw.X.
(For info, you can see the command line options by saying gnatmake -h (or arm-eabi-gnatmake -h). There are a lot.)

Embedding Documents Directly in Documents with mongoid

I need to to bulk insert the array of embedded documents to an existing document. I have tried the below code, but it was not working
arr_loc = []
arr_loc << Location.new(:name=> "test") << Location.new(:name=> "test2")
biz = Business.first
biz.locations = arr_loc
biz.save # not working
currently i am inserting each doc separately by looping the array, i hope there is a better cleaner way to do this.
from mongo shell we can easily do this like this
> var mongo = db.things.findOne({name:"mongo"});
> print(tojson(mongo));
{"_id" : "497da93d4ee47b3a675d2d9b" , "name" : "mongo", "type" : "database"}
> mongo.data = { a:1, b:2};
{"a" : 1 , "b" : 2}
> db.things.save(mongo);
> db.things.findOne({name:"mongo"});
{"_id" : "497da93d4ee47b3a675d2d9b" , "name" : "mongo" , "type" : "database", "data" : {"a" : 1 , "b" : 2}}
>
check the link for more info.. is it possible to do this with mongoid?
It turns out to be a problem in calling save method after assignment
biz.locations = arr_loc #this is fine
biz.save # no need for that
Mongoid updates the document on the assignment itself, no explicit save required. Refer this mongoid google group thread (Thanks Nick hoffman) for more info

Resources