summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/docs/server2/build_server.py
blob: 276213f765005b4946077ce6b478c96c4f43438e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# This script is used to copy all dependencies into the local directory.
# The package of files can then be uploaded to App Engine.
import os
import shutil
import stat
import sys

SRC_DIR = os.path.join(sys.path[0], os.pardir, os.pardir, os.pardir, os.pardir,
    os.pardir)
THIRD_PARTY_DIR = os.path.join(SRC_DIR, 'third_party')
LOCAL_THIRD_PARTY_DIR = os.path.join(sys.path[0], 'third_party')
TOOLS_DIR = os.path.join(SRC_DIR, 'tools')
SCHEMA_COMPILER_FILES = ['memoize.py',
                         'model.py',
                         'idl_schema.py',
                         'schema_util.py',
                         'json_parse.py']

def MakeInit(path):
  path = os.path.join(path, '__init__.py')
  with open(os.path.join(path), 'w') as f:
    os.utime(os.path.join(path), None)

def OnError(function, path, excinfo):
  os.chmod(path, stat.S_IWUSR)
  function(path)

def CopyThirdParty(src, dest, files=None, make_init=True):
  dest_path = os.path.join(LOCAL_THIRD_PARTY_DIR, dest)
  if not files:
    shutil.copytree(src, dest_path)
    if make_init:
      MakeInit(dest_path)
    return
  try:
    os.makedirs(dest_path)
  except Exception:
    pass
  if make_init:
    MakeInit(dest_path)
  for filename in files:
    shutil.copy(os.path.join(src, filename), os.path.join(dest_path, filename))

def main():
  if os.path.isdir(LOCAL_THIRD_PARTY_DIR):
    try:
      shutil.rmtree(LOCAL_THIRD_PARTY_DIR, False, OnError)
    except OSError:
      print('*-------------------------------------------------------------*\n'
            '| If you are receiving an upload error, try removing          |\n'
            '| chrome/common/extensions/docs/server2/third_party manually. |\n'
            '*-------------------------------------------------------------*\n')


  CopyThirdParty(os.path.join(THIRD_PARTY_DIR, 'handlebar'), 'handlebar')
  CopyThirdParty(os.path.join(SRC_DIR, 'ppapi', 'generators'),
                 'json_schema_compiler')
  CopyThirdParty(os.path.join(THIRD_PARTY_DIR, 'ply'),
                 os.path.join('json_schema_compiler', 'ply'))
  CopyThirdParty(os.path.join(TOOLS_DIR, 'json_schema_compiler'),
                 'json_schema_compiler',
                 SCHEMA_COMPILER_FILES)
  CopyThirdParty(os.path.join(TOOLS_DIR, 'json_comment_eater'),
                 'json_schema_compiler',
                 ['json_comment_eater.py'])
  CopyThirdParty(os.path.join(THIRD_PARTY_DIR, 'simplejson'),
                 os.path.join('json_schema_compiler', 'simplejson'),
                 make_init=False)
  MakeInit(LOCAL_THIRD_PARTY_DIR)

  # To be able to use the Handlebar class we need this import in __init__.py.
  with open(os.path.join(LOCAL_THIRD_PARTY_DIR,
                         'handlebar',
                         '__init__.py'), 'a') as f:
    f.write('from handlebar import Handlebar\n')

if __name__ == '__main__':
  main()