Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite pyRevit configurations #2482

Draft
wants to merge 40 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
decf1d1
add new configuration project
dosymep Dec 18, 2024
492e6e3
add ini project
dosymep Dec 18, 2024
98c40b3
fix build
dosymep Dec 18, 2024
d9c2251
remove unnecessary usings
dosymep Dec 18, 2024
63393d7
update create config
dosymep Dec 18, 2024
2afea49
rewrite config class to new configs
dosymep Dec 18, 2024
68efd97
change return default value for lists
dosymep Dec 18, 2024
e7c28d7
add override name to create config
dosymep Dec 18, 2024
f4d0b36
added configuration path and save
dosymep Dec 18, 2024
b079c2f
update service interface
dosymep Dec 18, 2024
1b52854
Добавил сервис конфигурации
dosymep Dec 18, 2024
8618fad
fix spelling
dosymep Dec 20, 2024
8e4eddf
add sections classes
dosymep Dec 20, 2024
4bfae44
Merge branch 'develop' into features/configuration
jmcouffin Dec 20, 2024
a22a053
update
dosymep Dec 23, 2024
caea3f3
add configuration name
dosymep Dec 23, 2024
da4575d
add support requred and init features for net48
dosymep Dec 23, 2024
1661d2e
add parse config by reflection
dosymep Dec 23, 2024
08919b5
Merge remote-tracking branch 'origin/features/configuration' into fea…
dosymep Dec 23, 2024
29bc6ef
add attribute settings
dosymep Dec 23, 2024
6baf57d
add save config sections
dosymep Dec 27, 2024
cf74632
update public interface
dosymep Dec 27, 2024
6122fd9
update console config command
dosymep Dec 27, 2024
1b92380
update read and write propeties
dosymep Dec 27, 2024
7faee38
update pyRevit environment config
dosymep Dec 27, 2024
6e10ac0
Merge branch 'develop' into features/configuration
dosymep Dec 27, 2024
3825ecb
fix typo
dosymep Dec 28, 2024
3b09e3e
fix override config name
dosymep Dec 28, 2024
6f81e4a
update getting config file service
dosymep Dec 28, 2024
9e1f6bd
add readonly properti to service (python)
dosymep Dec 28, 2024
0b4fd1c
add user extensions
dosymep Dec 28, 2024
24927a5
update python code
dosymep Dec 28, 2024
0954681
update tests
dosymep Dec 28, 2024
23b218f
add realization
dosymep Dec 28, 2024
c1fef09
add reference
dosymep Dec 28, 2024
5c7dec2
add revit version to config
dosymep Dec 28, 2024
df9de22
fix override config name
dosymep Dec 28, 2024
6375993
fix override config prioritization
dosymep Dec 28, 2024
838f163
update references
dosymep Dec 28, 2024
eae821a
remove references
dosymep Dec 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bin/netcore/pyRevitLabs.Emojis.dll
Binary file not shown.
Binary file modified bin/netfx/pyRevitLabs.Emojis.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion dev/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<NetFolder Condition="'$(TargetFramework)' == 'net48'">netfx</NetFolder>
<NetFolder Condition="'$(TargetFramework)' == 'net8.0-windows'">netcore</NetFolder>
<NetFolder Condition="'$(TargetFramework.StartsWith(net8.0))'">netcore</NetFolder>
</PropertyGroup>

<PropertyGroup>
Expand Down
100 changes: 55 additions & 45 deletions dev/pyRevitLabs/pyRevitCLI/PyRevitCLI.cs

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions dev/pyRevitLabs/pyRevitCLI/PyRevitCLIExtensionCmds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,23 +171,23 @@ internal static void
}

