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
113
114
115
116
117
|
#!/usr/bin/env python
import argparse
import os
import re
import subprocess
import sys
import common
from devbot import config
GIT_CONFIG_SETUP = "sugar-build.send-patches.setup"
def get_git_config(name, is_global=False):
args = ["git", "config"]
if is_global:
args.append("--global")
args.append(name)
try:
return subprocess.check_output(args)
except subprocess.CalledProcessError:
return None
def set_git_config(name, value):
return subprocess.check_output(["git", "config", name, value])
def unset_git_config(name):
try:
subprocess.check_output(["git", "config", "--unset", name])
return True
except subprocess.CalledProcessError:
return False
def get_from():
name = get_git_config("user.name", is_global=True)
email = get_git_config("user.email", is_global=True)
if not name or not email:
print("Please configure your name and email\n\n"
"git config --global user.name Your Name\n"
"git config --global user.email youremail@example.com")
sys.exit(1)
return "%s <%s>" % (name, email)
def get_module():
for line in open("configure.ac"):
m = re.match("AC_INIT\((.+)\)", line)
if m:
return m.group(1).split(",")[-1][1:-1]
def setup():
print("Choose how to send email \n\n"
"1 Google account\n"
"2 Sugar Labs shell account\n"
"3 System sendmail")
choice = None
while choice not in ["1", "2", "3"]:
choice = input("# ")
if choice == "1":
print("\nEnter your user name")
smtpuser = input("# ")
set_git_config("sendemail.smtpencryption", "tls")
set_git_config("sendemail.smtpserver", "smtp.gmail.com")
set_git_config("sendemail.smtpserverport", "587")
set_git_config("sendemail.smtpuser", smtpuser)
elif choice == "2":
print("\nEnter your user name")
smtpuser = input("# ")
set_git_config("sendemail.smtpencryption", "tls")
set_git_config("sendemail.smtpserver", "smtp.sugarlabs.org")
set_git_config("sendemail.smtpserverport", "587")
set_git_config("sendemail.smtpuser", smtpuser)
elif choice == "3":
unset_git_config("sendemail.smtpencryption")
unset_git_config("sendemail.smtpserver")
unset_git_config("sendemail.smtpserverport")
unset_git_config("sendemail.smtpuser")
set_git_config(GIT_CONFIG_SETUP, "true")
common.setup()
if os.path.dirname(os.getcwd()) != config.get_source_dir():
print("The command must be run inside one of the source modules.")
sys.exit(1)
parser = argparse.ArgumentParser()
parser.add_argument("--setup", action="store_true",
help="interactive configuration")
parser.add_argument('rev_list', nargs='?', default='origin')
args = parser.parse_args()
if not get_git_config(GIT_CONFIG_SETUP) or args.setup:
setup()
subprocess.call(["git", "send-email",
"-from", get_from(),
"-to", "sugar-devel <sugar-devel@lists.sugarlabs.org>",
"--subject-prefix", "PATCH %s" % get_module(),
args.rev_list])
|