Permalink
Browse files

vlt add files

  • Loading branch information...
1 parent 07e49b0 commit 77810934129c18b4e377cd4aea56c2dadc894bb3 Tomek Wytrębowicz committed Jun 29, 2012
Showing with 72 additions and 10 deletions.
  1. +4 −0 Default.sublime-commands
  2. +66 −0 vlt.py
  3. BIN vlt.pyc
  4. +2 −10 vlt.sublime-settings
View
@@ -14,5 +14,9 @@
{
"caption": "vlt: Commit",
"command": "vlt_commit"
+ },
+ {
+ "caption": "vlt: Add",
+ "command": "vlt_add"
}
]
View
66 vlt.py
@@ -1,4 +1,5 @@
# Written by Tomek Wytrebowicz (tomalecpub@gmail.com)
+# TODO: vlt add directories (-N non recursive)
import sublime, sublime_plugin
import os
@@ -46,7 +47,26 @@ def Commit(in_folder, in_filename):
return VltCommandOnFile("commit", in_folder, in_filename);
class VltAutoCommit(sublime_plugin.EventListener):
+ preSaveIsFileInRepo = 0
+ def on_pre_save(self, view):
+ perforce_settings = sublime.load_settings('vlt.sublime-settings')
+
+ self.preSaveIsFileInRepo = 0
+
+ # check if this part of the plugin is enabled
+ if(not perforce_settings.get('vlt_auto_add')):
+ WarnUser("Auto Add disabled")
+ return
+
+ folder_name, filename = os.path.split(view.file_name())
+ self.preSaveIsFileInRepo = IsFileInRepo(folder_name, filename)
+
def on_post_save(self, view):
+ if(self.preSaveIsFileInRepo == -1):
+ folder_name, filename = os.path.split(view.file_name())
+ success, message = Add(folder_name, filename)
+ LogResults(success, message)
+ else:
folder_name, filename = os.path.split(view.file_name())
success, message = Commit(folder_name, filename)
LogResults(success, message)
@@ -59,3 +79,49 @@ def run(self, edit):
LogResults(success, message)
else:
WarnUser("View does not contain a file")
+
+# Add section
+def Add(in_folder, in_filename):
+ # Add the file
+ success, message = VltCommandOnFile("add", in_folder, in_filename);
+ if(not success or message[0,2]!="A "):
+ return 0, message
+ return VltCommandOnFile("ci", in_folder, in_filename);
+
+class VltAddCommand(sublime_plugin.TextCommand):
+ def run(self, edit):
+ if(self.view.file_name()):
+ folder_name, filename = os.path.split(self.view.file_name())
+ success, message = Add(folder_name, filename)
+ LogResults(success, message)
+ else:
+ WarnUser("View does not contain a file")
+
+def IsFileInRepo(in_folder, in_filename):
+ success, message = VltCommandOnFile("info", in_folder, in_filename);
+ if(not success):
+ return 0, message
+ # locate the line containing "Status: " and extract the following status
+ startindex = result.find("Status: ")
+ if(startindex == -1):
+ WarnUser("Unexpected output from 'vlt info'.")
+ return -1
+
+ startindex += 8 # advance after "Status: "
+
+ endindex = result.find("\n", startindex)
+ if(endindex == -1):
+ WarnUser("Unexpected output from 'vlt info'.")
+ return -1
+
+ status = result[startindex:endindex].strip();
+ if(os.path.isfile(os.path.join(in_folder, in_filename))): # file exists on disk, not being added
+ if(status != "unknown"):
+ return 1
+ else:
+ return 0
+ else:
+ if(status != "unknown"):
+ return -1 # will be in the depot, it's being added
+ else:
+ return 0
View
BIN vlt.pyc
Binary file not shown.
View
@@ -1,13 +1,5 @@
{
- "vlt_auto_commit": true, // when true, checkout will occur depending on the modify/save settings
- "vlt_auto_checkout": true, // when true, checkout will occur depending on the modify/save settings
- "vlt_auto_checkout_on_save": true,
- "vlt_auto_checkout_on_modified": false,
- "vlt_auto_add": true, // when true, any file within the client spec that doesn't exist during the presave will be added
+ "vlt_auto_commit": true, // when true, commit will occur
+ "vlt_auto_add": true, // when true, add will occur
"vlt_warnings_enabled": true, // will output messages when warnings happen
- "vlt_end_line_separator": "\n", // used to reconstruct the depot file after breaking it up to remove the first line
- "vlt_log_warnings_to_status": true, // used to redirect logs to the status bar instead. The standard output is too big for the line (can be multi-line with the raw output of p4)
-
- // use %depofile_path / %file_path as place holder for the full qulified path and %depofile_name / %file_name for the file name only
- //"vlt_graphical_diff_command": "p4diff \"%depofile_path\" \"%file_path\" -l \"%file_name in depot\" -e -1 4"
}

0 comments on commit 7781093

Please sign in to comment.