Skip to content

Commit

Permalink
fixed issue #1030 [cli] [installer]
Browse files Browse the repository at this point in the history
  • Loading branch information
eirannejad committed Oct 19, 2020
1 parent 47e6906 commit f58dde3
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 32 deletions.
8 changes: 6 additions & 2 deletions dev/pyRevitLabs/pyRevitCLI/PyRevitCLI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ private static void ProcessArguments() {
else if (all("update"))
PyRevitCLICloneCmds.UpdateClone(
allClones: arguments["--all"].IsTrue,
cloneName: TryGetValue("<clone_name>")
cloneName: TryGetValue("<clone_name>"),
username: TryGetValue("--username"),
password: TryGetValue("--password")
);

else
Expand Down Expand Up @@ -432,7 +434,9 @@ private static void ProcessArguments() {
else if (all("update"))
PyRevitCLIExtensionCmds.UpdateExtension(
all: arguments["--all"].IsTrue,
extName: TryGetValue("<extension_name>")
extName: TryGetValue("<extension_name>"),
username: TryGetValue("--username"),
password: TryGetValue("--password")
);

else if (IsHelpMode)
Expand Down
4 changes: 2 additions & 2 deletions dev/pyRevitLabs/pyRevitCLI/PyRevitCLICloneCmds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ internal static void
}

internal static void
UpdateClone(bool allClones, string cloneName) {
UpdateClone(bool allClones, string cloneName, string username, string password) {
// TODO: ask for closing running Revits

// prepare a list of clones to be updated
Expand Down Expand Up @@ -260,7 +260,7 @@ internal static void
// update clones that do not include this process
foreach (var clone in targetClones) {
logger.Debug("Updating clone \"{0}\"", clone.Name);
PyRevitClones.Update(clone);
PyRevitClones.Update(clone, username, password);
}

// now update myClone if any, as last step
Expand Down
6 changes: 3 additions & 3 deletions dev/pyRevitLabs/pyRevitCLI/PyRevitCLIExtensionCmds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,11 @@ internal static void
}

internal static void
UpdateExtension(bool all, string extName) {
UpdateExtension(bool all, string extName, string username, string password) {
if (all)
PyRevitExtensions.UpdateAllInstalledExtensions();
PyRevitExtensions.UpdateAllInstalledExtensions(username, password);
else if (extName != null)
PyRevitExtensions.UpdateExtension(extName);
PyRevitExtensions.UpdateExtension(extName, username, password);
}
}
}
4 changes: 2 additions & 2 deletions dev/pyRevitLabs/pyRevitCLI/Resources/UsagePatterns.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Usage:
pyrevit clones commit <clone_name> [<commit_hash>] [--log=<log_file>]
pyrevit clones origin <clone_name> --reset [--log=<log_file>]
pyrevit clones origin <clone_name> [<origin_url>] [--log=<log_file>]
pyrevit clones update (--all | <clone_name>) [--log=<log_file>]
pyrevit clones update (--all | <clone_name>) [--log=<log_file>] [--username=<username>] [--password=<password>]
pyrevit clones deployments <clone_name>
pyrevit clones engines <clone_name>
pyrevit attach --help
Expand Down Expand Up @@ -49,7 +49,7 @@ Usage:
pyrevit extensions sources [--help]
pyrevit extensions sources forget --all [--log=<log_file>]
pyrevit extensions sources (add | forget) <source_json_or_url> [--log=<log_file>]
pyrevit extensions update (--all | <extension_name>) [--log=<log_file>]
pyrevit extensions update (--all | <extension_name>) [--log=<log_file>] [--username=<username>] [--password=<password>]
pyrevit releases --help
pyrevit releases [--pre] [--notes]
pyrevit releases latest [--pre] [--notes]
Expand Down
21 changes: 15 additions & 6 deletions dev/pyRevitLabs/pyRevitLabs.Common/GitInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Web.UI.WebControls.Adapters;
using LibGit2Sharp;
using pyRevitLabs.NLog;

Expand Down Expand Up @@ -106,12 +106,19 @@ public static void CheckoutBranch(string repoPath, string branchName) {

// rebase current branch and pull from master
// @handled @logs
public static UpdateStatus ForcedUpdate(string repoPath) {
public static UpdateStatus ForcedUpdate(string repoPath, string username, string password) {
logger.Debug("Force updating repo \"{0}\"...", repoPath);
try {
var repo = new Repository(repoPath);
var options = new PullOptions();
options.FetchOptions = new FetchOptions();
var fetchOpts = new FetchOptions();

// add username and password to clone options, if provided by user
if (username != null && password != null)
fetchOpts.CredentialsProvider =
(_url, _usernameFromUrl, _credTypes) => new UsernamePasswordCredentials { Username = username, Password = password };

options.FetchOptions = fetchOpts;

// before updating, let's first
// forced checkout to overwrite possible local changes
Expand Down Expand Up @@ -233,10 +240,12 @@ public static string GetCheckedoutBranch(string repoPath) {
// get the checkedout branch from repopath
// @handled @logs
public static string GetHeadCommit(string repoPath) {
string head = null;
if (IsValidRepo(repoPath))
return new Repository(repoPath).Head.Tip.Id.ToString();
logger.Debug("Can not determine head commit hash for \"{0}\"", repoPath);
return null;
head = new Repository(repoPath).Head?.Tip?.Id.ToString();
if (head is null)
logger.Debug("Can not determine head commit hash for \"{0}\"", repoPath);
return head;
}

// get the checkedout branch from repopath
Expand Down
9 changes: 7 additions & 2 deletions dev/pyRevitLabs/pyRevitLabs.PyRevit/PyRevitClone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public struct PyRevitCloneFromImageArgs {
public string Url;
public string BranchName;
public string DeploymentName;

public override string ToString() {
return string.Format("Url: \"{0}\" | Branch: \"{1}\" | Deployment: \"{2}\"", Url, BranchName, DeploymentName);
}
}

public class PyRevitClone {
Expand Down Expand Up @@ -111,7 +115,7 @@ public string Branch {

public string Commit => GetCommit(ClonePath);

public string ShortCommit => Commit.GetHashShort();
public string ShortCommit => Commit?.GetHashShort();

public string Origin => GetOrigin(ClonePath);

Expand Down Expand Up @@ -459,7 +463,8 @@ private static PyRevitCloneFromImageArgs ReadDeploymentArgs(string clonePath) {
BranchName = contents[1] == string.Empty ? PyRevitLabsConsts.TragetBranch : contents[1],
DeploymentName = contents[2] == string.Empty ? null : contents[2]
};

logger.Debug(args);

return args;
}
catch (Exception ex) {
Expand Down
18 changes: 10 additions & 8 deletions dev/pyRevitLabs/pyRevitLabs.PyRevit/PyRevitClones.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public static void DeployFromImage(string cloneName,

// record image deployment settings
try {
RecordDeploymentArgs(cloneName, deploymentName, branchName, imagePath, destPath);
RecordDeploymentArgs(cloneName, deploymentName, branchName, imageSource, destPath);
}
catch (Exception ex) {
logger.Debug(string.Format("Exception occured after clone from image complete. " +
Expand Down Expand Up @@ -484,14 +484,16 @@ private static void RecordDeploymentArgs(string cloneName,
}
}

private static void ReDeployClone(PyRevitClone clone) {
private static void ReDeployClone(PyRevitClone clone, string username = null, string password = null) {
// grab clone arguments from inside of clone
var cloneName = clone.Name;
var clonePath = clone.ClonePath;
var cloneDeployArgs = clone.DeploymentArgs;
logger.Debug("Clone Name=\"{0}\", Path=\"{1}\" Args=> {2}", cloneName, clonePath, cloneDeployArgs);

// delete existing clone
Delete(clone);

// re-deploy
DeployFromImage(
cloneName: cloneName,
Expand Down Expand Up @@ -527,26 +529,26 @@ public static void DeleteAllClones(bool clearConfigs = false) {

// force update given or all registered clones
// @handled @logs
public static void Update(PyRevitClone clone) {
public static void Update(PyRevitClone clone, string username = null, string password = null) {
// current user config
logger.Debug("Updating pyRevit clone \"{0}\"", clone.Name);
if (clone.IsRepoDeploy) {
var res = GitInstaller.ForcedUpdate(clone.ClonePath);
var res = GitInstaller.ForcedUpdate(clone.ClonePath, username, password);
if (res <= UpdateStatus.Conflicts)
throw new PyRevitException(string.Format("Error updating clone \"{0}\"", clone.Name));
}
else {
// re-deploying is how the no-git clones get updated
ReDeployClone(clone);
ReDeployClone(clone, username, password);
}
}

// force update given or all registered clones
// @handled @logs
public static void UpdateAllClones() {
public static void UpdateAllClones(string username = null, string password = null) {
logger.Debug("Updating all pyRevit clones");
foreach (var clone in GetRegisteredClones())
Update(clone);
Update(clone, username, password);
}

// updates the config value for registered clones
Expand Down
12 changes: 6 additions & 6 deletions dev/pyRevitLabs/pyRevitLabs.PyRevit/PyRevitExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,28 +252,28 @@ public static void UninstallExtension(string extensionName, bool removeSearchPat

// force update extension
// @handled @logs
public static void UpdateExtension(PyRevitExtension ext) {
public static void UpdateExtension(PyRevitExtension ext, string username = null, string password = null) {
logger.Debug("Updating extension \"{0}\"", ext.Name);
logger.Debug("Updating extension repo at \"{0}\"", ext.InstallPath);
var res = GitInstaller.ForcedUpdate(ext.InstallPath);
var res = GitInstaller.ForcedUpdate(ext.InstallPath, username, password);
if (res <= UpdateStatus.Conflicts)
throw new PyRevitException(
string.Format("Error updating extension \"{0}\" installed at \"{1}\"", ext.Name, ext.InstallPath)
);
}

public static void UpdateExtension(string extName) {
public static void UpdateExtension(string extName, string username = null, string password = null) {
var ext = GetInstalledExtension(extName);
UpdateExtension(ext);
UpdateExtension(ext, username, password);
}

// force update all extensions
// @handled @logs
public static void UpdateAllInstalledExtensions() {
public static void UpdateAllInstalledExtensions(string username = null, string password = null) {
logger.Debug("Updating all installed extensions.");
// update all installed extensions
foreach (var ext in GetInstalledExtensions())
UpdateExtension(ext);
UpdateExtension(ext, username, password);
}

// enable extension in config
Expand Down
2 changes: 1 addition & 1 deletion release/.pyrevitargs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

https://github.com/eirannejad/pyRevit/archive/master.zip
master
basepublic

0 comments on commit f58dde3

Please sign in to comment.