def setCurrentWorkspace(self, *args): workspacePath = QtWidgets.QFileDialog.getExistingDirectory( interop.main_parent_window(), "Select existing workspace") for client in self.p4.run_clients(): if workspacePath.replace("\\", "/") == client['Root'].replace("\\", "/"): root, client = os.path.split(str(workspacePath)) self.p4.client = client Utils.p4Logger().info( "Setting current client to {0}".format(client)) # REALLY make sure we save the P4CLIENT variable if platform.system() == "Linux" or platform.system( ) == "Darwin": os.environ['P4CLIENT'] = self.p4.client Utils.saveEnvironmentVariable("P4CLIENT", self.p4.client) else: self.p4.set_env('P4CLIENT', self.p4.client) Utils.writeToP4Config(self.p4.p4config_file, "P4CLIENT", self.p4.client) break else: QtWidgets.QMessageBox.warning( interop.main_parent_window(), "Perforce Error", "{0} is not a workspace root".format(workspacePath))
def createWorkspace(self, *args): workspaceRoot = None # @ToDo remove this, it's badly written right now. # Safer to use P4V for the initial setup to rewrite this to be more reliable # Give the artist 3 chances to choose a folder (assuming they choose a bad path) tries = 3 i = 0 while i < tries: workspaceRoot = QtWidgets.QFileDialog.getExistingDirectory( interop.main_parent_window(), "Specify workspace root folder") i += 1 if workspaceRoot: break else: raise IOError("Can't set workspace") try: workspaceSuffixDialog = QtWidgets.QInputDialog workspaceSuffix = workspaceSuffixDialog.getText( interop.main_parent_window(), "Workspace", "Optional Name Suffix (e.g. Uni, Home):") Utils.createWorkspace(self.p4, workspaceRoot, str(workspaceSuffix[0])) Utils.writeToP4Config(self.p4.p4config_file, "P4CLIENT", self.p4.client) except P4Exception as e: displayErrorUI(e)
def firstTimeLogin(p4, enterUsername=True, enterPassword=True, parent=None, *args): username = None password = None if enterUsername: username, ok = QtWidgets.QInputDialog(None, QtCore.Qt.WindowStaysOnTopHint).getText( parent, "Enter username", "Username:"******"Invalid username") p4.user = str(username) if True or enterPassword: password, ok = QtWidgets.QInputDialog(None, QtCore.Qt.WindowStaysOnTopHint).getText( parent, "Enter password", "Password:"******"Invalid password") p4.password = str(password) # Validate SSH Login / Attempt to login try: Utils.p4Logger().info(p4.run_login("-a")) except P4Exception as e: regexKey = re.compile(ur'(?:[0-9a-fA-F]:?){40}') # regexIP = re.compile(ur'[0-9]+(?:\.[0-9]+){3}?:[0-9]{4}') errorMsg = str(e).replace('\\n', ' ') key = re.findall(regexKey, errorMsg) # ip = re.findall(regexIP, errorMsg) if key: Utils.p4Logger().info(p4.run_trust("-i", key[0])) Utils.p4Logger().info(p4.run_login("-a")) else: raise e if username: Utils.writeToP4Config(p4.p4config_file, "P4USER", str(username[0]))