Commits

Manabu TERADA  committed 115da79

number of issue backup data remove function

  • Participants
  • Parent commits 29a0f03
  • Tags 1.0b3

Comments (0)

Files changed (6)

 ----------------------
 
 - modify buckup function comment of issue [Manabu TERADA]
-- any number of issue backup data, but nothing remove function yet [Manabu TERADA]
+- any number of issue backup data [Manabu TERADA]
 
 
 1.0b2 (2012-08-25)
     ignore_project =
         xxxxxx1
         xxxxxx2
+    isseu_backup_count = 3
 
 Run the buildout ::
 

File buildout.cfg

 eggs = c2.recipe.bitbucketbk [tests]
 
 
+

File c2/recipe/bitbucketbk/README.txt

 	option
 	Listing project name, if do you have no backup project 
 
+isseu_backup_count
+    default 3
+    Number of backup data for issue
+
 Example usage
 =============
 

File c2/recipe/bitbucketbk/__init__.py

         ignore_project = options.get('ignore_project', '')
         self.ignore_projcet = tuple([ignore.strip() for ignore in
                                         ignore_project.split('\n') if ignore.strip()])
-        
+        options.setdefault('isseu_backup_count', '3')
+
         self.egg = zc.recipe.egg.Egg(buildout, options['recipe'], options)
         
         python = buildout['buildout']['python']
         options['bin-directory'] = buildout['buildout']['bin-directory']
         options['backup_name'] = self.name
         check_for_true(options, [])
-        
+
         self.options = options
 
     def install(self):
 password = %(password)r
 location = %(location)r
 ignore_project = %(ignore_project)r
+isseu_backup_count = %(isseu_backup_count)s
 """
         opts = self.options.copy()
         opts['ignore_project'] = self.ignore_projcet
               'backup_main')],
             #requirements,
             ws, self.options['executable'], self.options['bin-directory'],
-            arguments=('username, password, location, ignore_project'),
+            arguments=('username, password, location, ignore_project, isseu_backup_count'),
             initialization=initialization)
         return scripts
 
         else:
             options[key] = 'False'
 
+def modify_to_int(opthins, keys):
+    for key in keys:
+        opthins[key] = int(opthins[key])
+
 def construct_path(buildout_dir, path):
     """Return absolute path, taking into account buildout dir and ~ expansion.
 

File c2/recipe/bitbucketbk/backuprunner.py

     issues = json.load(bitbucket_obj).get('issues', [])
     _save_excel_data(issues_folder_location, repo_name, issues, access_api_base, api_url)
 
-def remove_old_issue_data(): #TODO
-    pass
 
-def backup_main(username, password, location, ignore_project):
+
+def remove_old_issue_data(issues_folder_location, isseu_backup_count):
+    def _cmp_mtime(x, y):
+        x_file = os.path.join(issues_folder_location, x)
+        y_file = os.path.join(issues_folder_location, y)
+        return cmp(os.stat(x_file).st_mtime, os.stat(y_file).st_mtime)
+    files = os.listdir(issues_folder_location)
+    for i, path in enumerate(sorted(files,
+        cmp=_cmp_mtime, reverse=True)):
+        if i > isseu_backup_count:
+            os.remove(os.path.join(issues_folder_location, path))
+
+def backup_main(username, password, location, ignore_project, isseu_backup_count):
     """Main method, gets called by generated bin/bitbucketbk.
     """
     if not os.path.exists(os.path.join(location, ISSUES_LOCATION)):
             if not os.path.exists(issues_folder_location):
                 os.mkdir(issues_folder_location)
             backup_isseus(access_api_base, repo_name, username, issues_folder_location)
-            remove_old_issue_data()
+            remove_old_issue_data(issues_folder_location, isseu_backup_count)
 
 if __name__ == '__main__':
     backup_main()