Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / common / extensions / docs / server2 / platform_util.py
blob84e8c7480f30b5ce1554cabced4e4f6cb35215d9
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 from path_util import AssertIsValid
8 _EXTENSION_TYPES = {'extensions': 'extension', 'apps': 'platform_app'}
11 def GetPlatforms():
12 return ('apps', 'extensions')
15 def GetExtensionTypes():
16 return ('platform_app', 'extension')
19 def ExtractPlatformFromURL(url):
20 '''Returns 'apps' or 'extensions' depending on the URL.
21 '''
22 AssertIsValid(url)
23 platform = url.split('/', 1)[0]
24 if platform not in GetPlatforms():
25 return None
26 return platform
29 def PluralToSingular(platform):
30 '''Converts 'apps' to 'app' and 'extensions' to 'extension'.
31 '''
32 assert platform in GetPlatforms(), platform
33 return platform[:-1]
36 def PlatformToExtensionType(platform):
37 assert platform in GetPlatforms(), platform
38 return _EXTENSION_TYPES[platform]