dp_changelogs wuth reboot
							parent
							
								
									1752eebd03
								
							
						
					
					
						commit
						682ae668bd
					
				|  | @ -12,5 +12,4 @@ | ||||||
|         <field name="code">model.cron_get_changelog() |         <field name="code">model.cron_get_changelog() | ||||||
|         </field> |         </field> | ||||||
|     </record> |     </record> | ||||||
| 
 |  | ||||||
| </odoo> | </odoo> | ||||||
|  |  | ||||||
|  | @ -2,6 +2,7 @@ | ||||||
| 
 | 
 | ||||||
| from subprocess import check_output | from subprocess import check_output | ||||||
| import pytz | import pytz | ||||||
|  | import os | ||||||
| 
 | 
 | ||||||
| from odoo import models, fields, api, tools | from odoo import models, fields, api, tools | ||||||
| 
 | 
 | ||||||
|  | @ -20,35 +21,65 @@ class ChangeLog(models.Model): | ||||||
|         tz_name = self.env.context.get('tz') or tools.config.get('timezone') |         tz_name = self.env.context.get('tz') or tools.config.get('timezone') | ||||||
|         date_string = fields.datetime.now().strftime("%Y-%m-%d %H:%M:%S") |         date_string = fields.datetime.now().strftime("%Y-%m-%d %H:%M:%S") | ||||||
|         date_string = fields.Datetime.to_string( |         date_string = fields.Datetime.to_string( | ||||||
|             pytz.timezone('UTC').localize(fields.Datetime.from_string(date_string), is_dst=None).astimezone( |             pytz.timezone('UTC').localize(fields.Datetime.from_string(date_string), | ||||||
|  |                                           is_dst=None).astimezone( | ||||||
|                 pytz.timezone(tz_name))) |                 pytz.timezone(tz_name))) | ||||||
|         return 'Changelog ' + date_string[:-3] |         return 'Changelog ' + date_string[:-3] | ||||||
| 
 | 
 | ||||||
|     name = fields.Char('Name', required=True, default=_get_changelog_name) |     name = fields.Char('Name', required=True, default=_get_changelog_name) | ||||||
|     date = fields.Date('Datum', required=True, default=lambda *a: fields.datetime.now()) |     date = fields.Datetime('Timestamp', required=True, default=lambda *a: fields.datetime.now()) | ||||||
|     commit = fields.Char('Commit') |     commit = fields.Char('Commit') | ||||||
|     changelogs = fields.Text('Changelogs') |     changelogs = fields.Text('Changelogs') | ||||||
|  |     ppid = fields.Char('letzte ppid') | ||||||
| 
 | 
 | ||||||
|     @api.model |     @api.model | ||||||
|     def cron_get_changelog(self): |     def cron_get_changelog(self): | ||||||
|         vals = self._get_changelogs_vals() |         vals = self._get_changelogs_vals() | ||||||
|  |         changelog = False | ||||||
|  |         if vals: | ||||||
|             changelog = self.create(vals) |             changelog = self.create(vals) | ||||||
|         return changelog |         return changelog | ||||||
| 
 | 
 | ||||||
|     @api.model |     @api.model | ||||||
|     def _get_changelogs_vals(self): |     def _get_changelogs_vals(self): | ||||||
|         commit = check_output(["git", "log", "--pretty=oneline", "-1"]) |         commit = check_output(["git", "log", "--pretty=oneline", "-1"]) | ||||||
|         commit1 = self.search([], limit=1) |         last_commit = self.search([], limit=1) | ||||||
|         com2 = commit.decode("utf-8") |         com2 = commit.decode("utf-8") | ||||||
|         com2 = com2.split(' ')[0] |         com2 = com2.split(' ')[0] | ||||||
|         new_logs = b'' |         new_logs = b'' | ||||||
|         if commit1: |         if last_commit: | ||||||
|             com1 = commit1.commit |             com1 = last_commit.commit | ||||||
|             changelogs = check_output(["git", "log", "--pretty=oneline", com1 + "..." + com2]) |             changelogs = check_output(["git", "log", "--pretty=oneline", com1 + "..." + com2]) | ||||||
|             new_logs = b'' |  | ||||||
|             for changelog in changelogs.splitlines(): |             for changelog in changelogs.splitlines(): | ||||||
|                 new_logs += b' '.join(changelog.split(b' ')[1:]) + b'\n' |                 new_logs += b' '.join(changelog.split(b' ')[1:]) + b'\n' | ||||||
|         return { |         if new_logs == b'': | ||||||
|  |             vals = {} | ||||||
|  |         else: | ||||||
|  |             vals = { | ||||||
|                 'commit': com2, |                 'commit': com2, | ||||||
|             'changelogs': new_logs |                 'changelogs': new_logs, | ||||||
|  |                 'ppid': last_commit.ppid | ||||||
|             } |             } | ||||||
|  |         return vals | ||||||
|  | 
 | ||||||
|  |     @api.model | ||||||
|  |     def _get_reboot_vals(self): | ||||||
|  |         last_commit = self.search([], limit=1) | ||||||
|  |         if last_commit and last_commit.ppid != str(os.getppid()): | ||||||
|  |             vals = { | ||||||
|  |                 'commit': last_commit.commit, | ||||||
|  |                 'changelogs': 'Reboot', | ||||||
|  |                 'ppid': str(os.getppid()) | ||||||
|  |             } | ||||||
|  |             return vals | ||||||
|  | 
 | ||||||
|  |     @api.model_cr | ||||||
|  |     def _register_hook(self): | ||||||
|  |         try: | ||||||
|  |             self.cron_get_changelog() | ||||||
|  |             vals = self._get_reboot_vals() | ||||||
|  |             if vals: | ||||||
|  |                 self.create(vals) | ||||||
|  |         except: | ||||||
|  |             # falls git nicht vorhanden ist wird sicher eine Fehler ausgegeben. | ||||||
|  |             pass | ||||||
|  |  | ||||||
|  | @ -10,6 +10,7 @@ | ||||||
|                     <field name="name"/> |                     <field name="name"/> | ||||||
|                     <field name="date"/> |                     <field name="date"/> | ||||||
|                     <field name="commit"/> |                     <field name="commit"/> | ||||||
|  |                     <field name="ppid"/> | ||||||
|                 </group> |                 </group> | ||||||
|                 <group name="changelogs"> |                 <group name="changelogs"> | ||||||
|                     <field name="changelogs"/> |                     <field name="changelogs"/> | ||||||
|  | @ -27,6 +28,7 @@ | ||||||
|                 <field name="name"/> |                 <field name="name"/> | ||||||
|                 <field name="date"/> |                 <field name="date"/> | ||||||
|                 <field name="commit"/> |                 <field name="commit"/> | ||||||
|  |                 <field name="ppid"/> | ||||||
|                 <field name="changelogs"/> |                 <field name="changelogs"/> | ||||||
|             </tree> |             </tree> | ||||||
|         </field> |         </field> | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue