浏览代码

Change handeling of paths for macos

/pyrception-integration
Leopoldo Zugasti 4 年前
当前提交
8dac7b54
共有 1 个文件被更改,包括 90 次插入22 次删除
  1. 112
      com.unity.perception/Editor/Pyrception/PyrceptionInstaller.cs

112
com.unity.perception/Editor/Pyrception/PyrceptionInstaller.cs


UnityEngine.Debug.Log("Current Process was set to null");
}*/
string path = Application.dataPath.Replace("/Assets", "");
string path = Path.GetFullPath(Application.dataPath.Replace("/Assets", ""));
string packagesPath = Application.dataPath.Replace("/Assets","/Library/PythonInstall/Scripts");
string packagesPath = Path.GetFullPath(Application.dataPath.Replace("/Assets","/Library/PythonInstall/Scripts"));
#elif (UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX)
string packagesPath = Application.dataPath.Replace("/Assets","/Library/PythonInstall/bin");
#endif

packagesPath = packagesPath.Replace("/", "\\");
pathToData = pathToData.Replace("/", "\\");
#elif (UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX)
path = path.Replace(" ", "\\ ");
pathToData = pathToData.Replace(" ", "\\ ");
//path = path.Replace(" ", "\\ ");
//packagesPath = packagesPath.Replace(" ", "\\ ");
//pathToData = pathToData.Replace(" ", "\\ ");
#endif
string command = "";

#elif (UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX)
//command = $"cd \"{path}/DataInsightsEnv/bin\";source activate;cd \"{pathToData}/..\";\"{path}/DataInsightsEnv/bin/pyrception-utils\" preview --data=\".\"";
command = $"cd {pathToData}/.. ; {packagesPath}/pyrception-utils preview --data=\".\"";
command = $"cd \'{packagesPath}\' ;./pyrception-utils preview --data=\'{pathToData}\'";
ExecuteCMD(command, ref ExitCode, waitForExit: false, displayWindow: true);
ExecuteCMD(command, ref ExitCode, waitForExit: true, displayWindow: true);
if (ExitCode != 0)
return;
else

}*/
//==============================SETUP PATHS======================================
string path = Application.dataPath.Replace("/Assets", "");
string packagesPath = Application.dataPath.Replace("/Assets","/Library/PythonInstall/Scripts");
string packagesPath = Path.GetFullPath(Application.dataPath.Replace("/Assets","/Library/PythonInstall/Scripts"));
string packagesPath = Application.dataPath.Replace("/Assets","/Library/PythonInstall/bin");
string packagesPath = Path.GetFullPath(Application.dataPath.Replace("/Assets","/Library/PythonInstall/bin"));
path = path.Replace("/", "\\");
path = path.Replace(" ", "\\ ");
pyrceptionPath = pyrceptionPath.Replace(" ", "\\ ");
packagesPath = packagesPath.Replace(" ", "\\ ");
//pyrceptionPath = pyrceptionPath.Replace(" ", "\\ ");
//packagesPath = packagesPath.Replace(" ", "\\ ");
#endif

