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.
4
5from path_util import AssertIsValid
6
7
8_EXTENSION_TYPES = {'extensions': 'extension', 'apps': 'platform_app'}
9
10
11def GetPlatforms():
12  return ('apps', 'extensions')
13
14
15def GetExtensionTypes():
16  return ('platform_app', 'extension')
17
18
19def 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
27
28
29def PluralToSingular(platform):
30  '''Converts 'apps' to 'app' and 'extensions' to 'extension'.
31  '''
32  assert platform in GetPlatforms(), platform
33  return platform[:-1]
34
35
36def PlatformToExtensionType(platform):
37  assert platform in GetPlatforms(), platform
38  return _EXTENSION_TYPES[platform]
39