forked from abock/osc-plugins
-
Notifications
You must be signed in to change notification settings - Fork 1
/
vc_meego.py
70 lines (56 loc) · 2.07 KB
/
vc_meego.py
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
# vc_meego.py
# osc plugin to write MeeGo compliant .changes files
#
# Written by Frederic Crozat <fcrozat@novell.com>
# Copyright 2010 Novell, Inc.
# Released under the MIT/X11 license.
#
def do_vc_meego (self, subcmd, opts, *args):
"""${cmd_name}: update changes with MeeGo format
${cmd_usage}
${cmd_option_list}
"""
import os
import fnmatch
from datetime import date
import pwd
import re
if len(args) > 0:
arg = args[0]
else:
arg = ""
# set user's email if no mailaddr exists
if not os.environ.has_key('mailaddr'):
if arg and is_package_dir(arg):
apiurl = store_read_apiurl(arg)
else:
apiurl = self.get_api_url()
user = conf.get_apiurl_usr(apiurl)
# work with all combinations of URL with or withouth the ending slas
if conf.config['api_host_options'][apiurl].has_key('email'):
mailaddr = conf.config['api_host_options'][apiurl] ['email']
else:
try:
mailaddr = get_user_data(apiurl, user, 'email')[0]
except Exception, e:
sys.exit('%s\nget_user_data(email) failed. Try env mailaddr= ....\n' % e)
else:
mailaddr = os.environ.get('mailaddr');
realname = pwd.getpwuid(os.getuid()).pw_gecos
re_spec_version = re.compile('^(Version:\s*)(\S*)', re.IGNORECASE)
for spec_file in fnmatch.filter(os.listdir('.'),'*.spec'):
fin = open(spec_file, 'r')
version = ""
for line in fin.readlines():
match = re_spec_version.match(line)
if match:
version = " - " + match.group(2)
break
for file in fnmatch.filter(os.listdir('.'),'*.changes'):
with open (file, "r+") as f:
old = f.read()
f.seek(0)
# * dow mmm dd yyyy Name Goes Here <your@email.com> - [version]"
f.write ("* " + date.today().strftime("%a %b %d %Y")+ " " + realname
+ " <" +mailaddr + ">"+ version + "\n" + old)
# self.do_vc (subcmd, opts, *args)