def uuid4(): # Workaround for http://bugs.python.org/issue4607 if ctypes and _uuid_generate_random: buffer = ctypes.create_string_buffer(16) _uuid_generate_random(buffer) return UUID(bytes=buffer.raw) return _uuid4()
def uuid(self, new=False, py=False): u""" UUID を得る。 :param `bool` new: 既存の ID 破棄して新しい ID を割り当てる。 :param `bool` py: Maya 標準機能ではなく Python の機能を使って生成する UUID は uuid という名前のアトリビュートに保存される。 2016 未満では常に True 扱いとなる。 2016 以降では、 それ以前に作られたファイルをリファレンスしていると シーンを開くたびにUUIDが変わってしまう問題を 回避する目的で利用できる。 :rtype: `.UUID` .. note:: 指定UUIDをアサインするには `assignUUID` 、 UUIDからノードを得るには `.CyObject.byUUID` を利用する。 """ if py: return self._py_uuid(new) elif new: val = _uuid4() _rename(self.name(), str(val), uuid=True) return val else: return self._uuid()
def uuid4(): # Workaround for http://bugs.python.org/issue4607 if ctypes and _uuid_generate_random: # pragma: no cover buffer = ctypes.create_string_buffer(16) _uuid_generate_random(buffer) return UUID(bytes=buffer.raw) return _uuid4()
def __init__(self, size=1000, date_time=False, timeout=DEF_TIMEOUT): self._name = (_uuid4().hex).encode("ascii") self._valid = False _lib_call("TOSDB_CreateBlock", self._name, size, date_time, timeout) self._valid = True self._block_size = size self._timeout = timeout self._date_time = date_time self._items = [] self._topics = []
def __init__(self, size=1000, date_time=False, timeout=DEF_TIMEOUT): self._name = (_uuid4().hex).encode("ascii") self._valid = False _lib_call("TOSDB_CreateBlock", self._name, size, date_time, timeout, arg_types=(_str_,_uint32_,_int_,_uint32_) ) self._valid= True self._block_size = size self._timeout = timeout self._date_time = date_time self._items = [] self._topics = []
def _py_uuid(self, new=False, py=False): if not self.hasAttr(UUID_ATTR_NAME): self.addAttr(UUID_ATTR_NAME, 'string') new = True plug = self.plug_(UUID_ATTR_NAME) if new: val = _uuid4() plug.set(str(val)) return val else: return _UUID(plug.get())
def __init__( self, size = 1000, date_time = False, timeout = DEF_TIMEOUT ): self._name = (_uuid4().hex).encode("ascii") self._valid = False err = _lib_call("TOSDB_CreateBlock",self._name,size,date_time,timeout) if( err ): raise TOSDB_CLibError( "error value [ " + str(err) + " ] returned " "from library call", "TOSDB_CreateBlock" ) self._valid= True self._block_size = size self._timeout = timeout self._date_time = date_time self._items = [] self._topics = []
def __init__(self, size=1000, date_time=False, timeout=DEF_TIMEOUT): self._name = (_uuid4().hex).encode("ascii") self._valid = False err = _lib_call("TOSDB_CreateBlock", self._name, size, date_time, timeout) if (err): raise TOSDB_CLibError( "error value [ " + str(err) + " ] returned " "from library call", "TOSDB_CreateBlock") self._valid = True self._block_size = size self._timeout = timeout self._date_time = date_time self._items = [] self._topics = []
def __init__(self, size=1000, date_time=False, timeout=DEF_TIMEOUT): self._name = (_uuid4().hex).encode("ascii") self._block_size = size self._timeout = timeout self._date_time = date_time self._items = [] self._topics = [] self._items_precached = [] self._topics_precached = [] self._valid = False _lib_call("TOSDB_CreateBlock", self._name, size, date_time, timeout, arg_types=(_str_, _uint32_, _int_, _uint32_)) self._valid = True
def _fetch_session_info(self, user, accepted, affordances, **other_tokens): tokens = other_tokens if accepted: session_id = _uuid4().hex session_info = {'user': user, 'accepted': accepted} session_info_json = _json.dumps(session_info) cache = _memcache.Client((self.server,)) cache.set(session_id, session_info_json) tokens.update(session_info) tokens['session_id'] = session_id tokens.update({'user': user, 'accepted': _json.dumps(accepted), 'memcache_server': self.server, 'memcache_username_key': self.username_key}) return _info.RequestAuthInfo(tokens=tokens, provisions= _session.SessionAuth.PROVISIONS, accepted=accepted)
def uuid4(): return str(_uuid4())
def __init__(self, source=None, destination=None, root=None, ignore_hidden=True, account=None, testing_key=None): """Construct the request to write the files specified in 'source' to 'destination' in the cloud object store. You can optionally pass a 'root' for all of the keys in the object store, and, if the source is a directory, you can ignore hidden files using 'ignore_hidden=True'. You must pass the 'account' from which payment will be taken to write files to the object store. Args: source (str): source directory to traverse destination (str, optional): destination directory root (str): root key to use in object store ignore_hidden (bool): If True ignore hidden files in folders, else include hidden files account (Account): instance of Account class testing_key (str): passed to enable testing of class Returns: None """ super().__init__() (filenames, keys) = FileWriteRequest.expand_source_and_destination( source, destination, root, ignore_hidden) self._destination_keys = keys self._source_filenames = filenames self._file_sizes = [] self._checksums = [] if len(self._source_filenames) == 0: self._uid = None return for filename in self._source_filenames: (size, checksum) = _get_filesize_and_checksum(filename) self._file_sizes.append(size) self._checksums.append(checksum) self._is_testing = False if testing_key: self._is_testing = True self._testing_key = testing_key elif account is not None: from Acquire.Client import Account as _Account if not isinstance(account, _Account): raise TypeError("The passed account must be type Account") if not account.is_logged_in(): raise PermissionError( "You can only authorise payment from the account if you " "have logged in") else: raise ValueError("You must pass a valid account to write files!") self._uid = str(_uuid4()) from Acquire.Identity import Authorisation as _Authorisation if self._is_testing: self._account_uid = "something" self._accounting_service_url = "somewhere" self._authorisation = _Authorisation(resource=self.resource_key(), testing_key=self._testing_key) else: self._account_uid = account.uid() self._accounting_service_url = account.accounting_service() \ .canonical_url() self._authorisation = _Authorisation(resource=self.resource_key(), user=account.owner())
def unique_id(): return str(_uuid4())
def uuid(): return _uuid4().hex
def build_record(instrument, dt_from, dt_to, user=None, sample_id=None, generate_previews=True): """ Construct an XML document conforming to the NexusLIMS schema from a directory containing microscopy data files. For calendar parsing, currently no logic is implemented for a query that returns multiple records Parameters ---------- instrument : :py:class:`~nexusLIMS.instruments.Instrument` One of the NexusLIMS instruments contained in the :py:attr:`~nexusLIMS.instruments.instrument_db` database. Controls what instrument calendar is used to get events. dt_from : datetime.datetime dt_to : datetime.datetime The dt_from : :py:class:`~datetime.datetime` or None A :py:class:`~datetime.datetime` object representing the starting timestamp that will be used to determine which files go in this record, as in :py:func:`~.sharepoint_calendar.fetch_xml`. dt_to : :py:class:`~datetime.datetime` or None A :py:class:`~datetime.datetime` object representing the ending timestamp used to determine the last point in time for which files should be associated with this record, as in :py:func:`~.sharepoint_calendar.fetch_xml`. user : str or None A valid NIST username (the short format: e.g. "ear1" instead of [email protected]). Controls the results returned from the calendar - value is as specified in :py:func:`~.sharepoint_calendar.get_events` sample_id : str or None A unique identifier pointing to a sample identifier for data collected in this record. If None, a UUIDv4 will be generated generate_previews : bool Whether or not to create the preview thumbnail images Returns ------- xml_record : str A formatted string containing a well-formed and valid XML document for the data contained in the provided path """ xml_record = '' if sample_id is None: sample_id = str(_uuid4()) # Insert XML prolog, XSLT reference, and namespaces. xml_record += "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n" # TODO: Header elements may be changed once integration into CDCS determined xml_record += "<?xml-stylesheet type=\"text/xsl\" href=\"\"?>\n" xml_record += "<nx:Experiment xmlns=\"\"\n" xml_record += "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" xml_record += "xmlns:nx=\"" \ "https://data.nist.gov/od/dm/nexus/experiment/v1.0\">\n" _logger.info( f"Getting calendar events with instrument: {instrument.name}, " f"from {dt_from.isoformat()} to {dt_to.isoformat()}, " f"user: {user}") events_str = _sp_cal.get_events(instrument=instrument, dt_from=dt_from, dt_to=dt_to, user=user, wrap=True) # Apply XSLT to transform calendar events to single record format: output = _parse_xml(events_str, XSLT_PATH, instrument_PID=instrument.name, instrument_name=instrument.schema_name, experiment_id=str(_uuid4()), collaborator=None, sample_id=sample_id) # No calendar events were found if str(output) == '': output = f'<title>Experiment on the {instrument.schema_name}' \ f' on {dt_from.strftime("%A %b. %d, %Y")}</title>\n' + \ '<id/>\n' + \ '<summary>\n' + \ f' <instrument pid="{instrument.name}">' \ f'{instrument.schema_name}</instrument>\n' + \ '</summary>\n' xml_record += str(output) _logger.info(f"Building acquisition activities for timespan from " f"{dt_from.isoformat()} to {dt_to.isoformat()}") aa_str, activities = build_acq_activities(instrument, dt_from, dt_to, sample_id, generate_previews) xml_record += aa_str xml_record += "</nx:Experiment>" # Add closing tag for root element. return xml_record