internal static void
ToggleExtension(bool enable, string cloneName, string extName) {
ToggleExtension(string revitVersion, bool enable, string cloneName, string extName) {
if (extName != null) {
PyRevitClone clone = null;
if (cloneName != null)
clone = PyRevitClones.GetRegisteredClone(cloneName);

if (enable) {
if (clone != null)
PyRevitExtensions.EnableShippedExtension(clone, extName);
PyRevitExtensions.EnableShippedExtension(revitVersion, clone, extName);
else
PyRevitExtensions.EnableInstalledExtension(extName);
PyRevitExtensions.EnableInstalledExtension(revitVersion, extName);
}
else {
if (clone != null)
PyRevitExtensions.DisableShippedExtension(clone, extName);
PyRevitExtensions.DisableShippedExtension(revitVersion, clone, extName);
else
PyRevitExtensions.DisableInstalledExtension(extName);
PyRevitExtensions.DisableInstalledExtension(revitVersion, extName);
}
}
}
Expand Down
54 changes: 27 additions & 27 deletions dev/pyRevitLabs/pyRevitCLI/Resources/UsagePatterns.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,36 +74,36 @@ Usage:
pyrevit config (-h | --help)
pyrevit config --from=<template_config_path> [--log=<log_file>]
pyrevit configs (-h | --help)
pyrevit configs bincache [(enable | disable)] [--log=<log_file>]
pyrevit configs checkupdates [(enable | disable)] [--log=<log_file>]
pyrevit configs autoupdate [(enable | disable)] [--log=<log_file>]
pyrevit configs rocketmode [(enable | disable)] [--log=<log_file>]
pyrevit configs logs [(none | verbose | debug)] [--log=<log_file>]
pyrevit configs filelogging [(enable | disable)] [--log=<log_file>]
pyrevit configs startuptimeout [<timeout>] [--log=<log_file>]
pyrevit configs loadbeta [(enable | disable)] [--log=<log_file>]
pyrevit configs cpyversion [<cpy_version>] [--log=<log_file>]
pyrevit configs usercanupdate [(yes | no)] [--log=<log_file>]
pyrevit configs usercanextend [(yes | no)] [--log=<log_file>]
pyrevit configs usercanconfig [(yes | no)] [--log=<log_file>]
pyrevit configs colordocs [(enable | disable)] [--log=<log_file>]
pyrevit configs tooltipdebuginfo [(enable | disable)] [--log=<log_file>]
pyrevit configs bincache [(enable | disable)] [<revit_year>] [--log=<log_file>]
pyrevit configs checkupdates [(enable | disable)] [<revit_year>] [--log=<log_file>]
pyrevit configs autoupdate [(enable | disable)] [<revit_year>] [--log=<log_file>]
pyrevit configs rocketmode [(enable | disable)] [<revit_year>] [--log=<log_file>]
pyrevit configs logs [(none | verbose | debug)] [<revit_year>] [--log=<log_file>]
pyrevit configs filelogging [(enable | disable)] [<revit_year>] [--log=<log_file>]
pyrevit configs startuptimeout [<timeout>] [<revit_year>] [--log=<log_file>]
pyrevit configs loadbeta [(enable | disable)] [<revit_year>] [--log=<log_file>]
pyrevit configs cpyversion [<cpy_version>] [<revit_year>] [--log=<log_file>]
pyrevit configs usercanupdate [(yes | no)] [<revit_year>] [--log=<log_file>]
pyrevit configs usercanextend [(yes | no)] [<revit_year>] [--log=<log_file>]
pyrevit configs usercanconfig [(yes | no)] [<revit_year>] [--log=<log_file>]
pyrevit configs colordocs [(enable | disable)] [<revit_year>] [--log=<log_file>]
pyrevit configs tooltipdebuginfo [(enable | disable)] [<revit_year>] [--log=<log_file>]
pyrevit configs routes [(-h | --help)]
pyrevit configs routes [(enable | disable)] [--log=<log_file>]
pyrevit configs routes port [<port_number>] [--log=<log_file>]
pyrevit configs routes coreapi [(enable | disable)] [--log=<log_file>]
pyrevit configs routes [(enable | disable)] [<revit_year>] [--log=<log_file>]
pyrevit configs routes port [<port_number>] [<revit_year>] [--log=<log_file>]
pyrevit configs routes coreapi [(enable | disable)] [<revit_year>] [--log=<log_file>]
pyrevit configs telemetry [(-h | --help)]
pyrevit configs telemetry [(enable | disable)] [--log=<log_file>]
pyrevit configs telemetry utc [(yes | no)] [--log=<log_file>]
pyrevit configs telemetry (file | server) [<dest_path>] [--log=<log_file>]
pyrevit configs telemetry hooks [(yes | no)] [--log=<log_file>]
pyrevit configs apptelemetry [(enable | disable)] [--log=<log_file>]
pyrevit configs apptelemetry flags [<flags>] [--log=<log_file>]
pyrevit configs apptelemetry server [<server_path>] [--log=<log_file>]
pyrevit configs outputcss [<css_path>] [--log=<log_file>]
pyrevit configs telemetry [(enable | disable)] [<revit_year>] [--log=<log_file>]
pyrevit configs telemetry utc [(yes | no)] [<revit_year>] [--log=<log_file>]
pyrevit configs telemetry (file | server) [<dest_path>] [<revit_year>] [--log=<log_file>]
pyrevit configs telemetry hooks [(yes | no)] [<revit_year>] [--log=<log_file>]
pyrevit configs apptelemetry [(enable | disable)] [<revit_year>] [--log=<log_file>]
pyrevit configs apptelemetry flags [<flags>] [<revit_year>] [--log=<log_file>]
pyrevit configs apptelemetry server [<server_path>] [<revit_year>] [--log=<log_file>]
pyrevit configs outputcss [<css_path>] [<revit_year>] [--log=<log_file>]
pyrevit configs seed [--lock] [--log=<log_file>]
pyrevit configs <option_path> [(enable | disable)] [--log=<log_file>]
pyrevit configs <option_path> [<option_value>] [--log=<log_file>]
pyrevit configs <option_path> [(enable | disable)] [<revit_year>] [--log=<log_file>]
pyrevit configs <option_path> [<option_value>] [<revit_year>] [--log=<log_file>]
pyrevit doctor (-h | --help)
pyrevit doctor [--list]
pyrevit doctor <doctor_command> [--dryrun]
4 changes: 0 additions & 4 deletions dev/pyRevitLabs/pyRevitLabs.Common/pyRevitLabs.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.10.0"/>
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" Version="4.10.0"/>

<PackageReference Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'" Include="MadMilkman.Ini" Version="1.0.6"/>
<PackageReference Condition="'$(TargetFrameworkIdentifier)' == '.NetCoreApp'" Include="MadMilkman.Ini.Unofficial" Version="1.0.1"/>

<Reference Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'" Include="System.Management"/>
<PackageReference Condition="'$(TargetFrameworkIdentifier)' == '.NetCoreApp'" Include="System.Management" Version="8.0.0"/>
</ItemGroup>
Expand All @@ -36,7 +33,6 @@
<Copy SourceFiles="$(OutDir)\DotNetVersionFinder.dll" DestinationFolder="$(PyRevitBinDir)"/>
<Copy SourceFiles="$(OutDir)\LibGit2Sharp.dll" DestinationFolder="$(PyRevitBinDir)"/>
<Copy SourceFiles="@(LibGit2SharpNative)" DestinationFolder="$(PyRevitBinDir)"/>
<Copy SourceFiles="$(OutDir)\MadMilkman.Ini.dll" DestinationFolder="$(PyRevitBinDir)"/>
<Copy SourceFiles="$(OutDir)\OpenMcdf.dll" DestinationFolder="$(PyRevitBinDir)"/>
<Copy SourceFiles="$(OutDir)\YamlDotNet.dll" DestinationFolder="$(PyRevitBinDir)"/>
<Copy SourceFiles="$(OutDir)\Microsoft.CodeAnalysis.dll" DestinationFolder="$(PyRevitBinDir)"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace pyRevitLabs.Configurations.Ini.Extensions;

public static class IniConfigurationExtensions
{
public static ConfigurationBuilder AddIniConfiguration(
this ConfigurationBuilder builder, string configurationPath, string conigurationName, bool readOnly = default)
{
if (builder == null)
throw new ArgumentNullException(nameof(builder));

if (string.IsNullOrWhiteSpace(configurationPath))
throw new ArgumentException("Value cannot be null or whitespace.", nameof(configurationPath));

if (string.IsNullOrWhiteSpace(conigurationName))
throw new ArgumentException("Value cannot be null or empty.", nameof(conigurationName));

return builder.AddConfigurationSource(conigurationName, IniConfiguration.Create(configurationPath, readOnly));
}
}
100 changes: 100 additions & 0 deletions dev/pyRevitLabs/pyRevitLabs.Configurations.Ini/IniConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using System.Text;
using IniParser;
using IniParser.Model;
using pyRevitLabs.Configurations.Abstractions;
using pyRevitLabs.Configurations.Exceptions;
using pyRevitLabs.Json;

namespace pyRevitLabs.Configurations.Ini;

public sealed class IniConfiguration : ConfigurationBase
{
public static readonly string DefaultFileExtension = ".ini";
public static readonly Encoding DefaultFileEncoding = new UTF8Encoding(false);

private readonly IniData _iniFile;
private readonly FileIniDataParser _parser;

/// <summary>
/// Create ini configuration instance.
/// </summary>
/// <param name="configurationPath">Configuration path.</param>
/// <param name="readOnly">Admin configurations </param>
private IniConfiguration(string configurationPath, bool readOnly)
: base(configurationPath, readOnly)
{
_parser = new FileIniDataParser();
_iniFile = !File.Exists(configurationPath)
? new IniData()
: _parser.ReadFile(_configurationPath, DefaultFileEncoding);
}

/// <summary>
/// Creates IniConfiguration.
/// </summary>
/// <param name="configurationPath">Configuration file path.</param>
/// <param name="readOnly">Mark file is readonly.</param>
/// <returns>Return new IniConfiguration.</returns>
/// <exception cref="ArgumentNullException">When configurationPath is null.</exception>
public static IConfiguration Create(string configurationPath, bool readOnly = default)
{
if (configurationPath is null)
throw new ArgumentNullException(nameof(configurationPath));

return new IniConfiguration(configurationPath, readOnly);
}

/// <inheritdoc />
protected override void SaveConfigurationImpl()
{
SaveConfigurationImpl(_configurationPath);
}

/// <inheritdoc />
protected override void SaveConfigurationImpl(string configurationPath)
{
_parser.WriteFile(configurationPath, _iniFile, DefaultFileEncoding);
}

/// <inheritdoc />
protected override bool HasSectionImpl(string sectionName)
{
return _iniFile.Sections.ContainsSection(sectionName);
}

/// <inheritdoc />
protected override bool HasSectionKeyImpl(string sectionName, string keyName)
{
return HasSection(sectionName)
&& _iniFile.Sections[sectionName].ContainsKey(keyName);
}

/// <inheritdoc />
protected override bool RemoveValueImpl(string sectionName, string keyName)
{
return _iniFile[sectionName].RemoveKey(keyName);
}

/// <inheritdoc />
protected override void SetValueImpl<T>(string sectionName, string keyName, T value)
{
if (!HasSection(sectionName))
{
_iniFile.Sections.AddSection(sectionName);
}

if (!HasSectionKey(sectionName, keyName))
{
_iniFile[sectionName].AddKey(keyName);
}

_iniFile[sectionName][keyName] = JsonConvert.SerializeObject(value);
}

/// <inheritdoc />
protected override object GetValueImpl(Type typeObject, string sectionName, string keyName)
{
return JsonConvert.DeserializeObject(_iniFile[sectionName][keyName], typeObject)
?? throw new ConfigurationException("Cannot deserialize value using the specified key.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net48;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>12</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ini-parser-netstandard" Version="2.5.2" />
<Reference Include="pyRevitLabs.Json" HintPath="$(PyRevitDevLibsDir)\pyRevitLabs.Json.dll" Private="false"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\pyRevitLabs.Configurations\pyRevitLabs.Configurations.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace pyRevitLabs.Configurations.Json.Extensions;

public static class JsonConfigurationExtensions
{
public static ConfigurationBuilder AddJsonConfiguration(
this ConfigurationBuilder builder, string configurationPath, string conigurationName, bool readOnly = default)
{
if (builder == null)
throw new ArgumentNullException(nameof(builder));

if (string.IsNullOrWhiteSpace(configurationPath))
throw new ArgumentException("Value cannot be null or whitespace.", nameof(configurationPath));

if (string.IsNullOrWhiteSpace(conigurationName))
throw new ArgumentException("Value cannot be null or whitespace.", nameof(conigurationName));

return builder.AddConfigurationSource(conigurationName, JsonConfiguration.Create(configurationPath, readOnly));
}
}
Loading