Mailinglist Archive: opensuse-buildservice (250 mails)

< Previous Next >
Re: [opensuse-buildservice] osc vc: configurable email adress
  • From: Michal Vyskocil <mvyskocil@xxxxxxx>
  • Date: Fri, 17 Apr 2009 11:03:36 +0200
  • Message-id: <200904171103.37087.mvyskocil@xxxxxxx>
On Thursday 16 of April 2009 18:18:58 Dominique Leuenberger wrote:
[snip]

Where do you get the address from? I think it would be great if this could
be specified in ~/.obsrc I for example NEVER use the email address I use on
IChain. simply becasue on IChain I have my work account registered (as
we're Novell Client I need access to NCC) but all the commits I do into OBS
are 'private' based.. so even though I use my business IChain account, I
would not want this email address to appear in the RPM Changelogs.

The new patch adds and optional email field to ~/.oscrc

[https://api.opensuse.org/]
user = login
pass = password
email = not@xxxxxxxxxxxx

So you can define an email for each API. If it was not found, then osc will
get a metadata from BS.

Regards
Michal Vyskocil
Index: osc/core.py
===================================================================
--- osc/core.py (revision 7099)
+++ osc/core.py (working copy)
@@ -1942,7 +1942,44 @@
elif input in 'eE':
pass

+def edit_changes(changes, email, change_message = ''):
+ import tempfile
+ import shutil
+ import time

+ (fd, filename) = tempfile.mkstemp(prefix = 'osc-changesmsg', suffix =
'.diff', dir = '/tmp')
+ f = os.fdopen(fd, 'w')
+
+ f.write('-' * 67 + '\n')
+ f.write("%s - %s\n\n" % (time.strftime("%a %b %d %H:%M:%S UTC %Y",
time.gmtime()), email))
+ f.write("- ")
+ if change_message:
+ f.write(change_message)
+ f.write("\n\n")
+
+ # add a rest of content file
+ fin = open(changes, 'r')
+ while 1:
+ buf = fin.read(BUFSIZE)
+ if not buf: break
+ f.write(buf)
+ fin.close()
+
+ f.flush()
+ f.close()
+ mtime_orig = os.stat(filename).st_mtime
+
+ if not change_message:
+ editor = os.getenv('EDITOR', default='vim')
+ subprocess.call('%s +4 %s' % (editor, filename), shell=True)
+
+ mtime = os.stat(filename).st_mtime
+
+ if change_message or mtime_orig < mtime:
+ # move it back
+ shutil.move(filename, changes)
+
+
def create_submit_request(apiurl,
src_project, src_package,
dst_project, dst_package,
Index: osc/conf.py
===================================================================
--- osc/conf.py (revision 7097)
+++ osc/conf.py (working copy)
@@ -111,6 +111,8 @@
pass = %(pass)s
# set aliases for this apiurl
# aliases = foo, bar
+# type email for changes, unless IChain one will be used
+# email =
# additional headers to pass to a request, e.g. for special authentication
#http_headers = Host: foofoobar,
# User: mumblegack
@@ -356,6 +358,9 @@
#from the general section.
user = cp.get(url, 'user')
password = cp.get(url, 'pass')
+ email = ''
+ if cp.has_option(url, 'email'):
+ email = cp.get(url, 'email')

if cp.has_option(url, 'http_headers'):
http_headers = cp.get(url, 'http_headers')
@@ -374,7 +379,9 @@

api_host_options[apiurl] = { 'user': user,
'pass': password,
- 'http_headers': http_headers};
+ 'http_headers': http_headers}
+ if email:
+ api_host_options[apiurl]['email'] = email

# add the auth data we collected to the config dict
config['api_host_options'] = api_host_options
Index: osc/commandline.py
===================================================================
--- osc/commandline.py (revision 7099)
+++ osc/commandline.py (working copy)
@@ -2695,6 +2695,65 @@
for data in streamfile(u):
sys.stdout.write(data)

+ @cmdln.option('-f', '--retry-lock', action='store_true', default=False,
+ help='TODO')
+ @cmdln.option('-m', '--message',
+ help='Change message')
+ def do_vc(self, subcmd, opts, *args):
+ """${cmd_name}: Edit the changes file
+
+ osc vc [filename[.changes]] [file_with_comment]]
+ If no <filename> is given, exactly one *.changes or *.spec file has to
+ be in the cwd.
+
+ The email adress used in .changes file is read from BuildService
+ instance, or should be defined in ~/.oscrc
+ [https://api.opensuse.org/]
+ user = login
+ pass = password
+ email = user@xxxxxxxxxxxxx
+
+ ${cmd_usage}
+ ${cmd_option_list}
+ """
+
+ import glob
+
+ file = ""
+ # detect the name of file to edit
+ if args:
+ if os.path.isfile(args[0]):
+ file = args[0]
+ elif os.path.isfile(args[0] + ".changes"):
+ file = args[0] + ".changes"
+ else:
+ files = glob.glob("*.changes")
+ if not files:
+ files = glob.glob("*.spec")
+
+ if not files:
+ print >>sys.stderr, "Error: no changes specified. Type osc vc
--help"
+ sys.exit(1)
+ elif len(files) >= 2:
+ print >>sys.stderr, "Error: Multiple targets found. Type osc
vc --help"
+ sys.exit(1)
+
+ file = files[0].replace('.spec', '.changes')
+
+ # user's email
+ apiurl = conf.config['apiurl']
+ user = conf.config['user']
+ if conf.config['api_host_options'][apiurl].has_key('email'):
+ email = conf.config['api_host_options'][apiurl]['email']
+ else:
+ email = get_user_data(apiurl, user, 'email')[0]
+
+ edit_changes(os.path.join(os.getcwdu(), file), email, opts.message)
+
+
+
+
+
# fini!
###############################################################################

< Previous Next >
Follow Ups