Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
eirannejad committed Apr 4, 2021
2 parents 9eb5df2 + 1f24228 commit 7eb0a4e
Show file tree
Hide file tree
Showing 82 changed files with 662 additions and 217 deletions.
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ black = "*"
docopt = "*"
requests = "*"
pygount = "*"
pyyaml = "*"
pyyaml = ">=5.4"

[requires]
python_version = "3.9"
Expand Down
97 changes: 51 additions & 46 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified bin/engines/CPY378/pyRevitLabs.PythonNet.dll
Binary file not shown.
Binary file modified bin/engines/CPY385/pyRevitLabs.PythonNet.dll
Binary file not shown.
Binary file modified bin/engines/IPY2710/pyRevitLoader.dll
Binary file not shown.
Binary file modified bin/engines/IPY2710/pyRevitRunner.dll
Binary file not shown.
Binary file modified bin/engines/IPY2711PR/pyRevitLabs.IronPython.Modules.dll
Binary file not shown.
Binary file modified bin/engines/IPY2711PR/pyRevitLabs.IronPython.SQLite.dll
Binary file not shown.
Binary file modified bin/engines/IPY2711PR/pyRevitLabs.IronPython.Wpf.dll
Binary file not shown.
Binary file modified bin/engines/IPY2711PR/pyRevitLabs.IronPython.dll
Binary file not shown.
Binary file modified bin/engines/IPY2711PR/pyRevitLabs.Microsoft.Dynamic.dll
Binary file not shown.
Binary file modified bin/engines/IPY2711PR/pyRevitLabs.Microsoft.Scripting.Metadata.dll
Binary file not shown.
Binary file modified bin/engines/IPY2711PR/pyRevitLabs.Microsoft.Scripting.dll
Binary file not shown.
Binary file modified bin/engines/IPY2711PR/pyRevitLoader.dll
Binary file not shown.
Binary file modified bin/engines/IPY2711PR/pyRevitRunner.dll
Binary file not shown.
Binary file modified bin/engines/IPY273/pyRevitLoader.dll
Binary file not shown.
Binary file modified bin/engines/IPY273/pyRevitRunner.dll
Binary file not shown.
Binary file modified bin/engines/IPY277/pyRevitLoader.dll
Binary file not shown.
Binary file modified bin/engines/IPY277/pyRevitRunner.dll
Binary file not shown.
Binary file modified bin/engines/IPY278/pyRevitLoader.dll
Binary file not shown.
Binary file modified bin/engines/IPY278/pyRevitRunner.dll
Binary file not shown.
Binary file modified bin/engines/IPY279/pyRevitLoader.dll
Binary file not shown.
Binary file modified bin/engines/IPY279/pyRevitRunner.dll
Binary file not shown.
Binary file modified bin/pyRevitLabs.Common.dll
Binary file not shown.
Binary file modified bin/pyRevitLabs.CommonCLI.dll
Binary file not shown.
Binary file modified bin/pyRevitLabs.CommonWPF.dll
Binary file not shown.
Binary file modified bin/pyRevitLabs.DeffrelDB.dll
Binary file not shown.
Binary file modified bin/pyRevitLabs.Emojis.dll
Binary file not shown.
Binary file modified bin/pyRevitLabs.Json.dll
Binary file not shown.
Binary file modified bin/pyRevitLabs.Language.dll
Binary file not shown.
Binary file modified bin/pyRevitLabs.MahAppsMetro.dll
Binary file not shown.
Binary file modified bin/pyRevitLabs.NLog.dll
Binary file not shown.
Binary file modified bin/pyRevitLabs.PyRevit.dll
Binary file not shown.
Binary file modified bin/pyRevitLabs.TargetApps.AutoCAD.dll
Binary file not shown.
Binary file modified bin/pyRevitLabs.TargetApps.Navisworks.dll
Binary file not shown.
Binary file modified bin/pyRevitLabs.TargetApps.Revit.dll
Binary file not shown.
Binary file modified bin/pyrevit-autocomplete.exe
Binary file not shown.
Binary file modified bin/pyrevit-doctor.exe
Binary file not shown.
12 changes: 12 additions & 0 deletions bin/pyrevit-products.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
[
{
"product": "pyRevit",
"release": "4.8.7",
"version": "4.8.7",
"key": "{FED5DEF7-8D3B-4832-BB3E-55C10FCF9ACF}"
},
{
"product": "pyRevit",
"release": "4.8.6",
Expand Down Expand Up @@ -227,6 +233,12 @@
"version": "4.6.1",
"key": "{EF91A585-DC0C-43B8-B88B-4C130F430E84}"
},
{
"product": "pyRevit CLI",
"release": "4.8.7",
"version": "4.8.7",
"key": "{E61BB97E-6FF1-4706-A92E-D9F38EB9C77B}"
},
{
"product": "pyRevit CLI",
"release": "4.8.6",
Expand Down
Binary file modified bin/pyrevit-stubsbuilder.exe
Binary file not shown.
Binary file modified bin/pyrevit-telemetryserver.exe
Binary file not shown.
Binary file modified bin/pyrevit-toast.exe
Binary file not shown.
Binary file modified bin/pyrevit.exe
Binary file not shown.
4 changes: 2 additions & 2 deletions dev/pyRevit/AssemblyVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;

[assembly: AssemblyVersion("4.8.6")]
[assembly: AssemblyFileVersion("4.8.6")]
[assembly: AssemblyVersion("4.8.7")]
[assembly: AssemblyFileVersion("4.8.7")]
21 changes: 15 additions & 6 deletions dev/pyRevitLabs/pyRevitCLI/PyRevitCLI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ internal static class PyRevitCLI {
internal static bool IsHelpUsagePatternMode = false;

// cli version property
public static string CLIPath => Assembly.GetExecutingAssembly().Location;
public static Version CLIVersion => Assembly.GetExecutingAssembly().GetName().Version;

// cli entry point:
Expand Down Expand Up @@ -218,12 +219,20 @@ private static void ProcessArguments() {
else if (all("open"))
PyRevitCLICloneCmds.OpenClone(TryGetValue("<clone_name>"));

else if (all("add"))
PyRevitCLICloneCmds.RegisterClone(
TryGetValue("<clone_name>"),
TryGetValue("<clone_path>"),
force: arguments["--force"].IsTrue
);
else if (all("add")) {
if(all("this"))
PyRevitCLICloneCmds.RegisterClone(
TryGetValue("<clone_name>"),
Path.GetDirectoryName(CLIPath),
force: arguments["--force"].IsTrue
);
else
PyRevitCLICloneCmds.RegisterClone(
TryGetValue("<clone_name>"),
TryGetValue("<clone_path>"),
force: arguments["--force"].IsTrue
);
}

else if (all("forget"))
PyRevitCLICloneCmds.ForgetClone(
Expand Down
2 changes: 2 additions & 0 deletions dev/pyRevitLabs/pyRevitCLI/PyRevitCLIAppHelps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ internal static void
{ "info", "Print info about clone" },
{ "open", "Open clone directory in file browser" },
{ "add", "Register an existing clone" },
{ "add this", "Register clone that contains this utility" },
{ "forget", "Forget a registered clone" },
{ "rename", "Rename a clone" },
{ "delete", "Delete a clone" },
Expand All @@ -116,6 +117,7 @@ internal static void
{ "<tag_name>", "Clone tag to rebase to" },
{ "<commit_hash>", "Clone commit rebase to" },
{ "<origin_url>", "New clone remote origin url" },
{ "--force", "Just do it; I know what I am doing" },
{ "--reset", "Reset remote origin url to default" },
{ "--clearconfigs", "Clear pyRevit configurations." },
{ "--all", "All clones" },
Expand Down
1 change: 1 addition & 0 deletions dev/pyRevitLabs/pyRevitCLI/Resources/UsagePatterns.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Usage:
pyrevit clone <clone_name> [--dest=<dest_path>] [--source=<repo_url>] [--branch=<branch_name>] [--log=<log_file>] [(--username=<username> --password=<password> | --token=<auth_token>)]
pyrevit clones [(-h | --help)]
pyrevit clones (info | open) <clone_name>
pyrevit clones add this <clone_name> [--force] [--log=<log_file>]
pyrevit clones add <clone_name> <clone_path> [--force] [--log=<log_file>]
pyrevit clones forget (--all | <clone_name>) [--log=<log_file>]
pyrevit clones rename <clone_name> <clone_new_name> [--log=<log_file>]
Expand Down
43 changes: 41 additions & 2 deletions dev/pyRevitLabs/pyRevitLabs.Common/CommonUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using pyRevitLabs.Common.Extensions;
using pyRevitLabs.NLog;
using System.Linq;
using System.Threading;

namespace pyRevitLabs.Common {
public static class CommonUtils {
Expand All @@ -29,6 +30,44 @@ public static bool VerifyFile(string filePath) {
return false;
}

// https://stackoverflow.com/a/937558/2350244
public static bool IsFileLocked(FileInfo file) {
try {
using (FileStream stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.None)) {
stream.Close();
}
}
catch (IOException) {
//the file is unavailable because it is:
//still being written to
//or being processed by another thread
//or does not exist (has already been processed)
return true;
}

//file is not locked
return false;
}

public static void VerifyFileAccessible(string filePath) {
// make sure file is accessible,
// try multiple times and wait a little in between
// fail after trying
var finfo = new FileInfo(filePath);

uint tries = 3;
do {
if (IsFileLocked(finfo)) {
Thread.Sleep(200);
tries--;
}
else
return;
} while (tries > 0);

throw new PyRevitException("File is not accessible");
}

public static bool VerifyPath(string path) {
if (path != null && path != string.Empty)
return Directory.Exists(path);
Expand Down Expand Up @@ -157,8 +196,8 @@ public static string DownloadFile(string url, string destPath, string progressTo
// while (client.IsBusy) ;
//}
//else {
logger.Debug("Downloading \"{0}\"", url);
client.DownloadFile(url, destPath);
logger.Debug("Downloading \"{0}\"", url);
client.DownloadFile(url, destPath);
//}
}
}
Expand Down
5 changes: 5 additions & 0 deletions dev/pyRevitLabs/pyRevitLabs.Common/UserEnv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ public static string GetLoggedInUserName() {
return null;
}

public static bool IsRunAsElevated() {
WindowsIdentity id = WindowsIdentity.GetCurrent();
return id.Owner != id.User;
}

public static bool IsRunAsAdmin() {
WindowsIdentity id = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(id);
Expand Down
1 change: 1 addition & 0 deletions dev/pyRevitLabs/pyRevitLabs.PyRevit/PyRevitConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class PyRevitConfig {
public PyRevitConfig(string cfgFilePath) {
if (cfgFilePath != null) {
if (CommonUtils.VerifyFile(cfgFilePath)) {
CommonUtils.VerifyFileAccessible(cfgFilePath);
ConfigFilePath = cfgFilePath;

// INI formatting
Expand Down
1 change: 1 addition & 0 deletions dev/pyRevitLabs/pyRevitLabs.PyRevit/PyRevitConfigs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public static void SeedConfig(bool makeCurrentUserAsOwner = false, string setupF
try {
if (File.Exists(sourceFile)) {
CommonUtils.EnsureFile(targetFile);
CommonUtils.VerifyFileAccessible(targetFile);
File.Copy(sourceFile, targetFile, true);

if (makeCurrentUserAsOwner) {
Expand Down
5 changes: 3 additions & 2 deletions dev/pyRevitLabs/pyRevitLabs.PyRevit/PyRevitConsts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,9 @@ public static string FindConfigFileInDirectory(string sourcePath) {
// @reviewed
public static string ConfigFilePath {
get {
var cfgFile = FindConfigFileInDirectory(PyRevitLabsConsts.PyRevitPath);
return cfgFile != null ? cfgFile : Path.Combine(PyRevitLabsConsts.PyRevitPath, DefaultConfigsFileName);
string configRoot = UserEnv.IsRunAsElevated() ? PyRevitLabsConsts.PyRevitProgramDataPath : PyRevitLabsConsts.PyRevitPath;
var cfgFile = FindConfigFileInDirectory(configRoot);
return cfgFile != null ? cfgFile : Path.Combine(configRoot, DefaultConfigsFileName);
}
}

Expand Down
3 changes: 3 additions & 0 deletions dev/pyRevitLabs/pyRevitLabs.TargetApps.Revit/RevitAddons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public static string GetRevitAddonsFolder(int revitYear, bool allUsers = false)
}

public static string GetRevitAddonsFilePath(int revitYear, string addinFileName, bool allusers = false) {
if (UserEnv.IsRunAsElevated())
allusers = true;

var rootFolder =
allusers ? System.Environment.SpecialFolder.CommonApplicationData : System.Environment.SpecialFolder.ApplicationData;
return Path.Combine(GetRevitAddonsFolder(revitYear, allUsers: allusers), addinFileName + ".addin");
Expand Down
13 changes: 13 additions & 0 deletions dev/pyRevitLoader/Source/PyRevitLoaderApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,26 @@
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;

/* Note:
* It is necessary that this code object do not have any references to IronPython.
* To ensure the correct version of IronPython dlls are loaded, the OnStartup()
* methods manually loads the IronPython assemblies before calling into the
* ScriptExecutor that has IronPython references
*/
namespace PyRevitLoader {
[Regeneration(RegenerationOption.Manual)]
[Transaction(TransactionMode.Manual)]
class PyRevitLoaderApplication : IExternalApplication {
public static string LoaderPath => Path.GetDirectoryName(typeof(PyRevitLoaderApplication).Assembly.Location);

// Hook into Revit to allow starting a command.
Result IExternalApplication.OnStartup(UIControlledApplication application) {
try {
// load all engine assemblies
// this is to ensure pyRevit is loaded on its own assemblies
foreach (var engineDll in Directory.GetFiles(LoaderPath, "*.dll"))
Assembly.LoadFrom(engineDll);

return ExecuteStartupScript(application);
}
catch (Exception ex) {
Expand Down
Loading

0 comments on commit 7eb0a4e

Please sign in to comment.