Skip to content

Commit

Permalink
Merge pull request #2001 from jmcouffin/rpws-update
Browse files Browse the repository at this point in the history
rpws updates, mostly docstrings edits from rpws repo
  • Loading branch information
jmcouffin authored Nov 9, 2023
2 parents 3708ce3 + f6ab243 commit 117a58b
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 98 deletions.
3 changes: 2 additions & 1 deletion pyrevitlib/rpws/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" python wrapper for Autodesk Revit Server
r"""Python wrapper for Autodesk Revit Server.
This is a python module for interacting with Autodesk Revit Server using
its RESTful API. This module requires 'requests' module for handling http
requests to the Revit Server.
Expand Down
2 changes: 2 additions & 0 deletions pyrevitlib/rpws/api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Revit Server API commands and dictionary keys."""

# http request header
REQ_HEADER_USERNAME = 'User-Name'
REQ_HEADER_MACHINE = 'User-Machine-Name'
Expand Down
31 changes: 29 additions & 2 deletions pyrevitlib/rpws/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,83 @@
# Revit server execeptions -----------------------------------------------------
"""Module exceptions."""


# Revit server execeptions ----------------------------------------------------
class ServerVersionNotSupported(Exception):
"""Server version not supported exception."""

pass


class ServerConnectionError(Exception):
"""Server connection exception."""

pass


class ServerTimeoutError(Exception):
"""Server timeout error."""

pass


class UnhandledException(Exception):
"""General exception for any unhandled exceptions."""

pass


# Revit Server API http status codes ------------------------------------------
# Revit Server API http status codes -----------------------------------------
# 400
class ServerBadRequestError(Exception):
"""Server bad request error."""

pass


# 403
class ServerForbiddenError(Exception):
"""Server forbidden command error."""

pass


# 404
class ServerFileNotFound(Exception):
"""Server file or folder not found error."""

pass


# 405
class ServerMethodNotAllowedError(Exception):
"""Server method not allowed error."""

pass


# 414
class ServerURITooLongError(Exception):
"""Server uri too long error."""

pass


# 500
class ServerInternalError(Exception):
"""Server internal error."""

pass


# 501
class ServerNotImplemented(Exception):
"""Server not implemented error."""

pass


# 503
class ServerServiceUnavailableError(Exception):
"""Server service unavailable error."""

pass
50 changes: 35 additions & 15 deletions pyrevitlib/rpws/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Data structures for wrapping information returned by Revit server."""

import re
from collections import namedtuple
import datetime
Expand Down Expand Up @@ -30,7 +32,7 @@


class ServerRole(enum.Enum):
""" Enum representing various server role codes
"""Enum representing various server role codes.
Attributes:
Host = 0
Expand Down Expand Up @@ -120,7 +122,7 @@ class ServerRole(enum.Enum):


class LockState(enum.Enum):
""" Enum representing Revit Server lock states
"""Enum representing Revit Server lock states.
Attributes:
Unlocked = 0
Expand All @@ -140,12 +142,16 @@ class LockState(enum.Enum):


class LockOptions(enum.Enum):
""" Enum representing Revit Server lock options
"""Enum representing Revit Server lock options.
Attributes:
NotSet = 0
Read = 1
Write = 2
NonExclusiveReadWrite = 128
ReadAndNonExclusiveReadWrite = 129
WriteAndNonExclusiveReadWrite = 130
ReadWriteAndNonExclusiveReadWrite = 130
"""

NotSet = 0
Expand All @@ -158,7 +164,7 @@ class LockOptions(enum.Enum):


class LockType(enum.Enum):
""" Enum representing Revit Server lock type
"""Enum representing Revit Server lock type.
Attributes:
Data = 0
Expand Down Expand Up @@ -286,7 +292,7 @@ class LockType(enum.Enum):


class ParamType(enum.Enum):
""" Enum representing parameter types
"""Enum representing parameter types.
Attributes:
System = 'system'
Expand All @@ -302,7 +308,7 @@ class ParamType(enum.Enum):


class ParamDataType(enum.Enum):
""" Enum representing parameter storage types
"""Enum representing parameter storage types.
Attributes:
Length = 'length'
Expand All @@ -324,8 +330,8 @@ class ParamDataType(enum.Enum):


MHistoryInfo = namedtuple('MHistoryInfo',
['path', # type: str
'items', # type: list<MHistoryItemInfo>
['path', # type: str
'items', # type: list<MHistoryItemInfo>
])
""" namedtuple for model history info
Expand Down Expand Up @@ -392,31 +398,45 @@ class ParamDataType(enum.Enum):


class DateEntry(datetime.datetime):
""" Timestamp data type converting Revit Server string timestamps to
a typical python datetime.datetime object
"""Timestamp data type wrapping Revit Server string timestamps.
Wraps Revit Server string timestamps in a typical python
datetime.datetime subclass.
Example:
>>> ts = DateEntry.fromrsdatestring("/Date(1483465201000)/")
DateEntry(2017, 1, 3, 17, 40, 1)
"""

@classmethod
def fromrsdatestring(cls, date_string):
"""Construct a class instance from Revit server timestamp.
Args:
date_string (str): Revit server timestamp string
"""
seconds_since_epoch = int(date_string[6:-2])/1000
return cls.utcfromtimestamp(seconds_since_epoch)


class TimeSpanEntry(datetime.timedelta):
""" Timespan data type converting Revit Server timespan to
a typical python datetime.timedelta object
"""Timespan data type wrapping Revit Server timespan.
Wraps Revit Server string timespan in a typical python
datetime.timedelta subclass
Example:
>>> ts = TimeSpanEntry.fromrstimespanstring("PT11M42.5154811S")
TimeSpanEntry(0, 5856, 811000)
"""

@classmethod
def fromrstimespanstring(cls, timespan_string):
"""Construct a class instance from Revit server timespan.
Args:
timespan_string (str): Revit server timespan string
"""
days = re.findall('(\d+)D', timespan_string)
days = int(days[0]) if days else 0

Expand All @@ -425,7 +445,7 @@ def fromrstimespanstring(cls, timespan_string):

seconds = re.findall('(\d+)\.(\d+)S', timespan_string)
seconds, millisecs = (int(seconds[0][0]), int(seconds[0][1])) \
if seconds else (0, 0)
if seconds else (0, 0)

return cls(days=days, minutes=minutes,
seconds=seconds, milliseconds=millisecs)
Loading

0 comments on commit 117a58b

Please sign in to comment.