#elif (UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX)
//ExecuteCMD($"pip3 install --target=\"{path}/virtualenvDI\" virtualenv", ref ExitCode); //(maybe add --no-user)
#endif
if (ExitCode != 0) {
/*if (ExitCode != 0) {
}
}*/
//==============================CREATE VIRTUALENV NAMED DataInsightsEnv======================================
//EditorUtility.DisplayProgressBar("Setting up Pyrception", "Setting up virtualenv instance...", 1f / steps);

string virtualenvPath = path+"/virtualenvDI/bin/";
//string virtualenvPath = path+"/virtualenvDI/bin/";
if (ExitCode != 0) {
/*if (ExitCode != 0) {
}
}*/
//==============================COPY ALL PYRCEPTION FILES FOR INSTALLATION======================================
EditorUtility.DisplayProgressBar("Setting up Pyrception", "Getting pyrception files...", 1.5f / steps);

ExecuteCMD($"XCOPY /E/I/Y \"{pyrceptionPath}\" \"{packagesPath}\\..\\pyrception-util\"", ref ExitCode);
//ExecuteCMD($"XCOPY /E/I/Y \"{pyrceptionPath}\" \"{packagesPath}\\..\\pyrception-util\"", ref ExitCode);
ExecuteCMD($"\\cp -r \"{pyrceptionPath}\" \"{packagesPath}/../pyrception-util\"", ref ExitCode);
ExecuteCMD($"\\cp -r \'{pyrceptionPath}\' \'{packagesPath}/../pyrception-util\'", ref ExitCode);
#endif
if (ExitCode != 0) {
EditorUtility.ClearProgressBar();

EditorUtility.DisplayProgressBar("Setting up Pyrception", "Installing pyrception utils...", 2.5f / steps);
/*UnityEngine.Debug.Log(pyrceptionPath);
UnityEngine.Debug.Log(packagesPath);
DirectoryCopy(pyrceptionPath, packagesPath);*/
EditorUtility.DisplayProgressBar("Setting up Pyrception", "Installing pyrception utils...", 2.5f / steps);
//==============================INSTALL PYRCEPTION IN THE VIRTUALENV======================================
#if UNITY_EDITOR_WIN
//ExecuteCMD($"\"{path}\\DataInsightsEnv\\Scripts\\activate\" && cd \"{path}\\DataInsightsEnv\\pyrception-util\" && \"{packagesPath}\"\\pip3 --no-cache-dir install -e . && deactivate", ref ExitCode);

//ExecuteCMD($"source \"{path}/DataInsightsEnv/bin/activate\"; cd \"{path}/DataInsightsEnv/pyrception-util\"; pip3 --no-cache-dir install -e .; deactivate", ref ExitCode);
ExecuteCMD($"cd \"{packagesPath}/../pyrception-util\"; \"{packagesPath}\"/pip3 --no-cache-dir install -e .", ref ExitCode);
ExecuteCMD($"cd \'{packagesPath}\'; ./pip3 install -e \'../pyrception-util/.\'", ref ExitCode);
#endif
if (ExitCode != 0) {
EditorUtility.ClearProgressBar();

string shell = "";
string argument = "";
string output = "";
UnityEngine.Debug.Log(command);
#if UNITY_EDITOR_WIN
shell = "cmd.exe";

cmd.Close();
return output;
}
private static void DirectoryCopy(string sourceDirName, string destDirName, bool first = true)
{
bool copySubDirs = true;
// Get the subdirectories for the specified directory.
DirectoryInfo dir = new DirectoryInfo(sourceDirName);
if (!dir.Exists)
{
throw new DirectoryNotFoundException(
"Source directory does not exist or could not be found: "
+ sourceDirName);
}
DirectoryInfo[] dirs = dir.GetDirectories();
// If the destination directory doesn't exist, create it.
DirectoryInfo dirDest = new DirectoryInfo(destDirName);
if (dirDest.Exists && first)
{
DeleteDirectory(destDirName);
}
Directory.CreateDirectory(destDirName);
// Get the files in the directory and copy them to the new location.
FileInfo[] files = dir.GetFiles();
foreach (FileInfo file in files)
{
string tempPath = Path.Combine(destDirName, file.Name);
file.CopyTo(tempPath, false);
UnityEngine.Debug.Log("Copying " + file.Name + " to " + tempPath);
}
// If copying subdirectories, copy them and their contents to new location.
if (copySubDirs)
{
foreach (DirectoryInfo subdir in dirs)
{
string tempPath = Path.Combine(destDirName, subdir.Name);
DirectoryCopy(subdir.FullName, tempPath, false);
}
}
}
private static void DeleteDirectory(string target_dir)
{
string[] files = Directory.GetFiles(target_dir);
string[] dirs = Directory.GetDirectories(target_dir);
foreach (string file in files)
{
File.SetAttributes(file, FileAttributes.Normal);
File.Delete(file);
}
foreach (string dir in dirs)
{
DeleteDirectory(dir);
}
Directory.Delete(target_dir, false);
}
}
正在加载...
取消
保存