Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Minor formatting

  • Loading branch information...
commit 3640d45b847b451cbde5502b47cb402eb58847d5 2 parents 2493c03 + e746a11
Vishal Rana authored
Showing with 4 additions and 2 deletions.
  1. +2 −0  .c9revisions/history.py.c9save
  2. +2 −2 history.py
View
2  .c9revisions/history.py.c9save
@@ -0,0 +1,2 @@
+{"ts":1352489223060,"silentsave":true,"restoring":false,"patch":[[{"diffs":[[1,"import sublime\nimport sublime_plugin\nimport os\nimport glob\nimport platform\nfrom datetime import datetime as dt\nimport difflib\nimport filecmp\nimport shutil\nfrom threading import Thread\n\n#--------------#\n# Settings #\n#--------------#\nsettings = sublime.load_settings(\"LocalHistory.sublime-settings\")\nhistory_location = settings.get(\"history_location\", \"~\")\nif history_location == \"~\":\n history_location = os.path.expanduser(\"~\")\nHISTORY_PATH = os.path.join(os.path.abspath(history_location), \".sublime\", \"history\")\nHISTORY_LIMIT = settings.get(\"history_limit\", 50)\nFILE_SIZE_LIMIT = settings.get(\"file_size_limit\", 262144)\n\n\ndef show_diff(window, diff):\n panel = window.new_file()\n panel.set_scratch(True)\n panel.set_syntax_file(\"Packages/Diff/Diff.tmLanguage\")\n panel_edit = panel.begin_edit()\n panel.insert(panel_edit, 0, diff)\n panel.end_edit(panel_edit)\n\n\ndef get_filedir(file_path):\n file_dir = os.path.dirname(file_path)\n if platform.system() == \"Windows\":\n if file_dir.find(\"\\\\\") == 0:\n file_dir = file_dir[2:] # Strip the network \\\\ starting path\n if file_dir.find(\":\") == 1:\n file_dir = file_dir.replace(\":\", \"\", 1)\n else:\n file_dir = file_dir[file_dir.find(os.sep) + 1:] # Trim the root\n return os.path.join(HISTORY_PATH, file_dir)\n\n\nclass HistorySave(sublime_plugin.EventListener):\n\n def on_post_save(self, view):\n\n def run(file_path):\n # Return if file exceeds the size limit\n if os.path.getsize(file_path) > FILE_SIZE_LIMIT:\n print \"WARNING: Local History did not save a copy of this file because it has exceeded {0}KB limit.\".format(FILE_SIZE_LIMIT / 1024)\n return\n\n # Get history directory\n file_name = os.path.basename(file_path)\n history_dir = get_filedir(file_path)\n if not os.path.exists(history_dir):\n # Create directory structure\n os.makedirs(history_dir)\n\n # Get history files\n os.chdir(history_dir)\n history_files = glob.glob(\"*\" + file_name)\n history_files.sort(key=lambda f: os.path.getmtime(f), reverse=True)\n\n # Skip if no changes\n if history_files:\n if filecmp.cmp(file_path, os.path.join(history_dir, history_files[0])):\n return\n\n # Store history\n shutil.copyfile(file_path, os.path.join(history_dir, \"{0}.{1}\".format(dt.now().strftime(\"%b.%d.%Y_%H.%M.%S\"), file_name)))\n\n # Remove old files\n for file in history_files[HISTORY_LIMIT - 1:]: # -1 as we just added a new file\n os.remove(file)\n\n # Process in a thread\n t = Thread(target=run, args=(view.file_name(),))\n t.start()\n\n\nclass HistoryOpen(sublime_plugin.TextCommand):\n\n def run(self, edit):\n # Get history directory\n file_name = os.path.basename(self.view.file_name())\n history_dir = get_filedir(self.view.file_name())\n\n # Get history files\n os.chdir(history_dir)\n history_files = glob.glob(\"*\" + file_name)\n history_files.sort(key=lambda f: os.path.getmtime(f), reverse=True)\n if not history_files:\n sublime.status_message(\"No Local History Found\")\n return\n\n def on_done(index):\n # Escape\n if index == -1:\n return\n\n # Open\n self.view.window().open_file(os.path.join(history_dir, history_files[index]))\n\n self.view.window().show_quick_panel(history_files, on_done)\n\n\nclass HistoryCompare(sublime_plugin.TextCommand):\n\n def run(self, edit):\n # Get history directory\n file_name = os.path.basename(self.view.file_name())\n history_dir = get_filedir(self.view.file_name())\n\n # Get history files\n os.chdir(history_dir)\n history_files = glob.glob(\"*\" + file_name)\n history_files.sort(key=lambda f: os.path.getmtime(f), reverse=True)\n # Skip the first one as its always identical\n history_files = history_files[1:]\n\n if not history_files:\n sublime.status_message(\"No Local History Found\")\n return\n\n def on_done(index):\n # Escape\n if index == -1:\n return\n\n # Trigger save before comparing, if required!\n if self.view.is_dirty():\n self.view.run_command(\"save\")\n\n # From\n from_file = history_files[index]\n with open(from_file, \"r\") as f:\n from_content = f.readlines()\n\n # To\n to_file = self.view.file_name()\n with open(to_file, \"r\") as f:\n to_content = f.readlines()\n\n # Compare and show diff\n diff = difflib.unified_diff(from_content, to_content, from_file, to_file)\n diff = [d.decode(\"utf8\") for d in diff]\n show_diff(self.view.window(), \"\".join(diff))\n\n self.view.window().show_quick_panel(history_files, on_done)\n\n\nclass HistoryReplace(sublime_plugin.TextCommand):\n\n def run(self, edit):\n # Get history directory\n file_name = os.path.basename(self.view.file_name())\n history_dir = get_filedir(self.view.file_name())\n\n # Get history files\n os.chdir(history_dir)\n history_files = glob.glob(\"*\" + file_name)\n history_files.sort(key=lambda f: os.path.getmtime(f), reverse=True)\n # Skip the first one as its always identical\n history_files = history_files[1:]\n\n if not history_files:\n sublime.status_message(\"No Local History Found\")\n return\n\n def on_done(index):\n # Escape\n if index == -1:\n return\n\n # Replace\n file = history_files[index]\n with open(file) as f:\n self.view.replace(edit, sublime.Region(0, self.view.size()), f.read())\n self.view.run_command(\"save\")\n\n self.view.window().show_quick_panel(history_files, on_done)\n\n\nclass HistoryIncrementalDiff(sublime_plugin.TextCommand):\n\n def run(self, edit, **kwargs):\n # Get history directory\n file_name = os.path.basename(self.view.file_name())\n history_dir = get_filedir(self.view.file_name())\n\n # Get history files\n os.chdir(history_dir)\n history_files = glob.glob(\"*\" + file_name)\n history_files.sort(key=lambda f: os.path.getmtime(f), reverse=True)\n if len(history_files) < 2:\n sublime.status_message(\"No Incremental Diff Found\")\n return\n\n def on_done(index):\n # Escape\n if index == -1:\n return\n\n # Selected the last file\n if index == len(history_files) - 1:\n sublime.status_message(\"No Incremental Diff Found\")\n return\n\n # From\n from_file = history_files[index + 1]\n with open(from_file) as f:\n from_content = f.readlines()\n\n # To\n to_file = history_files[index]\n with open(to_file) as f:\n to_content = f.readlines()\n\n # Compare and show diff\n diff = difflib.unified_diff(from_content, to_content, from_file, to_file)\n diff = [d.decode(\"utf8\") for d in diff]\n show_diff(self.view.window(), \"\".join(diff))\n\n self.view.window().show_quick_panel(history_files, on_done)\n\n\nclass HistoryDeleteAll(sublime_plugin.TextCommand):\n\n def run(self, edit):\n shutil.rmtree(HISTORY_PATH)\n sublime.status_message(\"All Local History Deleted\")\n"]],"start1":0,"start2":0,"length1":0,"length2":7678}]],"length":7678}
+{"contributors":[],"silentsave":false,"ts":1352489257662,"patch":[[{"diffs":[[0,"hread\n\n#"],[-1,"--------------"],[1,"=============="],[0,"#\n# Se"]],"start1":178,"start2":178,"length1":30,"length2":30},{"diffs":[[0," #\n#"],[-1,"--------------"],[1,"=============="],[0,"#\nse"]],"start1":216,"start2":216,"length1":22,"length2":22}]],"length":7678,"saved":false}
View
4 history.py
@@ -9,9 +9,9 @@
import shutil
from threading import Thread
-#--------------#
+#==============#
# Settings #
-#--------------#
+#==============#
settings = sublime.load_settings("LocalHistory.sublime-settings")
history_location = settings.get("history_location", "~")
if history_location == "~":
Please sign in to comment.
Something went wrong with that request. Please try again.