def test_fields_access(): """Check package fields access are working""" t = """ Package: mypackage Version: 1.0 Var: foo Var-Var: baz Final: ${Var} ${Var-Var} """ f = StringIO(t) pkgs = Package.read(f) eq_(len(pkgs), 1) assert pkgs[0].defined('') is False assert pkgs[0].defined('Var') is True assert pkgs[0].defined('Vbr') is False assert pkgs[0].defined('Var-Var') is True assert pkgs[0].defined('Var-Vbr') is False assert pkgs[0].defined('Var_Var') is True assert pkgs[0].defined('Var_Vbr') is False with assert_raises(AttributeError) as ex: _ = pkgs[0].vbr ok_(pkgs[0].get('Vbr') is None) eq_(pkgs[0].get('var'), 'foo') eq_(pkgs[0].var, 'foo') eq_(pkgs[0].get('var-var'), 'baz') eq_(pkgs[0].var_var, 'baz') eq_(pkgs[0].get('final'), '${Var} ${Var-Var}') eq_(pkgs[0].final, '${Var} ${Var-Var}') eq_(pkgs[0].expand('${Var}'), 'foo') eq_(pkgs[0].expand('${var}'), 'foo') eq_(pkgs[0].expand('${Var_Var}'), 'baz') eq_(pkgs[0].expand('${var_var}'), 'baz') eq_(pkgs[0].expand('${Var-Var}'), 'baz') eq_(pkgs[0].expand('${var-var}'), 'baz') eq_(pkgs[0].expand(pkgs[0].final), 'foo baz')
def test_read_source_package_with_checksum(): """Check parsing a source package definitions with checksums""" t = """ Package: mypackage Version: 2.3.4 Vim-Version: 23 2.3 Source-URL: https://downloads.repo.net/mypackage Source: any mypackage_src.zip ${Source-URL}/mypackage-${Version}-src.zip Source-Dir: mypackage_${Version} Checksum: mypackage_src.zip sha256 0001020304050607080910111213141516171819202122232425262728293132 Install: x86 mypackage_${Version}_x86 x64 mypackage_${Version}_x64 """ f = StringIO(t) pkgs = Package.read(f) eq_(len(pkgs), 1) rscs = pkgs[0].resources() eq_(len(rscs), 1) rsc = rscs[0] eq_(rsc.get(), (Arch.any, 'mypackage_src.zip', 'https://downloads.repo.net/mypackage/mypackage-2.3.4-src.zip')) assert rsc.checksums is not None eq_(rsc.checksums, [('sha256', '0001020304050607080910111213141516171819202122232425262728293132')]) paths = pkgs[0].install_paths() eq_(paths, [(Arch.find('x86'), 'mypackage_2.3.4_x86'), (Arch.find('x64'), 'mypackage_2.3.4_x64')])
def test_read_source_package(): """Check parsing a source package definitions""" t = """ Package: mypackage Version: 2.3.4 Vim-Version: 23 2.3 Source-URL: https://downloads.repo.net/mypackage Source: any mypackage_src.zip ${Source-URL}/mypackage-${Version}-src.zip Source-Dir: mypackage_${Version} Install: x86 mypackage_${Version}_x86 x64 mypackage_${Version}_x64 """ f = StringIO(t) pkgs = Package.read(f) eq_(len(pkgs), 1) eq_(pkgs[0].name, 'mypackage') eq_(pkgs[0].version, '2.3.4') eq_(pkgs[0].vim_version, '23 2.3') rscs = pkgs[0].resources() eq_(len(rscs), 1) rsc = rscs[0] eq_(rsc.get(), (Arch.any, 'mypackage_src.zip', 'https://downloads.repo.net/mypackage/mypackage-2.3.4-src.zip')) assert rsc.checksums is not None eq_(rsc.checksums, []) paths = pkgs[0].install_paths() eq_(paths, [(Arch.find('x86'), 'mypackage_2.3.4_x86'), (Arch.find('x64'), 'mypackage_2.3.4_x64')])
def test_name_field_is_forbidden(): """'Name' field is forbidden in package definition""" t = """ Package: mypackage Version: 1.0 Name: mypackage """ f = StringIO(t) with assert_raises(PackageException) as pe: pkgs = Package.read(f) ex = pe.exception eq_(ex.package, 'mypackage') eq_(ex.field, 'Name') eq_(ex.reason, 'not allowed in keys')
def home_post(): if 'file' not in request.files: return redirect(request.url) file = request.files['file'] if file: pkg = Package.from_tarball(file) file.seek(0) try: src_contrib.push(pkg) except DuplicatePkgException: abort(CONFLICT_CODE, 'This package version already exists on the server.') return 'OK\n' return abort(400, 'You must upload a tarball file to use the POST endpoint.')
def test_fails_on_duplicated_key(): """Fails if a field is defined twice""" t = """ Package: mypackage Version: 1.0 Var: foo Var: baz """ f = StringIO(t) with assert_raises(PackageException) as pe: pkgs = Package.read(f) ex = pe.exception eq_(ex.package, 'mypackage') eq_(ex.field, 'Var') eq_(ex.reason, 'already defined')
def test_read_empty_package(): """Minimal read of packages definitions""" t = """Package: mypackage Version: 0.1 Package: myotherpackage Version: 0.2 """ f = StringIO(t) pkgs = Package.read(f) eq_(len(pkgs), 2) eq_(pkgs[0].name, 'mypackage') eq_(pkgs[0].version, '0.1') eq_(str(pkgs[0]), 'Package(mypackage, 0.1)') eq_(pkgs[1].name, 'myotherpackage') eq_(pkgs[1].version, '0.2') eq_(str(pkgs[1]), 'Package(myotherpackage, 0.2)')
def main(): parser = argparse.ArgumentParser(description='Download external packages.') parser.add_argument('packages', type=argparse.FileType(encoding='utf-8'), nargs='+', help='list of packages to read') parser.add_argument('-n', '--nop', dest='nop', action='store_true', help='Describe what will be done') parser.add_argument('-a', '--arch', type=str, dest='arch', default='', help='Only download for specific architecture') args = parser.parse_args() if args.arch: arch = args.arch else: arch = os.getenv('ARCH', 'all') pkgs = [] for f in args.packages: pkgs += Package.read(f) if not get_all(pkgs, arch, nop=args.nop): sys.exit(1)
def test_malformed_source(): """'Source' field in package must be lines of three fields separated by spaces.""" t = """ Package: mypackage Version: 2.3.4 Source: any mypackage_src.zip https://downloads.repo.net/mypackage/mypackage-${Version}-src.zip """ f = StringIO(t) with assert_raises(PackageException) as pe: pkgs = Package.read(f) rscs = pkgs[0].resources() eq_(len(rscs), 1) ex = pe.exception eq_(ex.package, 'mypackage') eq_(ex.field, 'Source') eq_(ex.reason, 'not enough values to unpack (expected 3, got 2)')
def test_read_python36_package(): """Check parsing Python 3.6 package definitions""" t = """ Package: python3 Version: 3.6 Vim-Version: 36 Install: x86 C:\Program Files\Python36 x64 C:\Program Files\Python36 """ f = StringIO(t) pkgs = Package.read(f) eq_(len(pkgs), 1) eq_(pkgs[0].name, 'python3') eq_(pkgs[0].version, '3.6') eq_(pkgs[0].vim_version, '36') paths = pkgs[0].install_paths() eq_(paths, [(Arch.find('x86'), 'C:\Program Files\Python36'), (Arch.find('x64'), 'C:\Program Files\Python36')])
def main(): parser = argparse.ArgumentParser(description='Download external packages.') parser.add_argument('packages', type=argparse.FileType(encoding='utf-8'), nargs='+', help='list of packages to read') parser.add_argument('-o', '--ninja', type=str, dest='ninja', default='', help='Generate ninja file') parser.add_argument('-t', '--template-dir', type=str, dest='template_dir', default='./', help='Generate ninja file') parser.add_argument('-b', '--batch', type=str, dest='batch', default='', help='Generate dosbatch file') parser.add_argument('--vim', type=str, dest='vim_version', default='', required=True, help='Generate dosbatch file') args = parser.parse_args() packages = [] for f in args.packages: packages += Package.read(f) config = make_config(packages, vim_version=args.vim_version[1:]) if args.batch: render(args.batch, args.batch + '.j2', config, searchpath=args.template_dir) if args.ninja: render(args.ninja, args.ninja + '.j2', config, searchpath=args.template_dir)
def pack(self): package = Package() self.__config.set_sections() sections = self.__config.get_sections() if self.__command_line_argument in sections: package.set_config(self.__command_line_argument) package.load_config() package.remove_temp_dir() package.create_temp_dir() package.check_dest_install_and_clone() package.if_testing_change_branch() package.write_debian_file() package.write_pre_inst_file() package.write_post_inst_file() package.write_pre_rm_file() package.write_post_rm_file() package.clean_project() package.build() package.send_to_repo() package.remove_temp_dir() else: for section in sections: package.set_config(section) package.load_config() package.remove_temp_dir() package.create_temp_dir() package.check_dest_install_and_clone() package.if_testing_change_branch() package.write_debian_file() package.write_pre_inst_file() package.write_post_inst_file() package.write_pre_rm_file() package.write_post_rm_file() package.clean_project() package.build() package.send_to_repo() package.remove_temp_dir()