Skip to content

Commit

Permalink
-Added Basic Login/Logout (Actually just sets the path for those who …
Browse files Browse the repository at this point in the history
…had it unset)

-Added initial support for SHELVE/UNSHELVE Currently only for entire CLs
  • Loading branch information
AndrewButt committed Mar 23, 2012
1 parent 05ee145 commit 3c01395
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 2 deletions.
22 changes: 22 additions & 0 deletions Context.sublime-menu
Expand Up @@ -9,6 +9,10 @@
"id": "perforce",
"children":
[
{
"command": "perforce_login",
"caption": "Login"
},
{
"command": "perforce_add",
"caption": "Add"
Expand Down Expand Up @@ -66,6 +70,24 @@
{
"command": "perforce_submit",
"caption": "Submit"
},
{
"caption": "Shelve",
"children":
[
{
"command": "perforce_shelve_cl",
"caption": "Shelve Changelist"
},
{
"command": "perforce_unshelve_cl",
"caption": "Unshelve Changelist"
}
]
},
{
"command": "perforce_logout",
"caption": "Logout"
}
]
},
Expand Down
16 changes: 16 additions & 0 deletions Default.sublime-commands
@@ -1,4 +1,8 @@
[
{
"caption": "Perforce: Login",
"command": "perforce_login"
},
{
"caption": "Perforce: Checkout",
"command": "perforce_checkout"
Expand Down Expand Up @@ -50,5 +54,17 @@
{
"caption": "Perforce: Submit",
"command": "perforce_submit"
},
{
"caption": "Perforce: Logout",
"command": "perforce_logout"
},
{
"caption": "Perforce: Shelve Changelist",
"command": "perforce_shelve_cl"
},
{
"caption": "Perforce: Unshelve Changelist",
"command": "perforce_unshelve_cl"
}
]
22 changes: 22 additions & 0 deletions Main.sublime-menu
Expand Up @@ -11,6 +11,10 @@
"id": "perforce",
"children":
[
{
"command": "perforce_login",
"caption": "Login"
},
{
"command": "perforce_add",
"caption": "Add"
Expand Down Expand Up @@ -68,6 +72,24 @@
{
"command": "perforce_submit",
"caption": "Submit"
},
{
"caption": "Shelve",
"children":
[
{
"command": "perforce_shelve_cl",
"caption": "Shelve Changelist"
},
{
"command": "perforce_unshelve_cl",
"caption": "Unhelve Changelist"
}
]
},
{
"command": "perforce_logout",
"caption": "Logout"
}
]
}
Expand Down
109 changes: 107 additions & 2 deletions Perforce.py
Expand Up @@ -28,7 +28,11 @@
import tempfile
import threading
import json

import sys
try:
from Queue import Queue, Empty
except ImportError:
from queue import Queue, Empty # python 3.x
# Plugin Settings are located in 'perforce.sublime-settings' make a copy in the User folder to keep changes

# global variable used when calling p4 - it stores the path of the file in the current view, used to determine with P4CONFIG to use
Expand Down Expand Up @@ -898,4 +902,105 @@ def on_description_cancel(self):

class PerforceSubmitCommand(sublime_plugin.WindowCommand):
def run(self):
SubmitThread(self.window).start()
SubmitThread(self.window).start()



class PerforceLogoutCommand(sublime_plugin.WindowCommand):
def run(self):
try:
command = ConstructCommand("p4 set P4PASSWD=")
p = subprocess.Popen(command, stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=global_folder, shell=True)
p.communicate()
except ValueError:
pass

class PerforceLoginCommand(sublime_plugin.WindowCommand):
def run(self):
self.window.show_input_panel("Enter Perforce Password", "", self.on_done, None, None)

def on_done(self, password):
try:
command = ConstructCommand("p4 logout")
p = subprocess.Popen(command, stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=global_folder, shell=True)
p.communicate()
#unset var
command = ConstructCommand("p4 set P4PASSWD=" + password)
p = subprocess.Popen(command, stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=global_folder, shell=True)
p.communicate()
except ValueError:
pass

class PerforceUnshelveClCommand(sublime_plugin.WindowCommand):
def run(self):
try:
ShelveClCommand(self.window, False).start()
except:
WarnUser("Unknown Error, does the included P4 Version support Shelve?")
return -1
class PerforceShelveClCommand(sublime_plugin.WindowCommand):
def run(self):
try:
ShelveClCommand(self.window, True).start()
except:
WarnUser("Unknown Error, does the included P4 Version support Shelve?")
return -1

class ShelveClCommand(threading.Thread):
def __init__(self, window, shelve=True):
self.shelve = shelve
self.window = window
threading.Thread.__init__(self)

def run(self):
self.changelists_list = self.MakeChangelistsList()
def show_quick_panel():
if not self.changelists_list:
sublime.error_message(__name__ + ': There are no changelists to list.')
return
self.window.show_quick_panel(self.changelists_list, self.on_done)

sublime.set_timeout(show_quick_panel, 10)

def on_done(self, picked):
if picked == -1:
return
changelistlist = self.changelists_list[picked].split(' ')


changelist = 'Default'
if(len(changelistlist) > 1): # Numbered changelist
changelist = changelistlist[1]
else:
changelist = changelistlist[0]

print changelist


if self.shelve:
cmdString = "shelve -c" + changelist
else:
cmdString = "unshelve -s" + changelist + " -f"
command = ConstructCommand("p4 " + cmdString)
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=global_folder, shell=True)
result, err = p.communicate()
print result
if(err):
WarnUser("usererr " + err.strip())
return -1

def MakeChangelistsList(self):
success, rawchangelists = GetPendingChangelists();

resultchangelists = []

if(success):
changelists = rawchangelists.splitlines()

# for each line, extract the change
for changelistline in changelists:
changelistlinesplit = changelistline.split(' ')

resultchangelists.insert(0, "Changelist " + changelistlinesplit[1] + " - " + ' '.join(changelistlinesplit[7:]))

return resultchangelists

0 comments on commit 3c01395

Please sign in to comment.