def test_serialization(self): origin = OriginInfo("https://github.com/lasote/openssl", "OpenSSL_1_0_2_biicode", "biicode_1_0_1l", "9012312387162361287361923") self._assert_serialization(origin) origin = OriginInfo("https://github.com/lasote/openssl", None, "biicode_1_0_1l", None) self._assert_serialization(origin)
def get_publish_params(*parameters): def version_tag(value): '''function to avoid argparse error message override''' from biicode.common.model.version_tag import VersionTag try: return VersionTag.loads(value) except ValueError as e: raise BiiException(str(e)) parser = argparse.ArgumentParser(description=BiiCommand.publish.__doc__, prog="bii publish") parser.add_argument("block", nargs='?', default=None, help='Block name, e.g.: bii publish my_user/my_block. ' 'Do not use with --all argument', type=block_name) parser.add_argument("--tag", help='Release life-cycle TAG, e.g: bii publish --tag ALPHA', type=version_tag) parser.add_argument("--versiontag", help='Name tag for the version. e.g: v1.2 or "Sweet Beacon" ', type=str) parser.add_argument("--msg", help='DEPRECATED: Publication description') parser.add_argument("--all", default=False, action='store_true', help='Publish all blocks. Do not use with block argument') parser.add_argument("-r", "--remote", default=argparse.SUPPRESS, type=str, nargs="?", help='Publish VCS remote info. Format:' ' "remote_url (branch) @commit_id #tag" or blank to autodetect ' '(currently only git supported)') args = parser.parse_args(*parameters) if 'remote' in args: if args.remote: reg = "^(?P<url>\S*)(\s\((?P<branch>\S*)\))*" \ "(\s@(?P<commit>\S*))*(\s#(?P<tag>\S*))*\s*$" pattern = re.compile(reg) values = [m.groupdict() for m in pattern.finditer(args.remote)] if len(values) == 0: # Not Match raise BiiException("Origin info is not valid!") values = values[0] origin = OriginInfo(values.get("url", None), values.get("branch", None), values.get("tag", None), values.get("commit", None), ) else: # Force autodetect origin = OriginInfo(None, None, None, None) else: origin = None return args.block, args.tag, args.versiontag, args.msg, args.all, origin
def _auto_detect_origin_info(self, origin, block_name): hive_disk_image = self.bii.hive_disk_image hive_disk_image.update_root_block() disk_blocks = hive_disk_image.disk_blocks if block_name is None and len(disk_blocks) > 1: raise BiiException('Current project blocks:\n\t' '\n\t'.join(disk_blocks) + 'Please specify block to publish' ' with "$ bii publish my_user/my_block"') try: block_name = block_name or disk_blocks.keys()[0] block_path = disk_blocks[block_name] except: raise BiiException("No block %s to publish in this project" % (block_name or "")) try: origin = detect_updated_origin(block_path) self.bii.user_io.out.info("Detected origin: %s" % str(origin)) except BiiException as exc: # Not auto detected, request input self.bii.user_io.out.warn(str(exc)) self.bii.user_io.out.info("Input origin info:") url = self.bii.user_io.request_string("Url", origin.url) branch = self.bii.user_io.request_string("Branch", origin.branch) commit = self.bii.user_io.request_string("Tag", origin.tag) origin_tag = self.bii.user_io.request_string("Commit", origin.commit) origin = OriginInfo(url, branch, commit, origin_tag) return origin
def deserialize(data): '''From dictionary to object Publish Pack''' pp = PublishRequest() pp.parent = BlockVersion.deserialize( data[PublishRequest.SERIAL_TRACKED_KEY]) pp.parent_time = data[PublishRequest.SERIAL_PARENT_DATETIME] pp.tag = VersionTag.deserialize(data[PublishRequest.SERIAL_TAG_KEY]) pp.msg = data[PublishRequest.SERIAL_MSG_KEY] # Backward client compatibility pp.versiontag = data.get(PublishRequest.SERIAL_VTAG_KEY, None) pp.deptable = BlockVersionTable.deserialize( data[PublishRequest.SERIAL_DEP_TABLE]) pp.cells = ListDeserializer(CellDeserializer(BlockCellName)).\ deserialize(data[PublishRequest.SERIAL_CELLS_KEY]) pp.deleted = ListDeserializer(CellName).\ deserialize(data[PublishRequest.SERIAL_DELETED_KEY]) pp.renames = Renames.deserialize( data[PublishRequest.SERIAL_RENAMES_KEY]) pp.contents = DictDeserializer(CellName, ContentDeserializer(BlockCellName)).\ deserialize(data[PublishRequest.SERIAL_CONTENTS_KEY]) pp.contents_ids = DictDeserializer(CellName, ID).\ deserialize(data[PublishRequest.SERIAL_CONTENTS_ID_KEY]) # Backward client compatibility pp.origin = OriginInfo.deserialize( data.get(PublishRequest.SERIAL_ORIGIN_INFO, None)) return pp
def deserialize(doc): '''Block delta from serialized dictionary''' doc = list(doc) while ( len(doc) < 6 ): # Retrocompatibility with values serialized with not all parameters doc.append(None) return BlockDelta(doc[0], VersionTag.deserialize(doc[1]), doc[2], doc[3], OriginInfo.deserialize(doc[4]), doc[5]) # Msg, tag, date #vtag
def detect_updated_origin(block_path): vcs_detectors = [git_info] # Extend with SVN, Mercurial etc for detector in vcs_detectors: inf = detector(block_path) if (inf and inf["enabled"]): if "origin" in inf["remotes"]: remote = inf["remotes"]["origin"] elif inf["remotes"]: remote = inf["remotes"][inf["remotes"].keys()[0]] else: # Not remote continue if inf["all_pushed"] and inf["all_commited"]: return OriginInfo(remote, inf["branch"], inf["tag"], inf["commit"]) else: raise BiiException("Discarding '%s' origin. Pending changes " "not pushed!" % remote) raise BiiException("No VCS origins detected!")
def deserialize(data): '''From dictionary to object Publish Pack''' pp = PublishRequest() pp.parent = BlockVersion.deserialize(data[PublishRequest.SERIAL_TRACKED_KEY]) pp.parent_time = data[PublishRequest.SERIAL_PARENT_DATETIME] pp.tag = VersionTag.deserialize(data[PublishRequest.SERIAL_TAG_KEY]) pp.msg = data[PublishRequest.SERIAL_MSG_KEY] # Backward client compatibility pp.versiontag = data.get(PublishRequest.SERIAL_VTAG_KEY, None) pp.deptable = BlockVersionTable.deserialize(data[PublishRequest.SERIAL_DEP_TABLE]) pp.cells = ListDeserializer(CellDeserializer(BlockCellName)).\ deserialize(data[PublishRequest.SERIAL_CELLS_KEY]) pp.deleted = ListDeserializer(CellName).\ deserialize(data[PublishRequest.SERIAL_DELETED_KEY]) pp.renames = Renames.deserialize(data[PublishRequest.SERIAL_RENAMES_KEY]) pp.contents = DictDeserializer(CellName, ContentDeserializer(BlockCellName)).\ deserialize(data[PublishRequest.SERIAL_CONTENTS_KEY]) pp.contents_ids = DictDeserializer(CellName, ID).\ deserialize(data[PublishRequest.SERIAL_CONTENTS_ID_KEY]) # Backward client compatibility pp.origin = OriginInfo.deserialize(data.get(PublishRequest.SERIAL_ORIGIN_INFO, None)) return pp
def _assert_serialization(self, ob1): serial = ob1.serialize() ob2 = OriginInfo.deserialize(serial) self._assert_equal(ob1, ob2)