summaryrefslogtreecommitdiff
path: root/.update-xref.py
blob: 629f3707ec0f655d9e29d12d1ea6dc08532bb8a0 (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/bash
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# ===| BASH Stub |=============================================================

# The beginning of this script is both valid shell and valid python,
# such that the script starts with the shell and is reexecuted with
# the right python.
'''echo' $0: Starting up...
if [ -f "/opt/rh/python27/root/usr/bin/python2.7" ];then
    BINOC_PYTHON_ARGS=$@
    exec scl enable python27 "python $0 $BINOC_PYTHON_ARGS"
elif BINOC_PYTHON_PATH="$(which python2.7 2>/dev/null)"; then
    exec $BINOC_PYTHON_PATH $0 "$@"
else
    echo "$0 error: Python 2.7 was not found on this system"
    exit 1
fi
'''
# =============================================================================

# ===| Imports |===============================================================

from __future__ import print_function
import os
import sys
import subprocess
import platform

# =============================================================================

# ===| Global Variables |======================================================

strScriptPath = os.path.abspath(os.path.dirname(__file__))
strProjectsPath = strScriptPath + '/projects/'
strGitBinary = ''

# =============================================================================

# ===| Function: Output Message |==============================================

def funcOutputMessage(_messageType, _messageBody):
    _messagePrefix = 'update:'
    _errorPrefix = '{0} error:'.format(_messagePrefix)      
    _messageTemplates = {
        'statusGen'  : '{0} {1}'.format(_messagePrefix, _messageBody),
        'statusDep1' : '{0} Searching for {1}...'.format(_messagePrefix, _messageBody),
        'statusDep2' : '{0} Found {1}'.format(_messagePrefix, _messageBody),
        'errorGen' : '{0} {1}'.format(_errorPrefix, _messageBody),
        'errorDep' : '{0} {1} was not found on your system!'.format(_errorPrefix, _messageBody)
    }
    
    if _messageType in _messageTemplates:
        print(_messageTemplates[_messageType])
        if _messageTemplates[_messageType].find('error') != -1:
            sys.exit(1)
    else:
        print('{0} Unknown error - Referenced as \'{1}\' internally.'.format(_messagePrefix, _messageType))
        sys.exit(1)

# =============================================================================

# ===| Prerequisites |=========================================================

### Check for Git
funcOutputMessage("statusDep1", "Git")
if platform.system() == "Windows":
    if os.path.exists(os.path.normpath("c:/Program Files/Git/bin/git.exe")):
        strGitBinary = os.path.normpath("c:/Program Files/Git/bin/git.exe")
        funcOutputMessage("statusDep2", strGitBinary)
    elif os.path.exists(os.path.normpath("c:/Program Files (x86)/Git/bin/git.exe")):
        strGitBinary = os.path.normpath("c:/Program Files (x86)/Git/bin/git.exe")
        funcOutputMessage("statusDep2", strGitBinary)
    else:
       funcOutputMessage("errorDep", "Git")
elif platform.system() == "Linux":
    if os.path.exists("/usr/bin/git"):
        strGitBinary = "git"
        funcOutputMessage("statusDep2", strGitBinary)
    else:
        funcOutputMessage("errorDep", "Git")

# =============================================================================

# ===| Main |==================================================================

strSubPath = ''

# ambassador
strSubPath = '/mozilla/application/ambassador/'
funcOutputMessage('statusGen', 'Updating ambassador repository')
subprocess.call('"{0}" {1}'.format(strGitBinary, 'checkout'), shell=True, cwd=strScriptPath + strSubPath)
subprocess.call('"{0}" {1}'.format(strGitBinary, 'pull'), shell=True, cwd=strScriptPath + strSubPath)

# iceweasel-uxp
# strSubPath = '/mozilla/application/iceweasel-uxp/'
# funcOutputMessage('statusGen', 'Updating iceweasel repository')
# subprocess.call('"{0}" {1}'.format(strGitBinary, 'checkout'), shell=True, cwd=strScriptPath + strSubPath)
# subprocess.call('"{0}" {1}'.format(strGitBinary, 'pull'), shell=True, cwd=strScriptPath + strSubPath)

strSubPath = '/mozilla/'
funcOutputMessage('statusGen', 'Updating unified xul platform repository')
subprocess.call('"{0}" {1}'.format(strGitBinary, 'submodule update'), shell=True, cwd=strScriptPath)

# top-level
funcOutputMessage('statusGen', 'Updating top-level repository')
subprocess.call('"{0}" {1}'.format(strGitBinary, 'checkout'), shell=True, cwd=strScriptPath)
subprocess.call('"{0}" {1}'.format(strGitBinary, 'pull'), shell=True, cwd=strScriptPath)

# =============================================================================