Mailinglist Archive: opensuse-buildservice (250 mails)

< Previous Next >
[opensuse-buildservice] RFC: osc vc command
  • From: Michal Vyskocil <mvyskocil@xxxxxxx>
  • Date: Thu, 16 Apr 2009 18:01:14 +0200
  • Message-id: <200904161801.14241.mvyskocil@xxxxxxx>
Hi all,

For non-SUSE folks: vc is an internal command used for editing of .changes
files.

I'm working on implementation of vc command for osc. The current
implementation supports some subset of functionality of it's original.

But currently it can:
- smart detect of .changes to edit
- edit it using default editor
- or add a defaul message using -m

It can work in cwd only (should be implemented later) and not support locking
(not necessary for OBS).

The biggest changes are in header of .changes:

-------------------------------------------------------------------
Thu Apr 16 15:47:06 UTC 2009 - mvyskocil@xxxxxxxxxx

- osc vc test

-------------------------------------------------------------------
Thu Apr 16 16:00:58 CEST 2009 - mvyskocil@xxxxxxx

- vc test

The date is always in UTC, which I considered better than TZ=Europe/Berlin
used in vc, but it's a big change.

Different email is rather cosmetic change, even if it will be nice to have my
nice old @suse.cz back :), I don't know how to fix it.

So any comments and proposals?

Best 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/commandline.py
===================================================================
--- osc/commandline.py (revision 7099)
+++ osc/commandline.py (working copy)
@@ -2695,6 +2695,54 @@
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
+
+ Usage:
+ osc vc [filename[.changes]] [file_with_comment]]
+ If no <filename> is given, exactly one *.changes or
+ *.spec file has to be in the cwd.
+
+ ${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
+ email = get_user_data(conf.config['apiurl'], conf.config['user'],
'email')[0]
+
+ edit_changes(os.path.join(os.getcwdu(), file), email, opts.message)
+
+
+
+
+
# fini!
###############################################################################

< Previous Next >