Exemplo n.º 1
0
        InitExtension(bool ui, bool lib, bool run, string extensionName, string templatesDir, bool useTemplate)
        {
            PyRevitExtensionTypes extType = PyRevitExtensionTypes.Unknown;

            if (ui)
            {
                extType = PyRevitExtensionTypes.UIExtension;
            }
            else if (lib)
            {
                extType = PyRevitExtensionTypes.LibraryExtension;
            }
            else if (run)
            {
                extType = PyRevitExtensionTypes.RunnerExtension;
            }


            var extDirPostfix = PyRevitExtension.GetExtensionDirExt(extType);

            if (extensionName != null)
            {
                var pwd = Directory.GetCurrentDirectory();

                if (CommonUtils.EnsureFileNameIsUnique(pwd, extensionName))
                {
                    var extDir = Path.Combine(
                        pwd,
                        string.Format("{0}{1}", extensionName, extDirPostfix)
                        );

                    var extTemplateDir = GetExtensionTemplate(extType, templatesDir: templatesDir);
                    if (useTemplate && extTemplateDir != null)
                    {
                        CommonUtils.CopyDirectory(extTemplateDir, extDir);
                        Console.WriteLine(
                            string.Format("Extension directory created from template: \"{0}\"", extDir)
                            );
                    }
                    else
                    {
                        if (!Directory.Exists(extDir))
                        {
                            var dinfo = Directory.CreateDirectory(extDir);
                            Console.WriteLine(string.Format("{0} directory created: \"{1}\"", extType, extDir));
                        }
                        else
                        {
                            throw new pyRevitException("Directory already exists.");
                        }
                    }
                }
                else
                {
                    throw new pyRevitException(
                              string.Format("Another extension with name \"{0}\" already exists.", extensionName)
                              );
                }
            }
        }
Exemplo n.º 2
0
        public static string GetExtensionDirExt(PyRevitExtensionTypes extType)
        {
            switch (extType)
            {
            case PyRevitExtensionTypes.UIExtension: return(PyRevitConsts.ExtensionUIPostfix);

            case PyRevitExtensionTypes.LibraryExtension: return(PyRevitConsts.ExtensionLibraryPostfix);

            default: return(null);
            }
        }
        Extend(bool ui, bool lib, string extName, string destPath, string repoUrl, string branchName, string username, string password)
        {
            PyRevitExtensionTypes extType = PyRevitExtensionTypes.Unknown;

            if (ui)
            {
                extType = PyRevitExtensionTypes.UIExtension;
            }
            else if (lib)
            {
                extType = PyRevitExtensionTypes.LibraryExtension;
            }

            PyRevitExtensions.InstallExtension(extName, extType, repoUrl, destPath, branchName, username, password);
        }
        Extend(bool ui, bool lib, string extName, string destPath, string repoUrl, string branchName, GitInstallerCredentials credentials)
        {
            PyRevitExtensionTypes extType = PyRevitExtensionTypes.Unknown;

            if (ui)
            {
                extType = PyRevitExtensionTypes.UIExtension;
            }
            else if (lib)
            {
                extType = PyRevitExtensionTypes.LibraryExtension;
            }

            PyRevitExtensions.InstallExtension(extName, extType, repoUrl, destPath, branchName, credentials);
        }
        Extend(bool ui, bool lib, bool run, string extName, string destPath, string repoUrl, string branchName)
        {
            PyRevitExtensionTypes extType = PyRevitExtensionTypes.Unknown;

            if (ui)
            {
                extType = PyRevitExtensionTypes.UIExtension;
            }
            else if (lib)
            {
                extType = PyRevitExtensionTypes.LibraryExtension;
            }
            else if (run)
            {
                extType = PyRevitExtensionTypes.RunnerExtension;
            }

            PyRevit.InstallExtension(extName, extType, repoUrl, destPath, branchName);
        }
