Skip to content

Commit

Permalink
Merge branch 'master' into registration
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Oct 27, 2023
2 parents 5f6fc37 + ff4fc26 commit eb2dca0
Show file tree
Hide file tree
Showing 34 changed files with 723 additions and 114 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/weblate-merge-po.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
zypper --non-interactive --gpg-auto-import-keys ref
- name: Install tools
run: zypper --non-interactive install --no-recommends gh git gettext-tools
run: zypper --non-interactive install --no-recommends gh git gettext-tools python3-langtable

- name: Configure Git
run: |
Expand Down Expand Up @@ -92,6 +92,7 @@ jobs:
if: steps.check_changes.outputs.po_updated == 'true'
working-directory: ./agama
run: |
web/share/update-manifest.py src/manifest.json
# use a unique branch to avoid possible conflicts with already existing branches
git checkout -b "po_merge_${GITHUB_RUN_ID}"
git commit -a -m "Update PO files"$'\n\n'"Agama-weblate commit: `git -C ../agama-weblate rev-parse HEAD`"
Expand Down
6 changes: 3 additions & 3 deletions doc/dbus/bus/org.opensuse.Agama1.Network.Connection.bus.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@
Possible values: "disabled", "auto", "manual" or "link-local".
See [crate::network::model::IpMethod].
See [crate::network::model::Ipv4Method].
-->
<property name="Method4" type="s" access="readwrite"/>
<!--
IPv6 configuration method.
Possible values: "disabled", "auto", "manual" or "link-local".
Possible values: "disabled", "auto", "manual", "link-local", "ignore" or "dhcp".
See [crate::network::model::IpMethod].
See [crate::network::model::Ipv6Method].
-->
<property name="Method6" type="s" access="readwrite"/>
<!--
Expand Down
6 changes: 3 additions & 3 deletions doc/dbus/org.opensuse.Agama1.Network.Connection.IP.doc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
Possible values: "disabled", "auto", "manual" or "link-local".
See [crate::network::model::IpMethod].
See [crate::network::model::Ipv4Method].
-->
<property name="Method4" type="s" access="readwrite"/>
<!--
IPv6 configuration method.
Possible values: "disabled", "auto", "manual" or "link-local".
Possible values: "disabled", "auto", "manual", "link-local", "ignore" or "dhcp".
See [crate::network::model::IpMethod].
See [crate::network::model::Ipv6Method].
-->
<property name="Method6" type="s" access="readwrite"/>
<!--
Expand Down
50 changes: 44 additions & 6 deletions doc/i18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- [Formatting Texts](#formatting-texts)
- [TRANSLATORS Comments](#translators-comments)
- [Missing Translations](#missing-translations)
- [ESLint Plugin](#eslint-plugin)
- [Testing Language](#testing-language)
- [Building POT File](#building-pot-file)
- [Cockpit Details](#cockpit-details)
Expand All @@ -45,14 +46,23 @@ part in the details below.

Users have two ways how to change the used language in the Agama interface.

### Language Selector

The sidebar of the web UI contains a component that allows to change the
language. It was introduced in Agama 5 and it is the recommended way. The list
of supported languages is read from the
[manifest.json](https://github.com/openSUSE/agama/blob/master/web/src/manifest.json)
file. Check the [The Web Frontend](#the-web-frontend) for further details.

### URL Query Parameter

When using a remote installation it is possible to set the used language via an
URL query parameter. This is an expert option.

To change the language append the `?lang=<locale>` query to the URL when
accessing the Agama installer. The `locale` string uses the usual Linux locale
format, e.g. `cs_CZ`.
accessing the Agama installer. The `locale` string uses the [RFC
5646](https://www.rfc-editor.org/rfc/rfc5646.html) but the usual Linux locale
format is supported too, e.g. `cs_CZ`.

It is the user responsibility to use a correct locale name. When using a wrong
name the translations might be broken, displayed only partially or even not at
Expand All @@ -62,10 +72,6 @@ Changing the language causes reloading the page, in some situations this could
cause losing some entered values on the current page. Therefore it is
recommended to change the language at the very beginning.

### Language Selector

*to be done...*

## Translations

For translation process Agama uses [Weblate](https://weblate.org/) tool running
Expand Down Expand Up @@ -145,6 +151,7 @@ GitHub action.

- It checks out both `agama` and `agama-weblate` repositories
- It copies the PO files from the `agama-weblate` to the `agama` repository
- It updates the `manifest.json` file with the list of supported languages.
- It creates a pull request with the changes

If there are no changes besides the timestamps in the PO files the pull request
Expand Down Expand Up @@ -183,6 +190,31 @@ web frontend. However, the web frontend can display some translated texts coming
from the backend part so it is important to set the same language in both parts
and make sure the translations are available there.

The list of supported languages is read from the
[manifest.json](https://github.com/openSUSE/agama/blob/master/web/src/manifest.json),
under the `locales` key. Such a list is automatically refreshed when any of the
PO files is updated (see [Uploading Translatable
Texts](#uploading-translatable-texts)).

The [update-manifest.py
script](https://github.com/openSUSE/agama/blob/master/web/share/update-manifest.py)
is the responsible for updating the list of supported languages. It goes
through all PO files, filters out the ones with less than 70% of translated
content and adds the corresponding locales to the `manifest.json`.

The name of the locale is taken from
[langtable](https://pypi.org/project/langtable/), so be sure to have it
installed. However, when the territory is not include in the PO file (`es`
instead of `es_es`), the script uses the
[locales.json map](https://github.com/openSUSE/agama/blob/master/web/share/locales.json)
to determine which territory to use.

If you need to manually update the `manifest.json` file, run:

```
web/share/update-manifest.py web/src/manifest.json
```

### Marking Texts for Translation

The texts are marked for translation using the usual functions like `_()`,
Expand Down Expand Up @@ -405,6 +437,12 @@ even work, no crash. But there are still translation problems with them.
In both cases the strings will not be extracted to the POT file.
### ESLint Plugin
The [eslint-plugin-agama-i18n](../web/eslint-plugin-agama-i18n/) subdirectory
contains an ESLint plugin which ensures that a string literal is passed
to the translation function. See more details there.
### Testing Language
The Agama web interface supports special testing `xx` language. That language
Expand Down
2 changes: 1 addition & 1 deletion playwright/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const config: PlaywrightTestConfig = {
* Maximum time expect() should wait for the condition to be met.
* For example in `await expect(locator).toHaveText();`
*/
timeout: 5000
timeout: 15000
},
/* Do not run tests in files in parallel by default */
fullyParallel: false,
Expand Down
22 changes: 21 additions & 1 deletion rust/agama-cli/src/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::fs;
use std::fs::File;
use std::io;
use std::io::Write;
use std::os::unix::fs::PermissionsExt;
use std::path::{Path, PathBuf};
use std::process::Command;
use tempdir::TempDir;
Expand Down Expand Up @@ -295,7 +296,7 @@ fn compress_logs(tmp_dir: &TempDir, result: &String) -> io::Result<()> {
.status()?;

if res.success() {
Ok(())
set_archive_permissions(result)
} else {
Err(io::Error::new(
io::ErrorKind::Other,
Expand All @@ -304,6 +305,25 @@ fn compress_logs(tmp_dir: &TempDir, result: &String) -> io::Result<()> {
}
}

// Sets the archive owner to root:root. Also sets the file permissions to read/write for the
// owner only.
fn set_archive_permissions(archive: &String) -> io::Result<()> {
let attr = fs::metadata(archive)?;
let mut permissions = attr.permissions();

// set the archive file permissions to -rw-------
permissions.set_mode(0o600);
fs::set_permissions(archive, permissions)?;

// set the archive owner to root:root
// note: std::os::unix::fs::chown is unstable for now
Command::new("chown")
.args(["root:root", archive.as_str()])
.status()?;

Ok(())
}

// Handler for the "agama logs store" subcommand
fn store(options: LogOptions) -> Result<(), io::Error> {
if !Uid::effective().is_root() {
Expand Down
12 changes: 6 additions & 6 deletions rust/agama-dbus-server/src/network/dbus/interfaces/ip_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! to the `Ip<T>` struct.
use crate::network::{
action::Action,
model::{Connection as NetworkConnection, IpConfig, IpMethod},
model::{Connection as NetworkConnection, IpConfig, Ipv4Method, Ipv6Method},
};
use async_std::{channel::Sender, sync::Arc};
use cidr::IpInet;
Expand Down Expand Up @@ -95,7 +95,7 @@ impl Ip {
///
/// Possible values: "disabled", "auto", "manual" or "link-local".
///
/// See [crate::network::model::IpMethod].
/// See [crate::network::model::Ipv4Method].
#[dbus_interface(property)]
pub async fn method4(&self) -> String {
let ip_config = self.get_ip_config().await;
Expand All @@ -104,15 +104,15 @@ impl Ip {

#[dbus_interface(property)]
pub async fn set_method4(&mut self, method: &str) -> zbus::fdo::Result<()> {
let method: IpMethod = method.parse()?;
let method: Ipv4Method = method.parse()?;
self.update_config(|ip| ip.method4 = method).await
}

/// IPv6 configuration method.
///
/// Possible values: "disabled", "auto", "manual" or "link-local".
/// Possible values: "disabled", "auto", "manual", "link-local", "ignore" or "dhcp".
///
/// See [crate::network::model::IpMethod].
/// See [crate::network::model::Ipv6Method].
#[dbus_interface(property)]
pub async fn method6(&self) -> String {
let ip_config = self.get_ip_config().await;
Expand All @@ -121,7 +121,7 @@ impl Ip {

#[dbus_interface(property)]
pub async fn set_method6(&mut self, method: &str) -> zbus::fdo::Result<()> {
let method: IpMethod = method.parse()?;
let method: Ipv6Method = method.parse()?;
self.update_config(|ip| ip.method6 = method).await
}

Expand Down
68 changes: 55 additions & 13 deletions rust/agama-dbus-server/src/network/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ pub enum Status {

#[derive(Default, Debug, PartialEq, Clone)]
pub struct IpConfig {
pub method4: IpMethod,
pub method6: IpMethod,
pub method4: Ipv4Method,
pub method6: Ipv6Method,
pub addresses: Vec<IpInet>,
pub nameservers: Vec<IpAddr>,
pub gateway4: Option<IpAddr>,
Expand All @@ -352,34 +352,76 @@ pub struct MatchConfig {
pub struct UnknownIpMethod(String);

#[derive(Debug, Default, Copy, Clone, PartialEq)]
pub enum IpMethod {
pub enum Ipv4Method {
#[default]
Disabled = 0,
Auto = 1,
Manual = 2,
LinkLocal = 3,
}
impl fmt::Display for IpMethod {

impl fmt::Display for Ipv4Method {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let name = match &self {
Ipv4Method::Disabled => "disabled",
Ipv4Method::Auto => "auto",
Ipv4Method::Manual => "manual",
Ipv4Method::LinkLocal => "link-local",
};
write!(f, "{}", name)
}
}

impl FromStr for Ipv4Method {
type Err = UnknownIpMethod;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"disabled" => Ok(Ipv4Method::Disabled),
"auto" => Ok(Ipv4Method::Auto),
"manual" => Ok(Ipv4Method::Manual),
"link-local" => Ok(Ipv4Method::LinkLocal),
_ => Err(UnknownIpMethod(s.to_string())),
}
}
}

#[derive(Debug, Default, Copy, Clone, PartialEq)]
pub enum Ipv6Method {
#[default]
Disabled = 0,
Auto = 1,
Manual = 2,
LinkLocal = 3,
Ignore = 4,
Dhcp = 5,
}

impl fmt::Display for Ipv6Method {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let name = match &self {
IpMethod::Disabled => "disabled",
IpMethod::Auto => "auto",
IpMethod::Manual => "manual",
IpMethod::LinkLocal => "link-local",
Ipv6Method::Disabled => "disabled",
Ipv6Method::Auto => "auto",
Ipv6Method::Manual => "manual",
Ipv6Method::LinkLocal => "link-local",
Ipv6Method::Ignore => "ignore",
Ipv6Method::Dhcp => "dhcp",
};
write!(f, "{}", name)
}
}

impl FromStr for IpMethod {
impl FromStr for Ipv6Method {
type Err = UnknownIpMethod;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"disabled" => Ok(IpMethod::Disabled),
"auto" => Ok(IpMethod::Auto),
"manual" => Ok(IpMethod::Manual),
"link-local" => Ok(IpMethod::LinkLocal),
"disabled" => Ok(Ipv6Method::Disabled),
"auto" => Ok(Ipv6Method::Auto),
"manual" => Ok(Ipv6Method::Manual),
"link-local" => Ok(Ipv6Method::LinkLocal),
"ignore" => Ok(Ipv6Method::Ignore),
"dhcp" => Ok(Ipv6Method::Dhcp),
_ => Err(UnknownIpMethod(s.to_string())),
}
}
Expand Down
4 changes: 2 additions & 2 deletions rust/agama-dbus-server/src/network/nm/dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,8 @@ mod test {
"::ffff:c0a8:102".parse::<IpAddr>().unwrap()
]
);
assert_eq!(ip_config.method4, IpMethod::Auto);
assert_eq!(ip_config.method6, IpMethod::Auto);
assert_eq!(ip_config.method4, Ipv4Method::Auto);
assert_eq!(ip_config.method6, Ipv6Method::Auto);
}

#[test]
Expand Down
Loading

0 comments on commit eb2dca0

Please sign in to comment.