changeset 3841:979edf6a2990 beta

Prefix gist storage with rc, and store some metadata info into gist store repos
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 11 May 2013 21:33:45 +0200
parents dc4644865e8b
children 54bc7a89f090
files rhodecode/model/gist.py
diffstat 1 files changed, 15 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/model/gist.py	Sat May 11 20:24:02 2013 +0200
+++ b/rhodecode/model/gist.py	Sat May 11 21:33:45 2013 +0200
@@ -22,7 +22,7 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
+from __future__ import with_statement
 import os
 import time
 import logging
@@ -32,6 +32,7 @@
 from pylons.i18n.translation import _
 from rhodecode.lib.utils2 import safe_unicode, unique_id, safe_int, \
     time_to_datetime, safe_str, AttributeDict
+from rhodecode.lib.compat import json
 from rhodecode.lib import helpers as h
 from rhodecode.model import BaseModel
 from rhodecode.model.db import Gist
@@ -41,7 +42,8 @@
 
 log = logging.getLogger(__name__)
 
-GIST_STORE_LOC = '.gist_store'
+GIST_STORE_LOC = '.rc_gist_store'
+GIST_METADATA_FILE = '.rc_gist_metadata'
 
 
 class GistModel(BaseModel):
@@ -143,7 +145,17 @@
             nodes=processed_mapping,
             trigger_push_hook=False
         )
-
+        # store metadata inside the gist, this can be later used for imports
+        # or gist identification
+        metadata = {
+            'gist_db_id': gist.gist_id,
+            'gist_access_id': gist.gist_access_id,
+            'gist_owner_id': owner.user_id,
+            'gist_type': gist.gist_type,
+            'gist_exipres': gist.gist_expires
+        }
+        with open(os.path.join(repo.path, '.hg', GIST_METADATA_FILE), 'wb') as f:
+            f.write(json.dumps(metadata))
         return gist
 
     def delete(self, gist, fs_remove=True):