{"action":"created","comment":{"url":"https://api.github.com/repos/GafferHQ/gaffer/pulls/comments/170791427","pull_request_review_id":99531202,"id":170791427,"diff_hunk":"@@ -0,0 +1,305 @@\n+##########################################################################\n+#\n+#  Copyright (c) 2018, Image Engine Design Inc. All rights reserved.\n+#\n+#  Redistribution and use in source and binary forms, with or without\n+#  modification, are permitted provided that the following conditions are\n+#  met:\n+#\n+#      * Redistributions of source code must retain the above\n+#        copyright notice, this list of conditions and the following\n+#        disclaimer.\n+#\n+#      * Redistributions in binary form must reproduce the above\n+#        copyright notice, this list of conditions and the following\n+#        disclaimer in the documentation and/or other materials provided with\n+#        the distribution.\n+#\n+#      * Neither the name of John Haddon nor the names of\n+#        any other contributors to this software may be used to endorse or\n+#        promote products derived from this software without specific prior\n+#        written permission.\n+#\n+#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS\n+#  IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\n+#  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n+#  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+#  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\n+#  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n+#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n+#  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\n+#  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\n+#  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\n+#  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+#\n+##########################################################################\n+\n+import Gaffer\n+\n+import IECore\n+\n+from Qt import QtCore\n+\n+import collections\n+import os\n+import stat\n+import weakref\n+\n+class Backups( object ) :\n+\n+\tdef __init__( self, applicationRoot ) :\n+\n+\t\t# \\todo I wonder if it would make sense for this sort\n+\t\t# of \"bolt on\" component to be a GraphComponent that was\n+\t\t# parented under the ApplicationRoot somewhere, instead\n+\t\t# of manually tracking the \"parent\" like this?\n+\t\tself.__applicationRoot = weakref.ref( applicationRoot )\n+\n+\t\tself.__settings = Gaffer.Plug()\n+\t\tself.__settings[\"enabled\"] = Gaffer.BoolPlug( defaultValue = True )\n+\t\tself.__settings[\"frequency\"] = Gaffer.IntPlug( defaultValue = 5, minValue = 0 )\n+\t\tself.__settings[\"fileName\"] = Gaffer.StringPlug( defaultValue = \"${script:directory}/.gafferBackups/${script:name}-backup${backup:number}.gfr\" )\n+\t\tself.__settings[\"files\"] = Gaffer.IntPlug( defaultValue = 10, minValue = 1 )\n+\n+\t\tapplicationRoot[\"preferences\"][\"backups\"] = self.__settings\n+\n+\t\tself.__plugSetConnection = applicationRoot[\"preferences\"].plugSetSignal().connect( self.__plugSet )\n+\n+\t\tself.__timer = QtCore.QTimer()\n+\t\tself.__timer.timeout.connect( Gaffer.WeakMethod( self.__timeout ) )\n+\n+\t\t# Initialise the timer\n+\t\tself.__plugSet( self.__settings[\"enabled\"] )\n+\n+\t# Creates a backup for the specified script, returning the\n+\t# name of the backup file. This is really only public so we\n+\t# can call it from the unit tests.\n+\tdef backup( self, script ) :\n+\n+\t\tfileName = None\n+\t\texistingFiles = []\n+\t\tfor f in self.__potentialFileNames( script ) :\n+\t\t\tif not os.path.exists( f ) :\n+\t\t\t\tfileName = f\n+\t\t\t\tbreak\n+\t\t\telse :\n+\t\t\t\texistingFiles.append( ( os.path.getmtime( f ), f ) )\n+\n+\t\tif fileName is None :\n+\t\t\t# All files exist already, sort by modification\n+\t\t\t# time and choose the oldest.\n+\t\t\texistingFiles.sort()\n+\t\t\tfileName = existingFiles[0][1]\n+\n+\t\tdirName = os.path.dirname( fileName )\n+\t\ttry :\n+\t\t\tos.makedirs( dirName )","path":"python/GafferUI/Backups.py","position":96,"original_position":96,"commit_id":"58a4d9112fa940a3f5703ae24efa7c506ac04b91","original_commit_id":"6f4e2009e64b040dee3fb787034fda4ce001b0dd","user":{"login":"andrewkaufman","id":3979682,"avatar_url":"https://avatars1.githubusercontent.com/u/3979682?v=4","gravatar_id":"","url":"https://api.github.com/users/andrewkaufman","html_url":"https://github.com/andrewkaufman","followers_url":"https://api.github.com/users/andrewkaufman/followers","following_url":"https://api.github.com/users/andrewkaufman/following{/other_user}","gists_url":"https://api.github.com/users/andrewkaufman/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewkaufman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewkaufman/subscriptions","organizations_url":"https://api.github.com/users/andrewkaufman/orgs","repos_url":"https://api.github.com/users/andrewkaufman/repos","events_url":"https://api.github.com/users/andrewkaufman/events{/privacy}","received_events_url":"https://api.github.com/users/andrewkaufman/received_events","type":"User","site_admin":false},"body":"I think shutil has a solution that doesn't raise when the directorty exists","created_at":"2018-02-27T01:28:06Z","updated_at":"2018-02-27T01:32:31Z","html_url":"https://github.com/GafferHQ/gaffer/pull/2469#discussion_r170791427","pull_request_url":"https://api.github.com/repos/GafferHQ/gaffer/pulls/2469","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/GafferHQ/gaffer/pulls/comments/170791427"},"html":{"href":"https://github.com/GafferHQ/gaffer/pull/2469#discussion_r170791427"},"pull_request":{"href":"https://api.github.com/repos/GafferHQ/gaffer/pulls/2469"}}},"pull_request":{"url":"https://api.github.com/repos/GafferHQ/gaffer/pulls/2469","id":171143552,"html_url":"https://github.com/GafferHQ/gaffer/pull/2469","diff_url":"https://github.com/GafferHQ/gaffer/pull/2469.diff","patch_url":"https://github.com/GafferHQ/gaffer/pull/2469.patch","issue_url":"https://api.github.com/repos/GafferHQ/gaffer/issues/2469","number":2469,"state":"open","locked":false,"title":"Autosave backups of open scripts","user":{"login":"johnhaddon","id":1133871,"avatar_url":"https://avatars0.githubusercontent.com/u/1133871?v=4","gravatar_id":"","url":"https://api.github.com/users/johnhaddon","html_url":"https://github.com/johnhaddon","followers_url":"https://api.github.com/users/johnhaddon/followers","following_url":"https://api.github.com/users/johnhaddon/following{/other_user}","gists_url":"https://api.github.com/users/johnhaddon/gists{/gist_id}","starred_url":"https://api.github.com/users/johnhaddon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johnhaddon/subscriptions","organizations_url":"https://api.github.com/users/johnhaddon/orgs","repos_url":"https://api.github.com/users/johnhaddon/repos","events_url":"https://api.github.com/users/johnhaddon/events{/privacy}","received_events_url":"https://api.github.com/users/johnhaddon/received_events","type":"User","site_admin":false},"body":"You know, just in case Gaffer were to crash. If you want to test this interactively as well as review the code, you might find it useful to do the following :\r\n\r\n- Hack the timer multiplier so that it works in seconds rather than minutes\r\n- Run with `IECORE_LOG_LEVEL=Info`, to be notified of what backups are being made and when\r\n\r\n@donboie, we'll need to give some thought to how this interacts with Caribou, where the script is embedded in a Maya session and Maya itself will be doing autosaves. It might be sufficient to simply have a Caribou config that turns off `[\"preferences\"][\"backups\"][\"enabled\"]` and hides the plugs, but I haven't done any testing of that idea.","created_at":"2018-02-23T23:52:41Z","updated_at":"2018-02-27T01:32:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a56117d30be122fc3844fc174121ab28985c7188","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/GafferHQ/gaffer/pulls/2469/commits","review_comments_url":"https://api.github.com/repos/GafferHQ/gaffer/pulls/2469/comments","review_comment_url":"https://api.github.com/repos/GafferHQ/gaffer/pulls/comments{/number}","comments_url":"https://api.github.com/repos/GafferHQ/gaffer/issues/2469/comments","statuses_url":"https://api.github.com/repos/GafferHQ/gaffer/statuses/58a4d9112fa940a3f5703ae24efa7c506ac04b91","head":{"label":"johnhaddon:autosave","ref":"autosave","sha":"58a4d9112fa940a3f5703ae24efa7c506ac04b91","user":{"login":"johnhaddon","id":1133871,"avatar_url":"https://avatars0.githubusercontent.com/u/1133871?v=4","gravatar_id":"","url":"https://api.github.com/users/johnhaddon","html_url":"https://github.com/johnhaddon","followers_url":"https://api.github.com/users/johnhaddon/followers","following_url":"https://api.github.com/users/johnhaddon/following{/other_user}","gists_url":"https://api.github.com/users/johnhaddon/gists{/gist_id}","starred_url":"https://api.github.com/users/johnhaddon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johnhaddon/subscriptions","organizations_url":"https://api.github.com/users/johnhaddon/orgs","repos_url":"https://api.github.com/users/johnhaddon/repos","events_url":"https://api.github.com/users/johnhaddon/events{/privacy}","received_events_url":"https://api.github.com/users/johnhaddon/received_events","type":"User","site_admin":false},"repo":{"id":9043150,"name":"gaffer","full_name":"johnhaddon/gaffer","owner":{"login":"johnhaddon","id":1133871,"avatar_url":"https://avatars0.githubusercontent.com/u/1133871?v=4","gravatar_id":"","url":"https://api.github.com/users/johnhaddon","html_url":"https://github.com/johnhaddon","followers_url":"https://api.github.com/users/johnhaddon/followers","following_url":"https://api.github.com/users/johnhaddon/following{/other_user}","gists_url":"https://api.github.com/users/johnhaddon/gists{/gist_id}","starred_url":"https://api.github.com/users/johnhaddon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johnhaddon/subscriptions","organizations_url":"https://api.github.com/users/johnhaddon/orgs","repos_url":"https://api.github.com/users/johnhaddon/repos","events_url":"https://api.github.com/users/johnhaddon/events{/privacy}","received_events_url":"https://api.github.com/users/johnhaddon/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/johnhaddon/gaffer","description":"My day-to-day development","fork":true,"url":"https://api.github.com/repos/johnhaddon/gaffer","forks_url":"https://api.github.com/repos/johnhaddon/gaffer/forks","keys_url":"https://api.github.com/repos/johnhaddon/gaffer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/johnhaddon/gaffer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/johnhaddon/gaffer/teams","hooks_url":"https://api.github.com/repos/johnhaddon/gaffer/hooks","issue_events_url":"https://api.github.com/repos/johnhaddon/gaffer/issues/events{/number}","events_url":"https://api.github.com/repos/johnhaddon/gaffer/events","assignees_url":"https://api.github.com/repos/johnhaddon/gaffer/assignees{/user}","branches_url":"https://api.github.com/repos/johnhaddon/gaffer/branches{/branch}","tags_url":"https://api.github.com/repos/johnhaddon/gaffer/tags","blobs_url":"https://api.github.com/repos/johnhaddon/gaffer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/johnhaddon/gaffer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/johnhaddon/gaffer/git/refs{/sha}","trees_url":"https://api.github.com/repos/johnhaddon/gaffer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/johnhaddon/gaffer/statuses/{sha}","languages_url":"https://api.github.com/repos/johnhaddon/gaffer/languages","stargazers_url":"https://api.github.com/repos/johnhaddon/gaffer/stargazers","contributors_url":"https://api.github.com/repos/johnhaddon/gaffer/contributors","subscribers_url":"https://api.github.com/repos/johnhaddon/gaffer/subscribers","subscription_url":"https://api.github.com/repos/johnhaddon/gaffer/subscription","commits_url":"https://api.github.com/repos/johnhaddon/gaffer/commits{/sha}","git_commits_url":"https://api.github.com/repos/johnhaddon/gaffer/git/commits{/sha}","comments_url":"https://api.github.com/repos/johnhaddon/gaffer/comments{/number}","issue_comment_url":"https://api.github.com/repos/johnhaddon/gaffer/issues/comments{/number}","contents_url":"https://api.github.com/repos/johnhaddon/gaffer/contents/{+path}","compare_url":"https://api.github.com/repos/johnhaddon/gaffer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/johnhaddon/gaffer/merges","archive_url":"https://api.github.com/repos/johnhaddon/gaffer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/johnhaddon/gaffer/downloads","issues_url":"https://api.github.com/repos/johnhaddon/gaffer/issues{/number}","pulls_url":"https://api.github.com/repos/johnhaddon/gaffer/pulls{/number}","milestones_url":"https://api.github.com/repos/johnhaddon/gaffer/milestones{/number}","notifications_url":"https://api.github.com/repos/johnhaddon/gaffer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/johnhaddon/gaffer/labels{/name}","releases_url":"https://api.github.com/repos/johnhaddon/gaffer/releases{/id}","deployments_url":"https://api.github.com/repos/johnhaddon/gaffer/deployments","created_at":"2013-03-27T00:06:40Z","updated_at":"2017-11-02T13:05:51Z","pushed_at":"2018-02-25T22:57:02Z","git_url":"git://github.com/johnhaddon/gaffer.git","ssh_url":"git@github.com:johnhaddon/gaffer.git","clone_url":"https://github.com/johnhaddon/gaffer.git","svn_url":"https://github.com/johnhaddon/gaffer","homepage":"","size":32831,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"GafferHQ:master","ref":"master","sha":"15443d46157341a9f57dfd2428943de744c12a97","user":{"login":"GafferHQ","id":20556043,"avatar_url":"https://avatars1.githubusercontent.com/u/20556043?v=4","gravatar_id":"","url":"https://api.github.com/users/GafferHQ","html_url":"https://github.com/GafferHQ","followers_url":"https://api.github.com/users/GafferHQ/followers","following_url":"https://api.github.com/users/GafferHQ/following{/other_user}","gists_url":"https://api.github.com/users/GafferHQ/gists{/gist_id}","starred_url":"https://api.github.com/users/GafferHQ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GafferHQ/subscriptions","organizations_url":"https://api.github.com/users/GafferHQ/orgs","repos_url":"https://api.github.com/users/GafferHQ/repos","events_url":"https://api.github.com/users/GafferHQ/events{/privacy}","received_events_url":"https://api.github.com/users/GafferHQ/received_events","type":"Organization","site_admin":false},"repo":{"id":9043124,"name":"gaffer","full_name":"GafferHQ/gaffer","owner":{"login":"GafferHQ","id":20556043,"avatar_url":"https://avatars1.githubusercontent.com/u/20556043?v=4","gravatar_id":"","url":"https://api.github.com/users/GafferHQ","html_url":"https://github.com/GafferHQ","followers_url":"https://api.github.com/users/GafferHQ/followers","following_url":"https://api.github.com/users/GafferHQ/following{/other_user}","gists_url":"https://api.github.com/users/GafferHQ/gists{/gist_id}","starred_url":"https://api.github.com/users/GafferHQ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GafferHQ/subscriptions","organizations_url":"https://api.github.com/users/GafferHQ/orgs","repos_url":"https://api.github.com/users/GafferHQ/repos","events_url":"https://api.github.com/users/GafferHQ/events{/privacy}","received_events_url":"https://api.github.com/users/GafferHQ/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/GafferHQ/gaffer","description":"Gaffer is an open source application framework designed specifically for creating tools for use in visual effects production.","fork":false,"url":"https://api.github.com/repos/GafferHQ/gaffer","forks_url":"https://api.github.com/repos/GafferHQ/gaffer/forks","keys_url":"https://api.github.com/repos/GafferHQ/gaffer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/GafferHQ/gaffer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/GafferHQ/gaffer/teams","hooks_url":"https://api.github.com/repos/GafferHQ/gaffer/hooks","issue_events_url":"https://api.github.com/repos/GafferHQ/gaffer/issues/events{/number}","events_url":"https://api.github.com/repos/GafferHQ/gaffer/events","assignees_url":"https://api.github.com/repos/GafferHQ/gaffer/assignees{/user}","branches_url":"https://api.github.com/repos/GafferHQ/gaffer/branches{/branch}","tags_url":"https://api.github.com/repos/GafferHQ/gaffer/tags","blobs_url":"https://api.github.com/repos/GafferHQ/gaffer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/GafferHQ/gaffer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/GafferHQ/gaffer/git/refs{/sha}","trees_url":"https://api.github.com/repos/GafferHQ/gaffer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/GafferHQ/gaffer/statuses/{sha}","languages_url":"https://api.github.com/repos/GafferHQ/gaffer/languages","stargazers_url":"https://api.github.com/repos/GafferHQ/gaffer/stargazers","contributors_url":"https://api.github.com/repos/GafferHQ/gaffer/contributors","subscribers_url":"https://api.github.com/repos/GafferHQ/gaffer/subscribers","subscription_url":"https://api.github.com/repos/GafferHQ/gaffer/subscription","commits_url":"https://api.github.com/repos/GafferHQ/gaffer/commits{/sha}","git_commits_url":"https://api.github.com/repos/GafferHQ/gaffer/git/commits{/sha}","comments_url":"https://api.github.com/repos/GafferHQ/gaffer/comments{/number}","issue_comment_url":"https://api.github.com/repos/GafferHQ/gaffer/issues/comments{/number}","contents_url":"https://api.github.com/repos/GafferHQ/gaffer/contents/{+path}","compare_url":"https://api.github.com/repos/GafferHQ/gaffer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/GafferHQ/gaffer/merges","archive_url":"https://api.github.com/repos/GafferHQ/gaffer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/GafferHQ/gaffer/downloads","issues_url":"https://api.github.com/repos/GafferHQ/gaffer/issues{/number}","pulls_url":"https://api.github.com/repos/GafferHQ/gaffer/pulls{/number}","milestones_url":"https://api.github.com/repos/GafferHQ/gaffer/milestones{/number}","notifications_url":"https://api.github.com/repos/GafferHQ/gaffer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/GafferHQ/gaffer/labels{/name}","releases_url":"https://api.github.com/repos/GafferHQ/gaffer/releases{/id}","deployments_url":"https://api.github.com/repos/GafferHQ/gaffer/deployments","created_at":"2013-03-27T00:04:53Z","updated_at":"2018-02-09T02:32:47Z","pushed_at":"2018-02-26T05:02:31Z","git_url":"git://github.com/GafferHQ/gaffer.git","ssh_url":"git@github.com:GafferHQ/gaffer.git","clone_url":"https://github.com/GafferHQ/gaffer.git","svn_url":"https://github.com/GafferHQ/gaffer","homepage":"http://www.gafferhq.org","size":32540,"stargazers_count":330,"watchers_count":330,"language":"C++","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":113,"mirror_url":null,"archived":false,"open_issues_count":206,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":113,"open_issues":206,"watchers":330,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/GafferHQ/gaffer/pulls/2469"},"html":{"href":"https://github.com/GafferHQ/gaffer/pull/2469"},"issue":{"href":"https://api.github.com/repos/GafferHQ/gaffer/issues/2469"},"comments":{"href":"https://api.github.com/repos/GafferHQ/gaffer/issues/2469/comments"},"review_comments":{"href":"https://api.github.com/repos/GafferHQ/gaffer/pulls/2469/comments"},"review_comment":{"href":"https://api.github.com/repos/GafferHQ/gaffer/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/GafferHQ/gaffer/pulls/2469/commits"},"statuses":{"href":"https://api.github.com/repos/GafferHQ/gaffer/statuses/58a4d9112fa940a3f5703ae24efa7c506ac04b91"}},"author_association":"OWNER"}}
{"actor":{"display_login":"andrewkaufman"}}