Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
__init__.py283 linesDownload Raw Back to profiles
1#-------------------------------------------------------------------------2# Copyright (c) Microsoft Corporation. All rights reserved.3# Licensed under the MIT License. See License.txt in the project root for4# license information.5#--------------------------------------------------------------------------6from enum import Enum7 8class ProfileDefinition(object):9    """Allow to define a custom Profile definition.10 11    Note::12 13    The dict format taken as input is yet to be confirmed and should14    *not* be considered as stable in the current implementation.15 16    :param dict profile_dict: A profile dictionnary17    :param str label: A label for pretty printing18    """19    def __init__(self, profile_dict, label=None):20        self._profile_dict = profile_dict21        self._label = label22 23    @property24    def label(self):25        """The label associated to this profile definition.26        """27        return self._label28 29    def __repr__(self):30        return self._label if self._label else self._profile_dict.__repr__()31 32    def get_profile_dict(self):33        """Return the current profile dict.34 35        This is internal information, and content should not be considered stable.36        """37        return self._profile_dict38 39 40class DefaultProfile(object):41    """Store a default profile.42 43    :var ProfileDefinition profile: The default profile as class attribute44    """45    profile = None46 47    def use(self, profile):48        """Define a new default profile."""49        if not isinstance(profile, (KnownProfiles, ProfileDefinition)):50            raise ValueError("Can only set as default a ProfileDefinition or a KnownProfiles")51        type(self).profile = profile52 53    def definition(self):54        return type(self).profile55 56class KnownProfiles(Enum):57    """This defines known Azure Profiles.58 59    There is two meta-profiles:60 61    - latest : will always use latest available api-version on each package62    - default : mutable, will define profile automatically for all packages63 64    If you change default, this changes all created packages on the fly to65    this profile. This can be used to switch a complete set of API Version66    without re-creating all clients.67    """68 69    # default - This is a meta-profile and point to another profile70    default = DefaultProfile()71    # latest - This is a meta-profile and does not contain definitions72    latest = ProfileDefinition(None, "latest")73    v2017_03_09_profile = ProfileDefinition(74        {75            "azure.keyvault.KeyVaultClient":{76                None: "2016-10-01"77            },78            "azure.mgmt.authorization.AuthorizationManagementClient": {79                None: "2015-07-01"80            },81            "azure.mgmt.compute.ComputeManagementClient": {82                None: "2016-03-30"83            },84            "azure.mgmt.keyvault.KeyVaultManagementClient":{85                None: "2016-10-01"86            },87            "azure.mgmt.network.NetworkManagementClient": {88                None: "2015-06-15"89            },90            "azure.mgmt.storage.StorageManagementClient": {91                None: "2016-01-01"92            },93            "azure.mgmt.resource.policy.PolicyClient": {94                None: "2015-10-01-preview"95            },96            "azure.mgmt.resource.locks.ManagementLockClient": {97                None: "2015-01-01"98            },99            "azure.mgmt.resource.links.ManagementLinkClient": {100                None: "2016-09-01"101            },102            "azure.mgmt.resource.resources.ResourceManagementClient": {103                None: "2016-02-01"104            },105            "azure.mgmt.resource.subscriptions.SubscriptionClient": {106                None: "2016-06-01"107            }108        },109        "2017-03-09-profile"110    )111    v2018_03_01_hybrid = ProfileDefinition(112        {113            "azure.keyvault.KeyVaultClient":{114                None: "2016-10-01"115            },116            "azure.mgmt.authorization.AuthorizationManagementClient": {117                None: "2015-07-01"118            },119            "azure.mgmt.compute.ComputeManagementClient": {120                None: "2017-03-30"121            },122            "azure.mgmt.keyvault.KeyVaultManagementClient":{123                None: "2016-10-01"124            },125            "azure.mgmt.network.NetworkManagementClient": {126                None: "2017-10-01"127            },128            "azure.mgmt.storage.StorageManagementClient": {129                None: "2016-01-01"130            },131            "azure.mgmt.resource.policy.PolicyClient": {132                None: "2016-12-01"133            },134            "azure.mgmt.resource.locks.ManagementLockClient": {135                None: "2016-09-01"136            },137            "azure.mgmt.resource.links.ManagementLinkClient": {138                None: "2016-09-01"139            },140            "azure.mgmt.resource.resources.ResourceManagementClient": {141                None: "2018-02-01"142            },143            "azure.mgmt.resource.subscriptions.SubscriptionClient": {144                None: "2016-06-01"145            },146            "azure.mgmt.dns.DnsManagementClient": {147                None: "2016-04-01"148            }149        },150        "2018-03-01-hybrid"151    )152    v2019_03_01_hybrid = ProfileDefinition(153        {154            "azure.keyvault.KeyVaultClient": {155                None: "2016-10-01"156            },157            "azure.mgmt.authorization.AuthorizationManagementClient": {158                None: "2015-07-01"159            },160            "azure.mgmt.compute.ComputeManagementClient": {161                None: "2017-12-01",162                'resource_skus': '2017-09-01',163                'disks': '2017-03-30',164                'snapshots': '2017-03-30'165            },166            "azure.mgmt.keyvault.KeyVaultManagementClient":{167                None: "2016-10-01"168            },169            "azure.mgmt.monitor.MonitorManagementClient": {170                'metric_definitions': '2018-01-01',171                'metrics': '2018-01-01',172                'diagnostic_settings': '2017-05-01-preview',173                'diagnostic_settings_category': '2017-05-01-preview',174                'event_categories': '2015-04-01',175                'operations': '2015-04-01',176            },177            "azure.mgmt.network.NetworkManagementClient": {178                None: "2017-10-01"179            },180            "azure.mgmt.storage.StorageManagementClient": {181                None: "2017-10-01"182            },183            "azure.mgmt.resource.policy.PolicyClient": {184                None: "2016-12-01"185            },186            "azure.mgmt.resource.locks.ManagementLockClient": {187                None: "2016-09-01"188            },189            "azure.mgmt.resource.links.ManagementLinkClient": {190                None: "2016-09-01"191            },192            "azure.mgmt.resource.resources.ResourceManagementClient": {193                None: "2018-05-01"194            },195            "azure.mgmt.resource.subscriptions.SubscriptionClient": {196                None: "2016-06-01"197            },198            "azure.mgmt.dns.DnsManagementClient": {199                None: "2016-04-01"200            }201        },202        "2019-03-01-hybrid"203    )204    v2020_09_01_hybrid = ProfileDefinition(205        {206            "azure.keyvault.KeyVaultClient": {207                None: "2016-10-01"208            },209            "azure.mgmt.authorization.AuthorizationManagementClient": {210                None: "2016-09-01"211            },212            "azure.mgmt.compute.ComputeManagementClient": {213                None: "2020-06-01",214                'resource_skus': '2019-04-01',215                'disks': '2019-07-01',216                'snapshots': '2019-07-01'217            },218            "azure.mgmt.keyvault.KeyVaultManagementClient":{219                None: "2019-09-01"220            },221            "azure.mgmt.monitor.MonitorManagementClient": {222                'metric_definitions': '2018-01-01',223                'metrics': '2018-01-01',224                'diagnostic_settings': '2017-05-01-preview',225                'diagnostic_settings_category': '2017-05-01-preview',226                'event_categories': '2015-04-01',227                'operations': '2015-04-01',228            },229            "azure.mgmt.network.NetworkManagementClient": {230                None: "2018-11-01"231            },232            "azure.mgmt.storage.StorageManagementClient": {233                None: "2019-06-01"234            },235            "azure.mgmt.resource.policy.PolicyClient": {236                None: "2016-12-01"237            },238            "azure.mgmt.resource.locks.ManagementLockClient": {239                None: "2016-09-01"240            },241            "azure.mgmt.resource.links.ManagementLinkClient": {242                None: "2016-09-01"243            },244            "azure.mgmt.resource.resources.ResourceManagementClient": {245                None: "2019-10-01"246            },247            "azure.mgmt.resource.subscriptions.SubscriptionClient": {248                None: "2016-06-01"249            },250            "azure.mgmt.dns.DnsManagementClient": {251                None: "2016-04-01"252            }253        },254        "2020-09-01-hybrid"255    )256 257 258    def __init__(self, profile_definition):259        self._profile_definition = profile_definition260 261    def use(self, profile):262        if self is not type(self).default:263            raise ValueError("use can only be used for `default` profile")264        self.value.use(profile)265 266    def definition(self):267        if self is not type(self).default:268            raise ValueError("use can only be used for `default` profile")269        return self.value.definition()270 271    @classmethod272    def from_name(cls, profile_name):273        if profile_name == "default":274            return cls.default275        for profile in cls:276            if isinstance(profile.value, ProfileDefinition) and profile.value.label == profile_name:277                return profile278        raise ValueError("No profile called {}".format(profile_name))279 280 281# Default profile is floating "latest"282KnownProfiles.default.use(KnownProfiles.latest)283 
codekingpro/portable-devtools · Team Ai