GetSetCloneBranch(string cloneName, string branchName) { if (cloneName != null) { var clone = PyRevit.GetRegisteredClone(cloneName); if (clone != null) { if (clone.IsRepoDeploy) { if (branchName != null) { clone.SetBranch(branchName); } else { Console.WriteLine(string.Format("Clone \"{0}\" is on branch \"{1}\"", clone.Name, clone.Branch)); } } else { PyRevitCLIAppCmds.ReportCloneAsNoGit(clone); } } } }
GetSetCloneOrigin(string cloneName, string originUrl, bool reset) { if (cloneName != null) { var clone = PyRevit.GetRegisteredClone(cloneName); if (clone.IsRepoDeploy) { if (originUrl != null || reset) { string newUrl = reset ? PyRevitConsts.OriginalRepoPath : originUrl; clone.SetOrigin(newUrl); } else { Console.WriteLine(string.Format("Clone \"{0}\" origin is at \"{1}\"", clone.Name, clone.Origin)); } } else { PyRevitCLIAppCmds.ReportCloneAsNoGit(clone); } } }
PrintExtensionDefinitions(string searchPattern, string headerPrefix = "Registered") { PyRevitCLIAppCmds.PrintHeader(string.Format("{0} Extensions", headerPrefix)); foreach (PyRevitExtensionDefinition ext in PyRevit.LookupRegisteredExtensions(searchPattern)) { Console.WriteLine(ext); } }
PrintSupportedRevits() { PyRevitCLIAppCmds.PrintHeader("Supported Revits"); foreach (var revit in RevitProduct.ListSupportedProducts().OrderByDescending(x => x.Version)) { Console.WriteLine(string.Format("{0} | Version: {1} | Build: {2}({3})", revit.ProductName, revit.Version, revit.BuildNumber, revit.BuildTarget)); } }
PrintExtensionSearchPaths() { PyRevitCLIAppCmds.PrintHeader("Default Extension Search Path"); Console.WriteLine(PyRevit.pyRevitDefaultExtensionsPath); PyRevitCLIAppCmds.PrintHeader("Extension Search Paths"); foreach (var searchPath in PyRevit.GetRegisteredExtensionSearchPaths()) { Console.WriteLine(searchPath); } }
PrintExtensionLookupSources() { PyRevitCLIAppCmds.PrintHeader("Extension Sources - Default"); Console.WriteLine(PyRevit.GetDefaultExtensionLookupSource()); PyRevitCLIAppCmds.PrintHeader("Extension Sources - Additional"); foreach (var extLookupSrc in PyRevit.GetRegisteredExtensionLookupSources()) { Console.WriteLine(extLookupSrc); } }
UpdateClone(bool allClones, string cloneName) { // TODO: ask for closing running Revits // prepare a list of clones to be updated var targetClones = new List <PyRevitClone>(); // separate the clone that this process might be running from // this is used to update this clone from outside since the dlls will be locked PyRevitClone myClone = null; // all clones if (allClones) { foreach (var clone in PyRevit.GetRegisteredClones()) { if (PyRevitCLIAppCmds.IsRunningInsideClone(clone)) { myClone = clone; } else { targetClones.Add(clone); } } } // or single clone else { if (cloneName != null) { var clone = PyRevit.GetRegisteredClone(cloneName); if (PyRevitCLIAppCmds.IsRunningInsideClone(clone)) { myClone = clone; } else { targetClones.Add(clone); } } } // update clones that do not include this process foreach (var clone in targetClones) { logger.Debug("Updating clone \"{0}\"", clone.Name); PyRevit.Update(clone); } // now update myClone if any, as last step if (myClone != null) { PyRevitCLIAppCmds.UpdateFromOutsideAndClose(myClone); } }
PrintCloneEngines(string cloneName) { if (cloneName != null) { var clone = PyRevit.GetRegisteredClone(cloneName); PyRevitCLIAppCmds.PrintHeader(string.Format("Deployments for \"{0}\"", clone.Name)); foreach (var engine in clone.GetConfiguredEngines()) { Console.WriteLine(engine); } } }
PrintExtensions(IEnumerable <PyRevitExtension> extList = null, string headerPrefix = "Installed") { if (extList == null) { extList = PyRevit.GetInstalledExtensions(); } PyRevitCLIAppCmds.PrintHeader(string.Format("{0} Extensions", headerPrefix)); foreach (PyRevitExtension ext in extList.OrderBy(x => x.Name)) { Console.WriteLine(ext); } }
PrintAttachments(int revitYear = 0) { PyRevitCLIAppCmds.PrintHeader("Attachments"); foreach (var attachment in PyRevit.GetAttachments().OrderByDescending(x => x.Product.Version)) { if (revitYear == 0) { Console.WriteLine(attachment); } else if (revitYear == attachment.Product.ProductYear) { Console.WriteLine(attachment); } } }
PrintClones() { PyRevitCLIAppCmds.PrintHeader("Registered Clones (full git repos)"); var clones = PyRevit.GetRegisteredClones().OrderBy(x => x.Name); foreach (var clone in clones.Where(c => c.IsRepoDeploy)) { Console.WriteLine(clone); } PyRevitCLIAppCmds.PrintHeader("Registered Clones (deployed from archive/image)"); foreach (var clone in clones.Where(c => !c.IsRepoDeploy)) { Console.WriteLine(clone); } }
PrintCloneDeployments(string cloneName) { if (cloneName != null) { var clone = PyRevit.GetRegisteredClone(cloneName); PyRevitCLIAppCmds.PrintHeader(string.Format("Deployments for \"{0}\"", clone.Name)); foreach (var dep in clone.GetConfiguredDeployments()) { Console.WriteLine(string.Format("\"{0}\" deploys:", dep.Name)); foreach (var path in dep.Paths) { Console.WriteLine(" " + path); } Console.WriteLine(); } } }
PrintLocalRevits(bool running = false) { if (running) { PyRevitCLIAppCmds.PrintHeader("Running Revit Instances"); foreach (var revit in RevitController.ListRunningRevits().OrderByDescending(x => x.RevitProduct.Version)) { Console.WriteLine(revit); } } else { PyRevitCLIAppCmds.PrintHeader("Installed Revits"); foreach (var revit in RevitProduct.ListInstalledProducts().OrderByDescending(x => x.Version)) { Console.WriteLine(revit); } } }
private static string GetBundleTemplate(PyRevitBundleTypes bundleType, string templatesDir = null) { templatesDir = templatesDir != null ? templatesDir : PyRevitCLIAppCmds.GetTemplatesPath(); if (CommonUtils.VerifyPath(templatesDir)) { var bundleTempPath = Path.Combine(templatesDir, "template" + PyRevitBundle.GetBundleDirExt(bundleType)); if (CommonUtils.VerifyPath(bundleTempPath)) { return(bundleTempPath); } } else { throw new pyRevitException( string.Format("Templates directory does not exist at \"{0}\"", templatesDir) ); } return(null); }
PrintReleases(string searchPattern, bool latest = false, bool printReleaseNotes = false, bool listPreReleases = false) { PyRevitCLIAppCmds.PrintHeader("Releases"); List <PyRevitRelease> releasesToList = new List <PyRevitRelease>(); // determine latest release if (latest) { var latestRelease = PyRevitRelease.GetLatestRelease(includePreRelease: listPreReleases); if (latestRelease == null) { throw new pyRevitException("Can not determine latest release."); } releasesToList.Add(latestRelease); } else { if (searchPattern != null) { releasesToList = PyRevitRelease.FindReleases(searchPattern, includePreRelease: listPreReleases); } else { releasesToList = PyRevitRelease.GetReleases().Where(r => r.IsPyRevitRelease).ToList(); } } foreach (var prelease in releasesToList) { Console.WriteLine(prelease); if (printReleaseNotes) { Console.WriteLine(prelease.ReleaseNotes.Indent(1)); } } }
GetSetCloneCommit(string cloneName, string commitHash) { if (cloneName != null) { var clone = PyRevit.GetRegisteredClone(cloneName); if (clone.IsRepoDeploy) { if (commitHash != null) { clone.SetCommit(commitHash); } else { Console.WriteLine(string.Format("Clone \"{0}\" is on commit \"{1}\"", clone.Name, clone.Commit)); } } else { PyRevitCLIAppCmds.ReportCloneAsNoGit(clone); } } }
// cli argument processor private static void ProcessArguments() { if (IsHelpUsagePatternMode) { Console.WriteLine(UsagePatterns.Replace("\t", " ")); } else if (IsVersionMode) { PyRevitCLIAppCmds.PrintVersion(); } else if (all("help")) { PyRevitCLIAppHelps.OpenHelp(); } else if (all("blog")) { CommonUtils.OpenUrl(PyRevitConsts.BlogsUrl); } else if (all("docs")) { CommonUtils.OpenUrl(PyRevitConsts.DocsUrl); } else if (all("source")) { CommonUtils.OpenUrl(PyRevitConsts.SourceRepoUrl); } else if (all("youtube")) { CommonUtils.OpenUrl(PyRevitConsts.YoutubeUrl); } else if (all("support")) { CommonUtils.OpenUrl(PyRevitConsts.SupportRepoUrl); } else if (all("env")) { if (IsHelpMode) { PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Env); } else { PyRevitCLIAppCmds.MakeEnvReport(json: arguments["--json"].IsTrue); } } else if (all("clone")) { if (IsHelpMode) { PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Clone); } else { PyRevitCLICloneCmds.CreateClone( cloneName: TryGetValue("<clone_name>"), deployName: TryGetValue("<deployment_name>"), branchName: TryGetValue("--branch"), repoUrl: TryGetValue("--source"), imagePath: TryGetValue("--image"), destPath: TryGetValue("--dest") ); } } else if (all("clones")) { if (IsHelpMode) { PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Clones); } else if (all("info")) { PyRevitCLICloneCmds.PrintCloneInfo(TryGetValue("<clone_name>")); } 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("forget")) { PyRevitCLICloneCmds.ForgetClone( allClones: arguments["--all"].IsTrue, cloneName: TryGetValue("<clone_name>") ); } else if (all("rename")) { PyRevitCLICloneCmds.RenameClone( cloneName: TryGetValue("<clone_name>"), cloneNewName: TryGetValue("<clone_new_name>") ); } else if (all("delete")) { PyRevitCLICloneCmds.DeleteClone( allClones: arguments["--all"].IsTrue, cloneName: TryGetValue("<clone_name>"), clearConfigs: arguments["--clearconfigs"].IsTrue ); } else if (all("branch")) { PyRevitCLICloneCmds.GetSetCloneBranch( cloneName: TryGetValue("<clone_name>"), branchName: TryGetValue("<branch_name>") ); } else if (all("version")) { PyRevitCLICloneCmds.GetSetCloneTag( cloneName: TryGetValue("<clone_name>"), tagName: TryGetValue("<tag_name>") ); } else if (all("commit")) { PyRevitCLICloneCmds.GetSetCloneCommit( cloneName: TryGetValue("<clone_name>"), commitHash: TryGetValue("<commit_hash>") ); } else if (all("origin")) { PyRevitCLICloneCmds.GetSetCloneOrigin( cloneName: TryGetValue("<clone_name>"), originUrl: TryGetValue("<origin_url>"), reset: arguments["--reset"].IsTrue ); } else if (all("deployments")) { PyRevitCLICloneCmds.PrintCloneDeployments(TryGetValue("<clone_name>")); } else if (all("engines")) { PyRevitCLICloneCmds.PrintCloneEngines(TryGetValue("<clone_name>")); } else if (all("update")) { PyRevitCLICloneCmds.UpdateClone( allClones: arguments["--all"].IsTrue, cloneName: TryGetValue("<clone_name>") ); } else { PyRevitCLICloneCmds.PrintClones(); } } else if (all("attach")) { if (IsHelpMode) { PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Attach); } else { PyRevitCLICloneCmds.AttachClone( cloneName: TryGetValue("<clone_name>"), latest: arguments["latest"].IsTrue, dynamoSafe: arguments["dynamosafe"].IsTrue, engineVersion: TryGetValue("<engine_version>"), revitYear: TryGetValue("<revit_year>"), installed: arguments["--installed"].IsTrue, attached: arguments["--attached"].IsTrue, allUsers: arguments["--allusers"].IsTrue ); } } else if (all("detach")) { if (IsHelpMode) { PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Detach); } else { PyRevitCLICloneCmds.DetachClone( revitYear: TryGetValue("<revit_year>"), all: arguments["--all"].IsTrue ); } } else if (all("attached")) { if (IsHelpMode) { PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Attached); } else { PyRevitCLICloneCmds.ListAttachments(revitYear: TryGetValue("<revit_year>")); } } else if (all("switch")) { if (IsHelpMode) { PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Switch); } else { PyRevitCLICloneCmds.SwitchAttachment( cloneName: TryGetValue("<clone_name>"), revitYear: TryGetValue("<revit_year>") ); } } else if (all("extend")) { if (IsHelpMode) { PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Extend); } else if (any("ui", "lib", "run")) { PyRevitCLIExtensionCmds.Extend( ui: arguments["ui"].IsTrue, lib: arguments["lib"].IsTrue, run: arguments["run"].IsTrue, extName: TryGetValue("<extension_name>"), destPath: TryGetValue("--dest"), repoUrl: TryGetValue("<repo_url>"), branchName: TryGetValue("--branch") ); } else { PyRevitCLIExtensionCmds.Extend( extName: TryGetValue("<extension_name>"), destPath: TryGetValue("--dest"), branchName: TryGetValue("--branch") ); } } else if (all("extensions")) { if (all("search")) { PyRevitCLIExtensionCmds.PrintExtensionDefinitions( searchPattern: TryGetValue("<search_pattern>"), headerPrefix: "Matched" ); } else if (any("info", "help", "open")) { PyRevitCLIExtensionCmds.ProcessExtensionInfoCommands( extName: TryGetValue("<extension_name>"), info: arguments["info"].IsTrue, help: arguments["help"].IsTrue, open: arguments["open"].IsTrue ); } else if (all("delete")) { PyRevitCLIExtensionCmds.DeleteExtension(TryGetValue("<extension_name>")); } else if (all("origin")) { PyRevitCLIExtensionCmds.GetSetExtensionOrigin( extName: TryGetValue("<extension_name>"), originUrl: TryGetValue("<origin_url>"), reset: arguments["--reset"].IsTrue ); } else if (all("paths")) { if (IsHelpMode) { PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.ExtensionsPaths); } else if (all("add")) { PyRevitCLIExtensionCmds.AddExtensionPath( searchPath: TryGetValue("<extensions_path>") ); } else if (all("forget")) { PyRevitCLIExtensionCmds.ForgetAllExtensionPaths( all: arguments["--all"].IsTrue, searchPath: TryGetValue("<extensions_path>") ); } else { PyRevitCLIExtensionCmds.PrintExtensionSearchPaths(); } } else if (any("enable", "disable")) { PyRevitCLIExtensionCmds.ToggleExtension( enable: arguments["enable"].IsTrue, extName: TryGetValue("<extension_name>") ); } else if (all("sources")) { Console.WriteLine("dfsdfsd"); if (IsHelpMode) { PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.ExtensionsSources); } else if (all("add")) { PyRevitCLIExtensionCmds.AddExtensionLookupSource( lookupPath: TryGetValue("<source_json_or_url>") ); } else if (all("forget")) { PyRevitCLIExtensionCmds.ForgetExtensionLookupSources( all: arguments["--all"].IsTrue, lookupPath: TryGetValue("<source_json_or_url>") ); } else { PyRevitCLIExtensionCmds.PrintExtensionLookupSources(); } } else if (all("update")) { PyRevitCLIExtensionCmds.UpdateExtension( all: arguments["--all"].IsTrue, extName: TryGetValue("<extension_name>") ); } else if (IsHelpMode) { PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Extensions); } else { PyRevitCLIExtensionCmds.PrintExtensions(); } } else if (all("releases")) { if (IsHelpMode) { PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Releases); } else if (all("open")) { PyRevitCLIReleaseCmds.OpenReleasePage( searchPattern: TryGetValue("<search_pattern>"), latest: arguments["latest"].IsTrue, listPreReleases: arguments["--pre"].IsTrue ); } else if (all("download")) { PyRevitCLIReleaseCmds.DownloadReleaseAsset( arguments["archive"].IsTrue ? PyRevitReleaseAssetType.Archive : PyRevitReleaseAssetType.Installer, destPath: TryGetValue("--dest"), searchPattern: TryGetValue("<search_pattern>"), latest: arguments["latest"].IsTrue, listPreReleases: arguments["--pre"].IsTrue ); } else { PyRevitCLIReleaseCmds.PrintReleases( searchPattern: TryGetValue("<search_pattern>"), latest: arguments["latest"].IsTrue, printReleaseNotes: arguments["--notes"].IsTrue, listPreReleases: arguments["--pre"].IsTrue ); } } else if (all("image")) { if (IsHelpMode) { PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Image); } else { PyRevitCLICloneCmds.BuildImage( cloneName: TryGetValue("<clone_name>"), configFile: TryGetValue("--config"), imageFilePath: TryGetValue("--dest") ); } } else if (all("revits")) { if (all("killall")) { PyRevitCLIRevitCmds.KillAllRevits( revitYear: TryGetValue("<revit_year>") ); } else if (all("fileinfo")) { PyRevitCLIRevitCmds.ProcessFileInfo( targetPath: TryGetValue("<file_or_dir_path>"), outputCSV: TryGetValue("--csv"), IncludeRVT: arguments["--rvt"].IsTrue, includeRTE: arguments["--rte"].IsTrue, includeRFA: arguments["--rfa"].IsTrue, includeRFT: arguments["--rft"].IsTrue ); } else if (all("addons")) { if (IsHelpMode) { PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.RevitsAddons); } else if (all("prepare")) { PyRevitCLIRevitCmds.PrepareAddonsDir( revitYear: TryGetValue("<revit_year>"), allUses: arguments["--allusers"].IsTrue ); } else if (any("install", "uninstall")) { // TODO: implement revit addon manager logger.Error("Revit addon manager is not implemented yet"); } } else if (IsHelpMode) { PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Revits); } else if (arguments["--supported"].IsTrue) { PyRevitCLIRevitCmds.ProcessBuildInfo( outputCSV: TryGetValue("--csv") ); } else { PyRevitCLIRevitCmds.PrintLocalRevits(running: arguments["--installed"].IsFalse); } } else if (all("run")) { if (IsHelpMode) { PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Run); } else { PyRevitCLIRevitCmds.RunPythonCommand( inputCommand: TryGetValue("<script_or_command_name>"), targetFile: TryGetValue("<model_file>"), revitYear: TryGetValue("--revit"), runOptions: new PyRevitRunnerOptions() { PurgeTempFiles = arguments["--purge"].IsTrue, ImportPath = TryGetValue("--import", null) } ); } } else if (all("init")) { if (IsHelpMode) { PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Init); } else if (any("ui", "lib", "run")) { PyRevitCLLInitCmds.InitExtension( ui: arguments["ui"].IsTrue, lib: arguments["lib"].IsTrue, run: arguments["run"].IsTrue, extensionName: TryGetValue("<extension_name>"), templatesDir: TryGetValue("--templates"), useTemplate: arguments["--usetemplate"].IsTrue ); } else if (any("tab", "panel", "panelopt", "pull", "split", "splitpush", "push", "smart", "command")) { PyRevitCLLInitCmds.InitBundle( tab: arguments["tab"].IsTrue, panel: arguments["panel"].IsTrue, panelopt: arguments["panelopt"].IsTrue, pull: arguments["pull"].IsTrue, split: arguments["split"].IsTrue, splitpush: arguments["splitpush"].IsTrue, push: arguments["push"].IsTrue, smart: arguments["smart"].IsTrue, command: arguments["command"].IsTrue, bundleName: TryGetValue("<bundle_name>"), templatesDir: TryGetValue("--templates"), useTemplate: arguments["--usetemplate"].IsTrue ); } } else if (all("caches")) { if (IsHelpMode) { PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Caches); } else if (all("clear")) { PyRevitCLIAppCmds.ClearCaches( allCaches: arguments["--all"].IsTrue, revitYear: TryGetValue("<revit_year>") ); } } else if (all("config")) { if (IsHelpMode) { PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Config); } else { PyRevitCLIConfigCmds.SeedConfigs( templateConfigFilePath: TryGetValue("<template_config_path>") ); } } else if (all("configs")) { if (IsHelpMode) { PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Configs); } else if (all("logs")) { Console.WriteLine(string.Format("Logging Level is {0}", PyRevit.GetLoggingLevel().ToString())); } else if (all("logs", "none")) { PyRevit.SetLoggingLevel(PyRevitLogLevels.None); } else if (all("logs", "verbose")) { PyRevit.SetLoggingLevel(PyRevitLogLevels.Verbose); } else if (all("logs", "debug")) { PyRevit.SetLoggingLevel(PyRevitLogLevels.Debug); } // TODO: Implement allowremotedll else if (all("allowremotedll")) { throw new NotImplementedException(); } else if (all("checkupdates")) { if (any("enable", "disable")) { PyRevit.SetCheckUpdates(arguments["enable"].IsTrue); } else { Console.WriteLine(string.Format("Check Updates is {0}", PyRevit.GetCheckUpdates() ? "Enabled" : "Disabled")); } } else if (all("autoupdate")) { if (any("enable", "disable")) { PyRevit.SetAutoUpdate(arguments["enable"].IsTrue); } else { Console.WriteLine(string.Format("Auto Update is {0}", PyRevit.GetAutoUpdate() ? "Enabled" : "Disabled")); } } else if (all("rocketmode")) { if (any("enable", "disable")) { PyRevit.SetRocketMode(arguments["enable"].IsTrue); } else { Console.WriteLine(string.Format("Rocket Mode is {0}", PyRevit.GetRocketMode() ? "Enabled" : "Disabled")); } } else if (all("filelogging")) { if (any("enable", "disable")) { PyRevit.SetFileLogging(arguments["enable"].IsTrue); } else { Console.WriteLine(string.Format("File Logging is {0}", PyRevit.GetFileLogging() ? "Enabled" : "Disabled")); } } else if (all("loadbeta")) { if (any("enable", "disable")) { PyRevit.SetLoadBetaTools(arguments["enable"].IsTrue); } else { Console.WriteLine(string.Format("Load Beta is {0}", PyRevit.GetLoadBetaTools() ? "Enabled" : "Disabled")); } } else if (all("usercanupdate")) { if (any("enable", "disable")) { PyRevit.SetUserCanUpdate(arguments["Yes"].IsTrue); } else { Console.WriteLine(string.Format("User {0} update.", PyRevit.GetUserCanUpdate() ? "CAN" : "CAN NOT")); } } else if (all("usercanextend")) { if (any("enable", "disable")) { PyRevit.SetUserCanExtend(arguments["Yes"].IsTrue); } else { Console.WriteLine(string.Format("User {0} extend.", PyRevit.GetUserCanExtend() ? "CAN" : "CAN NOT")); } } else if (all("usercanconfig")) { if (any("enable", "disable")) { PyRevit.SetUserCanConfig(arguments["Yes"].IsTrue); } else { Console.WriteLine(string.Format("User {0} config.", PyRevit.GetUserCanConfig() ? "CAN" : "CAN NOT")); } } else if (all("usagelogging")) { if (all("enable", "file")) { PyRevit.EnableUsageReporting(logFilePath: TryGetValue("<dest_path>")); } else if (all("enable", "server")) { PyRevit.EnableUsageReporting(logServerUrl: TryGetValue("<dest_path>")); } else if (all("disable")) { PyRevit.DisableUsageReporting(); } else { Console.WriteLine(string.Format("Usage logging is {0}", PyRevit.GetUsageReporting() ? "Enabled" : "Disabled")); Console.WriteLine(string.Format("Log File Path: {0}", PyRevit.GetUsageLogFilePath())); Console.WriteLine(string.Format("Log Server Url: {0}", PyRevit.GetUsageLogServerUrl())); } } else if (all("outputcss")) { if (arguments["<css_path>"] == null) { Console.WriteLine(string.Format("Output Style Sheet is set to: {0}", PyRevit.GetOutputStyleSheet())); } else { PyRevit.SetOutputStyleSheet(TryGetValue("<css_path>")); } } else if (all("seed")) { PyRevit.SeedConfig(makeCurrentUserAsOwner: arguments["--lock"].IsTrue); } else if (all("enable", "disable")) { if (arguments["<option_path>"] != null) { // extract section and option names string orignalOptionValue = TryGetValue("<option_path>"); if (orignalOptionValue.Split(':').Count() == 2) { string configSection = orignalOptionValue.Split(':')[0]; string configOption = orignalOptionValue.Split(':')[1]; PyRevit.SetConfig(configSection, configOption, arguments["enable"].IsTrue); } } } else { if (arguments["<option_path>"] != null) { // extract section and option names string orignalOptionValue = TryGetValue("<option_path>"); if (orignalOptionValue.Split(':').Count() == 2) { string configSection = orignalOptionValue.Split(':')[0]; string configOption = orignalOptionValue.Split(':')[1]; // if no value provided, read the value if (arguments["<option_value>"] != null) { PyRevit.SetConfig( configSection, configOption, TryGetValue("<option_value>") ); } else if (arguments["<option_value>"] == null) { Console.WriteLine( string.Format("{0} = {1}", configOption, PyRevit.GetConfig(configSection, configOption) )); } } } } } else if (all("cli")) { if (IsHelpMode) { PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Cli); } else if (all("addshortcut")) { PyRevitCLIAppCmds.AddCLIShortcut( shortcutName: TryGetValue("<shortcut_name>"), shortcutArgs: TryGetValue("<shortcut_args>"), shortcutDesc: TryGetValue("--desc"), allUsers: arguments["--allusers"].IsTrue ); } else if (all("installautocomplete")) { PyRevitCLIAppCmds.ActivateAutoComplete(); } } else if (IsHelpMode) { PyRevitCLIAppHelps.PrintHelp(PyRevitCLICommandType.Main); } }
PrintCloneInfo(string cloneName) { PyRevitCLIAppCmds.PrintHeader("Clone info"); Console.WriteLine(PyRevit.GetRegisteredClone(cloneName)); }
RunPythonCommand(string inputCommand, string targetFile, string revitYear, PyRevitRunnerOptions runOptions) { // determine if script or command var modelFiles = new List <string>(); // make sure file exists if (targetFile != null) { CommonUtils.VerifyFile(targetFile); } if (inputCommand != null) { // determine target revit year int revitYearNumber = 0; // if revit year is not specified try to get from model file if (revitYear == null) { if (targetFile != null) { try { revitYearNumber = new RevitModelFile(targetFile).RevitProduct.ProductYear; // collect model names also modelFiles.Add(targetFile); } catch (Exception ex) { logger.Error( "Revit version must be explicitly specifies if using a model list file. | {0}", ex.Message ); } } // if no revit year and no model, run with latest revit else { revitYearNumber = RevitProduct.ListInstalledProducts().Max(r => r.ProductYear); } } // otherwise, grab the year from argument else { revitYearNumber = int.Parse(revitYear); // prepare model list of provided if (targetFile != null) { try { var modelVer = new RevitModelFile(targetFile).RevitProduct.ProductYear; if (revitYearNumber < modelVer) { logger.Warn("Model is newer than the target Revit version."); } else { modelFiles.Add(targetFile); } } catch { // attempt at reading the list file and grab the model files only foreach (var modelPath in File.ReadAllLines(targetFile)) { if (CommonUtils.VerifyFile(modelPath)) { try { var modelVer = new RevitModelFile(modelPath).RevitProduct.ProductYear; if (revitYearNumber < modelVer) { logger.Warn("Model is newer than the target Revit version."); } else { modelFiles.Add(modelPath); } } catch { logger.Error("File is not a valid Revit file: \"{0}\"", modelPath); } } else { logger.Error("File does not exist: \"{0}\"", modelPath); } } } } } // now run if (revitYearNumber != 0) { // determine attached clone var attachment = PyRevit.GetAttached(revitYearNumber); if (attachment == null) { logger.Error("pyRevit is not attached to Revit \"{0}\". " + "Runner needs to use the attached clone and engine to execute the script.", revitYear); } else { // determine script to run string commandScriptPath = null; if (!CommonUtils.VerifyPythonScript(inputCommand)) { logger.Debug("Input is not a script file \"{0}\"", inputCommand); logger.Debug("Attempting to find run command matching \"{0}\"", inputCommand); // try to find run command in attached clone being used for execution // if not found, try to get run command from all other installed extensions var targetExtensions = new List <PyRevitExtension>(); if (attachment.Clone != null) { targetExtensions.AddRange(attachment.Clone.GetExtensions()); } targetExtensions.AddRange(PyRevit.GetInstalledExtensions()); foreach (PyRevitExtension ext in targetExtensions) { logger.Debug("Searching for run command in: \"{0}\"", ext.ToString()); if (ext.Type == PyRevitExtensionTypes.RunnerExtension) { try { var cmdScript = ext.GetRunCommand(inputCommand); if (cmdScript != null) { logger.Debug("Run command matching \"{0}\" found: \"{1}\"", inputCommand, cmdScript); commandScriptPath = cmdScript; break; } } catch { // does not include command continue; } } } } else { commandScriptPath = inputCommand; } // if command is not found, stop if (commandScriptPath == null) { throw new pyRevitException( string.Format("Run command not found: \"{0}\"", inputCommand) ); } // RUN! var execEnv = PyRevitRunner.Run( attachment, commandScriptPath, modelFiles, runOptions ); // print results (exec env) PyRevitCLIAppCmds.PrintHeader("Execution Environment"); Console.WriteLine(string.Format("Execution Id: \"{0}\"", execEnv.ExecutionId)); Console.WriteLine(string.Format("Product: {0}", execEnv.Revit)); Console.WriteLine(string.Format("Clone: {0}", execEnv.Clone)); Console.WriteLine(string.Format("Engine: {0}", execEnv.Engine)); Console.WriteLine(string.Format("Script: \"{0}\"", execEnv.Script)); Console.WriteLine(string.Format("Working Directory: \"{0}\"", execEnv.WorkingDirectory)); Console.WriteLine(string.Format("Journal File: \"{0}\"", execEnv.JournalFile)); Console.WriteLine(string.Format("Manifest File: \"{0}\"", execEnv.PyRevitRunnerManifestFile)); Console.WriteLine(string.Format("Log File: \"{0}\"", execEnv.LogFile)); // report whether the env was purge or not if (execEnv.Purged) { Console.WriteLine("Execution env is successfully purged."); } // print target models if (execEnv.ModelPaths.Count() > 0) { PyRevitCLIAppCmds.PrintHeader("Target Models"); foreach (var modelPath in execEnv.ModelPaths) { Console.WriteLine(modelPath); } } // print log file contents if exists if (File.Exists(execEnv.LogFile)) { PyRevitCLIAppCmds.PrintHeader("Execution Log"); Console.WriteLine(File.ReadAllText(execEnv.LogFile)); } } } } }