Exemplo n.º 6
0
        // private extensions and bundles
        private static string GetExtensionTemplate(PyRevitExtensionTypes extType, string templatesDir = null)
        {
            templatesDir = templatesDir != null ? templatesDir : PyRevitCLIAppCmds.GetTemplatesPath();
            if (CommonUtils.VerifyPath(templatesDir))
            {
                var extTempPath =
                    Path.Combine(templatesDir, "template" + PyRevitExtension.GetExtensionDirExt(extType));
                if (CommonUtils.VerifyPath(extTempPath))
                {
                    return(extTempPath);
                }
            }
            else
            {
                throw new pyRevitException(
                          string.Format("Templates directory does not exist at \"{0}\"", templatesDir)
                          );
            }


            return(null);
        }
Exemplo n.º 7
0
 public static string MakeConfigName(string extName, PyRevitExtensionTypes extType)
 {
     return(extName + GetExtensionDirExt(extType));
 }
Exemplo n.º 8
0
        // installs extension from repo url
        // @handled @logs
        public static void InstallExtension(string extensionName, PyRevitExtensionTypes extensionType,
                                            string repoPath, string destPath = null, string branchName = null,
                                            string username = null, string password = null)
        {
            // make sure extension is not installed already
            try {
                var existExt = GetInstalledExtension(extensionName);
                if (existExt != null)
                {
                    throw new PyRevitException(string.Format("Extension \"{0}\" is already installed under \"{1}\"",
                                                             existExt.Name, existExt.InstallPath));
                }
            }
            catch {
                // extension is not installed so everything is fine
            }

            // determine repo folder name
            // Name.extension for UI Extensions
            // Name.lib for Library Extensions
            string extDestDirName = PyRevitExtension.MakeConfigName(extensionName, extensionType);

            // determine destination
            destPath = destPath ?? PyRevitConsts.DefaultExtensionsPath;
            string finalExtRepoPath = Path.Combine(destPath, extDestDirName).NormalizeAsPath();

            // determine branch name
            branchName = branchName ?? PyRevitConsts.DefaultExtensionRepoDefaultBranch;

            logger.Debug("Extension branch name determined as \"{0}\"", branchName);
            logger.Debug("Installing extension into \"{0}\"", finalExtRepoPath);

            // start the clone process
            var repo = GitInstaller.Clone(repoPath, branchName, finalExtRepoPath, username, password);

            // Check installation
            if (repo != null)
            {
                // make sure to delete the repo if error occured after cloning
                var clonedPath = repo.Info.WorkingDirectory;
                if (GitInstaller.IsValidRepo(clonedPath))
                {
                    logger.Debug("Clone successful \"{0}\"", clonedPath);
                    RegisterExtensionSearchPath(destPath.NormalizeAsPath());
                }
                else
                {
                    logger.Debug("Invalid repo after cloning. Deleting clone \"{0}\"", repoPath);
                    try {
                        CommonUtils.DeleteDirectory(repoPath);
                    }
                    catch (Exception delEx) {
                        logger.Error(string.Format("Error post-install cleanup on \"{0}\" | {1}",
                                                   repoPath, delEx.Message));
                    }
                }
            }
            else
            {
                throw new PyRevitException(string.Format("Error installing extension. Null repo error on \"{0}\"",
                                                         repoPath));
            }
        }
Exemplo n.º 9
0
 public static string MakeConfigName(string extName, PyRevitExtensionTypes extType)
 {
     return(extType ==
            PyRevitExtensionTypes.UIExtension ?
            extName + PyRevitConsts.ExtensionUIPostfix : extName + PyRevitConsts.ExtensionLibraryPostfix);
 }
Exemplo n.º 10
0
 public static string GetExtensionDirExt(PyRevitExtensionTypes extType)
 {
     return(extType == PyRevitExtensionTypes.UIExtension ? ExtensionUIPostfix : ExtensionLibraryPostfix);
 }