mirror of
				https://github.com/vyos/vyos-build.git
				synced 2025-10-01 20:28:40 +02:00 
			
		
		
		
	Since we only support jessie as build host, and jessie knowingly does have python3 (although not by default), we don't really need to worry about being both 2 and 3 compatible.
		
			
				
	
	
		
			73 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			73 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
| #!/usr/bin/python3
 | |
| #
 | |
| # Copyright (C) 2016 VyOS maintainers and contributors
 | |
| #
 | |
| # This program is free software; you can redistribute it and/or modify
 | |
| # it under the terms of the GNU General Public License version 2 or later as
 | |
| # published by the Free Software Foundation.
 | |
| #
 | |
| # This program is distributed in the hope that it will be useful,
 | |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of
 | |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | |
| # GNU General Public License for more details.
 | |
| #
 | |
| # You should have received a copy of the GNU General Public License
 | |
| # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | |
| #
 | |
| # File: make-version-file
 | |
| # Purpose:
 | |
| #   Creates version file in live-build chroot includes dir
 | |
| #   that is included in the image and used by 'show version' command
 | |
| #   and install/upgrade scripts.
 | |
| 
 | |
| import os
 | |
| import datetime
 | |
| import json
 | |
| import uuid
 | |
| 
 | |
| import defaults
 | |
| import util
 | |
| 
 | |
| util.check_build_config()
 | |
| with open(defaults.BUILD_CONFIG, 'r') as f:
 | |
|      build_config = json.load(f)
 | |
| 
 | |
| 
 | |
| now = datetime.datetime.today()
 | |
| 
 | |
| build_timestamp = now.strftime("%Y%m%d%H%M")
 | |
| 
 | |
| # FIXME: use aware rather than naive object
 | |
| build_date = now.strftime("%a %d %b %Y %H:%M UTC")
 | |
| 
 | |
| # Assign a (hopefully) unique identifier to the build (UUID)
 | |
| build_id = str(uuid.uuid4())
 | |
| 
 | |
| if build_config['build_type'] == 'development':
 | |
|     version = "999.{0}".format(build_timestamp)
 | |
| else:
 | |
|     version = build_config['version']
 | |
| 
 | |
| version_data = {
 | |
|     'version': version,
 | |
|     'built_by': build_config['build_by'],
 | |
|     'built_on': build_date,
 | |
|     'build_id': build_id
 | |
| }
 | |
| 
 | |
| 
 | |
| with open(os.path.join(defaults.CHROOT_INCLUDES_DIR, 'opt/vyatta/etc/version.json'), 'w') as f:
 | |
|     json.dump(version_data, f)
 | |
| 
 | |
| # For backwards compatibility with 'add system image' script from older versions
 | |
| # we need a file in old format so that script can find out the version of the image
 | |
| # for upgrade
 | |
| with open(os.path.join(defaults.CHROOT_INCLUDES_DIR, 'opt/vyatta/etc/version'), 'w') as f:
 | |
|     print("Version: {0}".format(version), file=f)
 | |
| 
 | |
| # Leaky abstraction: we want ISO file name include version number,
 | |
| # but we probably don't want to  have a separate build step just for this,
 | |
| # neither we want to use lengthy paths in makefiles
 | |
| with open(os.path.join(defaults.BUILD_DIR, 'version'), 'w') as f:
 | |
|     print(version, file=f)
 |