1 # Copyright (C) 2006 Novell Inc. All rights reserved.
2 # This program is free software; it may be used, copied, modified
3 # and distributed under the terms of the GNU General Public Licence,
4 # either version 2, or version 3 (at your option).
11 import urlgrabber.progress
12 from optparse import SUPPRESS_HELP
14 MAN_HEADER = r""".TH %(ucname)s "1" "%(date)s" "%(name)s %(version)s" "User Commands"
16 %(name)s \- openSUSE build service command-line tool.
19 [\fIGLOBALOPTS\fR] \fISUBCOMMAND \fR[\fIOPTS\fR] [\fIARGS\fR...]
24 openSUSE build service command-line tool.
28 Type 'osc help <subcommand>' for more detailed help on a specific subcommand.
30 For additional information, see
31 * http://en.opensuse.org/Build_Service_Tutorial
32 * http://en.opensuse.org/Build_Service/CLI
34 You can modify osc commands, or roll you own, via the plugin API:
35 * http://en.opensuse.org/Build_Service/osc_plugins
37 osc was written by several authors. This man page is automatically generated.
40 class Osc(cmdln.Cmdln):
41 """Usage: osc [GLOBALOPTS] SUBCOMMAND [OPTS] [ARGS...]
42 or: osc help SUBCOMMAND
44 openSUSE build service command-line tool.
45 Type 'osc help <subcommand>' for help on a specific subcommand.
50 For additional information, see
51 * http://en.opensuse.org/Build_Service_Tutorial
52 * http://en.opensuse.org/Build_Service/CLI
54 You can modify osc commands, or roll you own, via the plugin API:
55 * http://en.opensuse.org/Build_Service/osc_plugins
60 man_header = MAN_HEADER
61 man_footer = MAN_FOOTER
63 def __init__(self, *args, **kwargs):
64 cmdln.Cmdln.__init__(self, *args, **kwargs)
65 cmdln.Cmdln.do_help.aliases.append('h')
67 def get_version(self):
68 return get_osc_version()
70 def get_optparser(self):
71 """this is the parser for "global" options (not specific to subcommand)"""
73 optparser = cmdln.CmdlnOptionParser(self, version=get_osc_version())
74 optparser.add_option('--debugger', action='store_true',
75 help='jump into the debugger before executing anything')
76 optparser.add_option('--post-mortem', action='store_true',
77 help='jump into the debugger in case of errors')
78 optparser.add_option('-t', '--traceback', action='store_true',
79 help='print call trace in case of errors')
80 optparser.add_option('-H', '--http-debug', action='store_true',
81 help='debug HTTP traffic')
82 optparser.add_option('-d', '--debug', action='store_true',
83 help='print info useful for debugging')
84 optparser.add_option('-A', '--apiurl', dest='apiurl',
86 help='specify URL to access API server at or an alias')
87 optparser.add_option('-c', '--config', dest='conffile',
89 help='specify alternate configuration file')
90 optparser.add_option('--no-keyring', action='store_true',
91 help='disable usage of desktop keyring system')
92 optparser.add_option('--no-gnome-keyring', action='store_true',
93 help='disable usage of GNOME Keyring')
94 optparser.add_option('-v', '--verbose', dest='verbose', action='count', default=0,
95 help='increase verbosity')
96 optparser.add_option('-q', '--quiet', dest='verbose', action='store_const', const=-1,
97 help='be quiet, not verbose')
101 def postoptparse(self, try_again = True):
102 """merge commandline options into the config"""
104 conf.get_config(override_conffile = self.options.conffile,
105 override_apiurl = self.options.apiurl,
106 override_debug = self.options.debug,
107 override_http_debug = self.options.http_debug,
108 override_traceback = self.options.traceback,
109 override_post_mortem = self.options.post_mortem,
110 override_no_keyring = self.options.no_keyring,
111 override_no_gnome_keyring = self.options.no_gnome_keyring,
112 override_verbose = self.options.verbose)
113 except oscerr.NoConfigfile, e:
114 print >>sys.stderr, e.msg
115 print >>sys.stderr, 'Creating osc configuration file %s ...' % e.file
118 config['user'] = raw_input('Username: ')
119 config['pass'] = getpass.getpass()
120 if self.options.no_keyring:
121 config['use_keyring'] = '0'
122 if self.options.no_gnome_keyring:
123 config['gnome_keyring'] = '0'
124 if self.options.apiurl:
125 config['apiurl'] = self.options.apiurl
127 conf.write_initial_config(e.file, config)
128 print >>sys.stderr, 'done'
129 if try_again: self.postoptparse(try_again = False)
130 except oscerr.ConfigMissingApiurl, e:
131 print >>sys.stderr, e.msg
133 user = raw_input('Username: ')
134 passwd = getpass.getpass()
135 conf.add_section(e.file, e.url, user, passwd)
136 if try_again: self.postoptparse(try_again = False)
138 self.options.verbose = conf.config['verbose']
139 self.download_progress = None
140 if conf.config.get('show_download_progress', False):
141 from meter import TextMeter
142 self.download_progress = TextMeter()
145 def get_cmd_help(self, cmdname):
146 doc = self._get_cmd_handler(cmdname).__doc__
147 doc = self._help_reindent(doc)
148 doc = self._help_preprocess(doc, cmdname)
149 doc = doc.rstrip() + '\n' # trim down trailing space
150 return self._str(doc)
153 # overridden from class Cmdln() to use config variables in help texts
154 def _help_preprocess(self, help, cmdname):
155 help = cmdln.Cmdln._help_preprocess(self, help, cmdname)
156 return help % conf.config
159 def do_init(self, subcmd, opts, project, package=None):
160 """${cmd_name}: Initialize a directory as working copy
162 Initialize an existing directory to be a working copy of an
163 (already existing) buildservice project/package.
165 (This is the same as checking out a package and then copying sources
166 into the directory. It does NOT create a new package. To create a
167 package, use 'osc meta pkg ... ...')
169 You wouldn't normally use this command.
171 To get a working copy of a package (e.g. for building it or working on
172 it, you would normally use the checkout command. Use "osc help
173 checkout" to get help for it.
182 init_project_dir(conf.config['apiurl'], os.curdir, project)
183 print 'Initializing %s (Project: %s)' % (os.curdir, project)
185 init_package_dir(conf.config['apiurl'], project, package, os.path.curdir)
186 print 'Initializing %s (Project: %s, Package: %s)' % (os.curdir, project, package)
192 @cmdln.option('-a', '--arch', metavar='ARCH',
193 help='specify architecture (only for binaries)')
194 @cmdln.option('-r', '--repo', metavar='REPO',
195 help='specify repository (only for binaries)')
196 @cmdln.option('-b', '--binaries', action='store_true',
197 help='list built binaries instead of sources')
198 @cmdln.option('-R', '--revision', metavar='REVISION',
199 help='specify revision (only for sources)')
200 @cmdln.option('-e', '--expand', action='store_true',
201 help='expand linked package (only for sources)')
202 @cmdln.option('-u', '--unexpand', action='store_true',
203 help='always work with unexpanded (source) packages')
204 @cmdln.option('-v', '--verbose', action='store_true',
205 help='print extra information')
206 @cmdln.option('-l', '--long', action='store_true', dest='verbose',
207 help='print extra information')
208 def do_list(self, subcmd, opts, *args):
209 """${cmd_name}: List sources or binaries on the server
211 Examples for listing sources:
212 ls # list all projects
213 ls PROJECT # list packages in a project
214 ls PROJECT PACKAGE # list source files of package of a project
215 ls PROJECT PACKAGE <file> # list <file> if this file exists
216 ls -v PROJECT PACKAGE # verbosely list source files of package
217 ls -l PROJECT PACKAGE # verbosely list source files of package
218 ll PROJECT PACKAGE # verbosely list source files of package
219 LL PROJECT PACKAGE # verbosely list source files of expanded link
221 With --verbose, the following fields will be shown for each item:
223 Revision number of the last commit
225 Date and time of the last commit
227 Examples for listing binaries:
228 ls -b PROJECT # list all binaries of a project
229 ls -b PROJECT -a ARCH # list ARCH binaries of a project
230 ls -b PROJECT -r REPO # list binaries in REPO
231 ls -b PROJECT PACKAGE REPO ARCH
234 ${cmd_name} [PROJECT [PACKAGE]]
235 ${cmd_name} -b [PROJECT [PACKAGE [REPO [ARCH]]]]
239 apiurl = conf.config['apiurl']
240 args = slash_split(args)
243 if subcmd == 'lL' or subcmd == 'LL':
257 if opts.repo != args[2]:
258 raise oscerr.WrongArgs("conflicting repos specified ('%s' vs '%s')"%(opts.repo, args[2]))
265 if not opts.binaries:
266 raise oscerr.WrongArgs('Too many arguments')
268 if opts.arch != args[3]:
269 raise oscerr.WrongArgs("conflicting archs specified ('%s' vs '%s')"%(opts.arch, args[3]))
274 if opts.binaries and opts.expand:
275 raise oscerr.WrongOptions('Sorry, --binaries and --expand are mutual exclusive.')
279 # ls -b toplevel doesn't make sense, so use info from
280 # current dir if available
283 if is_project_dir(dir):
284 project = store_read_project(dir)
285 apiurl = store_read_apiurl(dir)
286 elif is_package_dir(dir):
287 project = store_read_project(dir)
288 package = store_read_package(dir)
289 apiurl = store_read_apiurl(dir)
292 raise oscerr.WrongArgs('There are no binaries to list above project level.')
294 raise oscerr.WrongOptions('Sorry, the --revision option is not supported for binaries.')
298 if opts.repo and opts.arch:
299 repos.append(Repo(opts.repo, opts.arch))
300 elif opts.repo and not opts.arch:
301 for repo in get_repos_of_project(apiurl, project):
302 if repo.name == opts.repo:
304 elif opts.arch and not opts.repo:
305 for repo in get_repos_of_project(apiurl, project):
306 if repo.arch == opts.arch:
309 repos = get_repos_of_project(apiurl, project)
313 results.append((repo, get_binarylist(apiurl, project, repo.name, repo.arch, package=package, verbose=opts.verbose)))
315 for result in results:
318 print '%s/%s' % (result[0].name, result[0].arch)
323 print "%9d %s %-40s" % (f.size, shorttime(f.mtime), f.name)
329 elif not opts.binaries:
331 print '\n'.join(meta_get_project_list(conf.config['apiurl']))
335 if self.options.verbose:
336 print >>sys.stderr, 'Sorry, the --verbose option is not implemented for projects.'
338 raise oscerr.WrongOptions('Sorry, the --expand option is not implemented for projects.')
340 print '\n'.join(meta_get_packagelist(conf.config['apiurl'], project))
342 elif len(args) == 2 or len(args) == 3:
344 print_not_found = True
346 l = meta_get_filelist(conf.config['apiurl'],
349 verbose=opts.verbose,
351 revision=opts.revision)
354 if i.name == '_link':
356 out = [ '%s %7s %9d %s %s' % (i.md5, i.rev, i.size, shorttime(i.mtime), i.name) \
357 for i in l if not fname or fname == i.name ]
359 print_not_found = False
367 print_not_found = False
370 if opts.expand or opts.unexpand or link_seen == 0: break
371 m = show_files_meta(conf.config['apiurl'], project, package)
372 xml = ET.fromstring(''.join(m)).find('linkinfo')
373 print "# -> %s %s" % (xml.get('project'), xml.get('package'))
375 if fname and print_not_found:
376 print 'file \'%s\' does not exist' % fname
379 @cmdln.option('-f', '--force', action='store_true',
380 help='force generation of new patchinfo file')
381 @cmdln.option('--force-update', action='store_true',
382 help='drops away collected packages from an already built patch and let it collect again')
383 def do_patchinfo(self, subcmd, opts, *args):
384 """${cmd_name}: Generate and edit a patchinfo file.
386 A patchinfo file describes the packages for an update and the kind of
391 osc patchinfo PATCH_NAME
395 project_dir = localdir = os.getcwd()
396 if is_project_dir(localdir):
397 project = store_read_project(localdir)
398 apiurl = store_read_apiurl(localdir)
400 sys.exit('This command must be called in a checked out project.')
402 for p in meta_get_packagelist(apiurl, project):
403 if p.startswith("_patchinfo:"):
406 if opts.force or not patchinfo:
407 print "Creating initial patchinfo..."
408 query='cmd=createpatchinfo'
410 query += "&name=" + args[0]
411 url = makeurl(apiurl, ['source', project], query=query)
413 for p in meta_get_packagelist(apiurl, project):
414 if p.startswith("_patchinfo:"):
417 if not os.path.exists(project_dir + "/" + patchinfo):
418 checkout_package(apiurl, project, patchinfo, prj_dir=project_dir)
420 if sys.platform[:3] != 'win':
421 editor = os.getenv('EDITOR', default='vim')
423 editor = os.getenv('EDITOR', default='notepad')
424 subprocess.call('%s %s' % (editor, project_dir + "/" + patchinfo + "/_patchinfo"), shell=True)
427 @cmdln.option('-a', '--attribute', metavar='ATTRIBUTE',
428 help='affect only a given attribute')
429 @cmdln.option('--attribute-defaults', action='store_true',
430 help='include defined attribute defaults')
431 @cmdln.option('--attribute-project', action='store_true',
432 help='include project values, if missing in packages ')
433 @cmdln.option('-F', '--file', metavar='FILE',
434 help='read metadata from FILE, instead of opening an editor. '
435 '\'-\' denotes standard input. ')
436 @cmdln.option('-e', '--edit', action='store_true',
437 help='edit metadata')
438 @cmdln.option('-c', '--create', action='store_true',
439 help='create attribute without values')
440 @cmdln.option('-s', '--set', metavar='ATTRIBUTE_VALUES',
441 help='set attribute values')
442 @cmdln.option('--delete', action='store_true',
443 help='delete a pattern or attribute')
444 def do_meta(self, subcmd, opts, *args):
445 """${cmd_name}: Show meta information, or edit it
447 Show or edit build service metadata of type <prj|pkg|prjconf|user|pattern>.
449 This command displays metadata on buildservice objects like projects,
450 packages, or users. The type of metadata is specified by the word after
451 "meta", like e.g. "meta prj".
453 prj denotes metadata of a buildservice project.
454 prjconf denotes the (build) configuration of a project.
455 pkg denotes metadata of a buildservice package.
456 user denotes the metadata of a user.
457 pattern denotes installation patterns defined for a project.
459 To list patterns, use 'osc meta pattern PRJ'. An additional argument
460 will be the pattern file to view or edit.
462 With the --edit switch, the metadata can be edited. Per default, osc
463 opens the program specified by the environmental variable EDITOR with a
464 temporary file. Alternatively, content to be saved can be supplied via
465 the --file switch. If the argument is '-', input is taken from stdin:
466 osc meta prjconf home:user | sed ... | osc meta prjconf home:user -F -
468 When trying to edit a non-existing resource, it is created implicitly.
474 osc meta pkg PRJ PKG -e
475 osc meta attribute PRJ [PKG [SUBPACKAGE]] [--attribute ATTRIBUTE] [--create|--delete|--set [value_list]]
478 osc meta <prj|pkg|prjconf|user|pattern|attribute> ARGS...
479 osc meta <prj|pkg|prjconf|user|pattern|attribute> -e|--edit ARGS...
480 osc meta <prj|pkg|prjconf|user|pattern|attribute> -F|--file ARGS...
481 osc meta pattern --delete PRJ PATTERN
485 args = slash_split(args)
487 if not args or args[0] not in metatypes.keys():
488 raise oscerr.WrongArgs('Unknown meta type. Choose one of %s.' \
489 % ', '.join(metatypes))
495 min_args, max_args = 2, 2
496 elif cmd in ['pattern']:
497 min_args, max_args = 1, 2
498 elif cmd in ['attribute']:
499 min_args, max_args = 1, 3
501 min_args, max_args = 1, 1
502 if len(args) < min_args:
503 raise oscerr.WrongArgs('Too few arguments.')
504 if len(args) > max_args:
505 raise oscerr.WrongArgs('Too many arguments.')
512 project, package = args[0:2]
513 elif cmd == 'attribute':
519 if opts.attribute_project:
520 raise oscerr.WrongOptions('--attribute-project works only when also a package is given')
525 attributepath.append('source')
526 attributepath.append(project)
528 attributepath.append(package)
530 attributepath.append(subpackage)
531 attributepath.append('_attribute')
532 elif cmd == 'prjconf':
536 elif cmd == 'pattern':
542 # enforce pattern argument if needed
543 if opts.edit or opts.file:
544 raise oscerr.WrongArgs('A pattern file argument is required.')
547 if not opts.edit and not opts.file and not opts.delete and not opts.create and not opts.set:
549 sys.stdout.write(''.join(show_project_meta(conf.config['apiurl'], project)))
551 sys.stdout.write(''.join(show_package_meta(conf.config['apiurl'], project, package)))
552 elif cmd == 'attribute':
553 sys.stdout.write(''.join(show_attribute_meta(conf.config['apiurl'], project, package, subpackage, opts.attribute, opts.attribute_defaults, opts.attribute_project)))
554 elif cmd == 'prjconf':
555 sys.stdout.write(''.join(show_project_conf(conf.config['apiurl'], project)))
557 r = get_user_meta(conf.config['apiurl'], user)
559 sys.stdout.write(''.join(r))
560 elif cmd == 'pattern':
562 r = show_pattern_meta(conf.config['apiurl'], project, pattern)
564 sys.stdout.write(''.join(r))
566 r = show_pattern_metalist(conf.config['apiurl'], project)
568 sys.stdout.write('\n'.join(r) + '\n')
571 if opts.edit and not opts.file:
573 edit_meta(metatype='prj',
575 path_args=quote_plus(project),
578 'user': conf.config['user']}))
580 edit_meta(metatype='pkg',
582 path_args=(quote_plus(project), quote_plus(package)),
585 'user': conf.config['user']}))
586 elif cmd == 'prjconf':
587 edit_meta(metatype='prjconf',
589 path_args=quote_plus(project),
592 edit_meta(metatype='user',
594 path_args=(quote_plus(user)),
595 template_args=({'user': user}))
596 elif cmd == 'pattern':
597 edit_meta(metatype='pattern',
599 path_args=(project, pattern),
602 # create attribute entry
603 if (opts.create or opts.set) and cmd == 'attribute':
604 if not opts.attribute:
605 raise oscerr.WrongOptions('no attribute given to create')
608 opts.set = opts.set.replace('&', '&').replace('<', '<').replace('>', '>')
609 for i in opts.set.split(','):
610 values += '<value>%s</value>' % i
611 aname = opts.attribute.split(":")
612 d = '<attributes><attribute namespace=\'%s\' name=\'%s\' >%s</attribute></attributes>' % (aname[0], aname[1], values)
613 url = makeurl(conf.config['apiurl'], attributepath)
614 for data in streamfile(url, http_POST, data=d):
615 sys.stdout.write(data)
624 f = open(opts.file).read()
626 sys.exit('could not open file \'%s\'.' % opts.file)
629 edit_meta(metatype='prj',
632 path_args=quote_plus(project))
634 edit_meta(metatype='pkg',
637 path_args=(quote_plus(project), quote_plus(package)))
638 elif cmd == 'prjconf':
639 edit_meta(metatype='prjconf',
642 path_args=quote_plus(project))
644 edit_meta(metatype='user',
647 path_args=(quote_plus(user)))
648 elif cmd == 'pattern':
649 edit_meta(metatype='pattern',
652 path_args=(project, pattern))
657 path = metatypes[cmd]['path']
659 path = path % (project, pattern)
660 u = makeurl(conf.config['apiurl'], [path])
662 elif cmd == 'attribute':
663 if not opts.attribute:
664 raise oscerr.WrongOptions('no attribute given to create')
665 attributepath.append(opts.attribute)
666 u = makeurl(conf.config['apiurl'], attributepath)
667 for data in streamfile(u, http_DELETE):
668 sys.stdout.write(data)
670 raise oscerr.WrongOptions('The --delete switch is only for pattern metadata or attributes.')
673 @cmdln.option('-m', '--message', metavar='TEXT',
674 help='specify message TEXT')
675 @cmdln.option('-r', '--revision', metavar='REV',
676 help='for "create", specify a certain source revision ID (the md5 sum)')
677 @cmdln.option('-s', '--supersede', metavar='SUPERSEDE',
678 help='Superseding another request by this one')
679 @cmdln.option('--nodevelproject', action='store_true',
680 help='do not follow a defined devel project ' \
681 '(primary project where a package is developed)')
682 @cmdln.option('--cleanup', action='store_true',
683 help='remove package if submission gets accepted (default for home:<id>:branch projects)')
684 @cmdln.option('--no-cleanup', action='store_true',
685 help='never remove source package on accept, but update its content')
686 @cmdln.option('--no-update', action='store_true',
687 help='never touch source package on accept (will break source links)')
688 @cmdln.option('-d', '--diff', action='store_true',
689 help='show diff only instead of creating the actual request')
690 @cmdln.option('--yes', action='store_true',
691 help='proceed without asking.')
693 @cmdln.alias("submitreq")
694 @cmdln.alias("submitpac")
695 def do_submitrequest(self, subcmd, opts, *args):
696 """${cmd_name}: Create request to submit source into another Project
698 [See http://en.opensuse.org/Build_Service/Collaboration for information
701 See the "request" command for showing and modifing existing requests.
704 osc submitreq [OPTIONS]
705 osc submitreq [OPTIONS] DESTPRJ [DESTPKG]
706 osc submitreq [OPTIONS] SOURCEPRJ SOURCEPKG DESTPRJ [DESTPKG]
710 src_update = conf.config['submitrequest_on_accept_action'] or None
711 # we should check here for home:<id>:branch and default to update, but that would require OBS 1.7 server
713 src_update = "cleanup"
714 elif opts.no_cleanup:
715 src_update = "update"
717 src_update = "noupdate"
719 args = slash_split(args)
721 # remove this block later again
722 oldcmds = ['create', 'list', 'log', 'show', 'decline', 'accept', 'delete', 'revoke']
723 if args and args[0] in oldcmds:
724 print "************************************************************************"
725 print "* WARNING: It looks that you are using this command with a *"
726 print "* deprecated syntax. *"
727 print "* Please run \"osc sr --help\" and \"osc rq --help\" *"
728 print "* to see the new syntax. *"
729 print "************************************************************************"
730 if args[0] == 'create':
736 raise oscerr.WrongArgs('Too many arguments.')
738 if len(args) > 0 and len(args) <= 2 and is_project_dir(os.getcwd()):
739 sys.exit('osc submitrequest from project directory is only working without target specs and for source linked files\n')
741 apiurl = conf.config['apiurl']
743 if len(args) == 0 and is_project_dir(os.getcwd()):
745 # submit requests for multiple packages are currently handled via multiple requests
746 # They could be also one request with multiple actions, but that avoids to accepts parts of it.
747 project = store_read_project(os.curdir)
748 apiurl = store_read_apiurl(os.curdir)
754 # loop via all packages for checking their state
755 for p in meta_get_packagelist(apiurl, project):
756 if p.startswith("_patchinfo:"):
759 # get _link info from server, that knows about the local state ...
760 u = makeurl(apiurl, ['source', project, p])
762 root = ET.parse(f).getroot()
763 linkinfo = root.find('linkinfo')
765 print "Package ", p, " is not a source link."
766 sys.exit("This is currently not supported.")
767 if linkinfo.get('error'):
768 print "Package ", p, " is a broken source link."
769 sys.exit("Please fix this first")
770 t = linkinfo.get('project')
772 if len(root.findall('entry')) > 1: # This is not really correct, but should work mostly
773 # Real fix is to ask the api if sources are modificated
774 # but there is no such call yet.
775 targetprojects.append(t)
777 print "Submitting package ", p
779 print " Skipping package ", p
781 print "Skipping package ", p, " since it is a source link pointing inside the project."
785 print "Submitting patchinfo ", ', '.join(pi), " to ", ', '.join(targetprojects)
786 print "\nEverything fine? Can we create the requests ? [y/n]"
787 if sys.stdin.read(1) != "y":
788 sys.exit("Aborted...")
790 # loop via all packages to do the action
792 result = create_submit_request(apiurl, project, p)
795 sys.exit("submit request creation failed")
796 sr_ids.append(result)
798 # create submit requests for all found patchinfos
802 options_block="""<options><sourceupdate>%s</sourceupdate></options> """ % (src_update)
805 for t in targetprojects:
806 s = """<action type="submit"> <source project="%s" package="%s" /> <target project="%s" package="%s" /> %s </action>""" % \
807 (project, p, t, p, options_block)
811 xml = """<request> %s <state name="new"/> <description>%s</description> </request> """ % \
812 (actionxml, cgi.escape(opts.message or ""))
813 u = makeurl(apiurl, ['request'], query='cmd=create')
814 f = http_POST(u, data=xml)
816 root = ET.parse(f).getroot()
817 sr_ids.append(root.get('id'))
819 print "Requests created: ",
822 sys.exit('Successfull finished')
825 # try using the working copy at hand
826 p = findpacs(os.curdir)[0]
827 src_project = p.prjname
830 if len(args) == 0 and p.islink():
831 dst_project = p.linkinfo.project
832 dst_package = p.linkinfo.package
834 dst_project = args[0]
836 dst_package = args[1]
838 dst_package = src_package
840 sys.exit('Package \'%s\' is not a source link, so I cannot guess the submit target.\n'
841 'Please provide it the target via commandline arguments.' % p.name)
843 modified = [i for i in p.filenamelist if p.status(i) != ' ' and p.status(i) != '?']
844 if len(modified) > 0:
845 print 'Your working copy has local modifications.'
846 repl = raw_input('Proceed without committing the local changes? (y|N) ')
850 # get the arguments from the commandline
851 src_project, src_package, dst_project = args[0:3]
853 dst_package = args[3]
855 dst_package = src_package
857 raise oscerr.WrongArgs('Incorrect number of arguments.\n\n' \
858 + self.get_cmd_help('request'))
860 if not opts.nodevelproject:
863 devloc = show_develproject(apiurl, dst_project, dst_package)
864 except urllib2.HTTPError:
865 print >>sys.stderr, """\
866 Warning: failed to fetch meta data for '%s' package '%s' (new package?) """ \
867 % (dst_project, dst_package)
871 dst_project != devloc and \
872 src_project != devloc:
874 A different project, %s, is defined as the place where development
875 of the package %s primarily takes place.
876 Please submit there instead, or use --nodevelproject to force direct submission.""" \
877 % (devloc, dst_package)
882 if opts.diff or not opts.message:
884 rdiff = 'old: %s/%s\nnew: %s/%s' %(dst_project, dst_package, src_project, src_package)
885 rdiff += server_diff(apiurl,
886 dst_project, dst_package, opts.revision,
887 src_project, src_package, None, True)
893 reqs = get_request_list(apiurl, dst_project, dst_package, req_type='submit')
894 user = conf.get_apiurl_usr(apiurl)
895 myreqs = [ i for i in reqs if i.state.who == user ]
898 print 'You already created the following submit request: %s.' % \
899 ', '.join([str(i.reqid) for i in myreqs ])
900 repl = raw_input('Supersede the old requests? (y/n/c) ')
901 if repl.lower() == 'c':
902 print >>sys.stderr, 'Aborting'
908 changes_re = re.compile(r'^--- .*\.changes ')
909 for line in rdiff.split('\n'):
910 if line.startswith('--- '):
911 if changes_re.match(line):
916 difflines.append(line)
917 opts.message = edit_message(footer=rdiff, template='\n'.join(parse_diff_for_commit_message('\n'.join(difflines))))
919 result = create_submit_request(apiurl,
920 src_project, src_package,
921 dst_project, dst_package,
922 opts.message, orev=opts.revision, src_update=src_update)
923 if repl.lower() == 'y':
925 change_request_state(apiurl, str(req.reqid), 'superseded',
926 'superseded by %s' % result, result)
929 r = change_request_state(conf.config['apiurl'],
930 opts.supersede, 'superseded', opts.message or '', result)
932 print 'created request id', result
935 @cmdln.option('-m', '--message', metavar='TEXT',
936 help='specify message TEXT')
938 @cmdln.alias("deletereq")
939 def do_deleterequest(self, subcmd, opts, *args):
940 """${cmd_name}: Create request to delete a package or project
944 osc deletereq [-m TEXT] PROJECT [PACKAGE]
948 args = slash_split(args)
951 raise oscerr.WrongArgs('Please specify at least a project.')
953 raise oscerr.WrongArgs('Too many arguments.')
955 apiurl = conf.config['apiurl']
963 opts.message = edit_message()
965 result = create_delete_request(apiurl, project, package, opts.message)
969 @cmdln.option('-m', '--message', metavar='TEXT',
970 help='specify message TEXT')
972 @cmdln.alias("changedevelreq")
973 def do_changedevelrequest(self, subcmd, opts, *args):
974 """${cmd_name}: Create request to change the devel package definition.
976 [See http://en.opensuse.org/Build_Service/Collaboration for information
979 See the "request" command for showing and modifing existing requests.
981 osc changedevelrequest PROJECT PACKAGE DEVEL_PROJECT [DEVEL_PACKAGE]
985 raise oscerr.WrongArgs('Too many arguments.')
987 if len(args) == 0 and is_package_dir('.') and len(conf.config['getpac_default_project']):
989 devel_project = store_read_project(wd)
990 devel_package = package = store_read_package(wd)
991 apiurl = store_read_apiurl(wd)
992 project = conf.config['getpac_default_project']
995 raise oscerr.WrongArgs('Too few arguments.')
997 apiurl = conf.config['apiurl']
999 devel_project = args[2]
1002 devel_package = package
1004 devel_package = args[3]
1006 if not opts.message:
1008 footer=textwrap.TextWrapper(width = 66).fill(
1009 'please explain why you like to change the devel project of %s/%s to %s/%s'
1010 % (project,package,devel_project,devel_package))
1011 opts.message = edit_message(footer)
1013 result = create_change_devel_request(apiurl,
1014 devel_project, devel_package,
1020 @cmdln.option('-d', '--diff', action='store_true',
1021 help='generate a diff')
1022 @cmdln.option('-u', '--unified', action='store_true',
1023 help='output the diff in the unified diff format')
1024 @cmdln.option('-m', '--message', metavar='TEXT',
1025 help='specify message TEXT')
1026 @cmdln.option('-t', '--type', metavar='TYPE',
1027 help='limit to requests which contain a given action type (submit/delete/change_devel)')
1028 @cmdln.option('-a', '--all', action='store_true',
1029 help='all states. Same as\'-s all\'')
1030 @cmdln.option('-s', '--state', default='', # default is 'all' if no args given, 'new' otherwise
1031 help='only list requests in one of the comma separated given states (new/accepted/revoked/declined) or "all" [default=new, or all, if no args given]')
1032 @cmdln.option('-D', '--days', metavar='DAYS',
1033 help='only list requests in state "new" or changed in the last DAYS. [default=%(request_list_days)s]')
1034 @cmdln.option('-U', '--user', metavar='USER',
1035 help='same as -M, but for the specified USER')
1036 @cmdln.option('-b', '--brief', action='store_true', default=False,
1037 help='print output in list view as list subcommand')
1038 @cmdln.option('-M', '--mine', action='store_true',
1039 help='only show requests created by yourself')
1040 @cmdln.option('-B', '--bugowner', action='store_true',
1041 help='also show requests about packages where I am bugowner')
1042 @cmdln.option('-i', '--interactive', action='store_true',
1043 help='interactive review of request')
1044 @cmdln.option('--exclude-target-project', action='append',
1045 help='exclude target project from request list')
1046 @cmdln.option('--involved-projects', action='store_true',
1047 help='show all requests for project/packages where USER is involved in')
1049 @cmdln.alias("review")
1050 def do_request(self, subcmd, opts, *args):
1051 """${cmd_name}: Show and modify requests
1053 [See http://en.opensuse.org/Build_Service/Collaboration for information
1056 This command shows and modifies existing requests. To create new requests
1057 you need to call one of the following:
1060 osc changedevelrequest
1061 To send low level requests to the buildservice API, use:
1064 This command has the following sub commands:
1066 "list" lists open requests attached to a project or package or person.
1067 Uses the project/package of the current directory if none of
1068 -M, -U USER, project/package are given.
1070 "log" will show the history of the given ID
1072 "show" will show the request itself, and generate a diff for review, if
1073 used with the --diff option. The keyword show can be omitted if the ID is numeric.
1075 "decline" will change the request state to "declined" and append a
1076 message that you specify with the --message option.
1078 "wipe" will permanently delete a request.
1080 "revoke" will set the request state to "revoked" and append a
1081 message that you specify with the --message option.
1083 "accept" will change the request state to "accepted" and will trigger
1084 the actual submit process. That would normally be a server-side copy of
1085 the source package to the target package.
1087 "checkout" will checkout the request's source package. This only works for "submit" requests.
1090 osc request list [-M] [-U USER] [-s state] [-D DAYS] [-t type] [-B] [PRJ [PKG]]
1092 osc request [show] [-d] [-b] ID
1093 osc request accept [-m TEXT] ID
1094 osc request decline [-m TEXT] ID
1095 osc request revoke [-m TEXT] ID
1097 osc request checkout/co ID
1098 osc review accept [-m TEXT] ID
1099 osc review decline [-m TEXT] ID
1103 args = slash_split(args)
1105 if opts.all and opts.state:
1106 raise oscerr.WrongOptions('Sorry, the options --all and --state ' \
1107 'are mutually exclusive.')
1108 if opts.mine and opts.user:
1109 raise oscerr.WrongOptions('Sorry, the options --user and --mine ' \
1110 'are mutually exclusive.')
1115 if opts.state == '':
1118 if opts.state == '':
1121 cmds = ['list', 'log', 'show', 'decline', 'accept', 'wipe', 'revoke', 'checkout', 'co', 'help']
1122 if not args or args[0] not in cmds:
1123 raise oscerr.WrongArgs('Unknown request action %s. Choose one of %s.' \
1124 % (args[0],', '.join(cmds)))
1130 return self.do_help(['help', 'request'])
1133 min_args, max_args = 1, 1
1134 elif cmd in ['list']:
1135 min_args, max_args = 0, 2
1137 min_args, max_args = 1, 1
1138 if len(args) < min_args:
1139 raise oscerr.WrongArgs('Too few arguments.')
1140 if len(args) > max_args:
1141 raise oscerr.WrongArgs('Too many arguments.')
1143 apiurl = conf.config['apiurl']
1150 elif not opts.mine and not opts.user:
1152 project = store_read_project(os.curdir)
1153 apiurl = store_read_apiurl(os.curdir)
1154 package = store_read_package(os.curdir)
1155 except oscerr.NoWorkingCopy:
1160 elif cmd in ['log', 'show', 'decline', 'accept', 'wipe', 'revoke', 'checkout', 'co']:
1165 states = ('new', 'accepted', 'revoked', 'declined')
1166 state_list = opts.state.split(',')
1167 if opts.state == 'all':
1168 state_list = ['all']
1170 for s in state_list:
1172 raise oscerr.WrongArgs('Unknown state \'%s\', try one of %s' % (s, ','.join(states)))
1175 who = conf.get_apiurl_usr(apiurl)
1179 state_list = ['all']
1181 ## FIXME -B not implemented!
1183 if (self.options.debug):
1184 print 'list: option --bugowner ignored: not impl.'
1186 if opts.involved_projects:
1187 who = who or conf.get_apiurl_usr(apiurl)
1188 results = get_user_projpkgs_request_list(apiurl, who, req_state=state_list,
1189 req_type=opts.type, exclude_projects=opts.exclude_target_project or [])
1191 results = get_request_list(apiurl, project, package, who,
1192 state_list, opts.type, opts.exclude_target_project or [])
1193 results.sort(reverse=True)
1195 days = opts.days or conf.config['request_list_days']
1202 since = time.strftime('%Y-%m-%dT%H:%M:%S',time.localtime(time.time()-days*24*3600))
1205 ## bs has received 2009-09-20 a new xquery compare() function
1206 ## which allows us to limit the list inside of get_request_list
1207 ## That would be much faster for coolo. But counting the remainder
1208 ## would not be possible with current xquery implementation.
1209 ## Workaround: fetch all, and filter on client side.
1211 ## FIXME: date filtering should become implemented on server side
1212 for result in results:
1213 if days == 0 or result.state.when > since or result.state.name == 'new':
1214 print result.list_view()
1218 print "There are %d requests older than %s days.\n" % (skipped, days)
1221 for l in get_request_log(conf.config['apiurl'], reqid):
1226 r = get_request(conf.config['apiurl'], reqid)
1229 elif opts.interactive or conf.config['request_show_interactive']:
1230 return request_interactive_review(conf.config['apiurl'], r)
1233 # fixme: will inevitably fail if the given target doesn't exist
1236 print server_diff(conf.config['apiurl'],
1237 r.actions[0].dst_project, r.actions[0].dst_package, None,
1238 r.actions[0].src_project, r.actions[0].src_package, r.actions[0].src_rev, opts.unified)
1239 except urllib2.HTTPError, e:
1240 e.osc_msg = 'Diff not possible'
1244 elif cmd == 'checkout' or cmd == 'co':
1245 r = get_request(conf.config['apiurl'], reqid)
1246 submits = [ i for i in r.actions if i.type == 'submit' ]
1247 if not len(submits):
1248 raise oscerr.WrongArgs('\'checkout\' only works for \'submit\' requests')
1249 checkout_package(conf.config['apiurl'], submits[0].src_project, submits[0].src_package, \
1250 submits[0].src_rev, expand_link=True, prj_dir=submits[0].src_project)
1253 if not opts.message:
1254 opts.message = edit_message()
1255 state_map = {'accept' : 'accepted', 'decline' : 'declined', 'wipe' : 'deleted', 'revoke' : 'revoked'}
1256 # Change review state only
1257 if subcmd == 'review':
1258 if cmd in ['accept', 'decline']:
1259 r = change_review_state(conf.config['apiurl'],
1260 reqid, state_map[cmd], conf.config['user'], '', opts.message or '')
1262 # Change state of entire request
1263 elif cmd in ['accept', 'decline', 'wipe', 'revoke']:
1264 r = change_request_state(conf.config['apiurl'],
1265 reqid, state_map[cmd], opts.message or '')
1268 # editmeta and its aliases are all depracated
1269 @cmdln.alias("editprj")
1270 @cmdln.alias("createprj")
1271 @cmdln.alias("editpac")
1272 @cmdln.alias("createpac")
1273 @cmdln.alias("edituser")
1274 @cmdln.alias("usermeta")
1276 def do_editmeta(self, subcmd, opts, *args):
1279 Obsolete command to edit metadata. Use 'meta' now.
1281 See the help output of 'meta'.
1285 print >>sys.stderr, 'This command is obsolete. Use \'osc meta <metatype> ...\'.'
1286 print >>sys.stderr, 'See \'osc help meta\'.'
1287 #self.do_help([None, 'meta'])
1291 @cmdln.option('-r', '--revision', metavar='rev',
1292 help='use the specified revision.')
1293 @cmdln.option('-u', '--unset', action='store_true',
1294 help='remove revision in link, it will point always to latest revision')
1295 def do_setlinkrev(self, subcmd, opts, *args):
1296 """${cmd_name}: Updates a revision number in a source link.
1298 This command adds or updates a specified revision number in a source link.
1299 The current revision of the source is used, if no revision number is specified.
1303 osc setlinkrev PROJECT [PACKAGE]
1307 args = slash_split(args)
1308 apiurl = conf.config['apiurl']
1311 p = findpacs(os.curdir)[0]
1316 sys.exit('Local directory is no checked out source link package, aborting')
1317 elif len(args) == 2:
1320 elif len(args) == 1:
1323 raise oscerr.WrongArgs('Incorrect number of arguments.\n\n' \
1324 + self.get_cmd_help('setlinkrev'))
1327 packages = [ package ]
1329 packages = meta_get_packagelist(apiurl, project)
1332 print "setting revision for package", p
1336 rev, dummy = parseRevisionOption(opts.revision)
1337 set_link_rev(apiurl, project, p, rev)
1340 def do_linktobranch(self, subcmd, opts, *args):
1341 """${cmd_name}: Convert a package containing a classic link with patch to a branch
1343 This command tells the server to convert a _link with or without a project.diff
1344 to a branch. This is a full copy with a _link file pointing to the branched place.
1347 osc linktobranch # can be used in checked out package
1348 osc linktobranch PROJECT PACKAGE
1352 args = slash_split(args)
1355 project = store_read_project(wd)
1356 package = store_read_package(wd)
1357 apiurl = store_read_apiurl(wd)
1358 update_local_dir = True
1360 raise oscerr.WrongArgs('Too few arguments (required none or two)')
1362 raise oscerr.WrongArgs('Too many arguments (required none or two)')
1364 apiurl = conf.config['apiurl']
1367 update_local_dir = False
1370 link_to_branch(apiurl, project, package)
1371 if update_local_dir:
1373 pac.update(rev=pac.latest_rev())
1376 @cmdln.option('-C', '--cicount', choices=['add', 'copy', 'local'],
1377 help='cicount attribute in the link, known values are add, copy, and local, default in buildservice is currently add.')
1378 @cmdln.option('-c', '--current', action='store_true',
1379 help='link fixed against current revision.')
1380 @cmdln.option('-r', '--revision', metavar='rev',
1381 help='link the specified revision.')
1382 @cmdln.option('-f', '--force', action='store_true',
1383 help='overwrite an existing link file if it is there.')
1384 @cmdln.option('-d', '--disable-publish', action='store_true',
1385 help='disable publishing of the linked package')
1386 def do_linkpac(self, subcmd, opts, *args):
1387 """${cmd_name}: "Link" a package to another package
1389 A linked package is a clone of another package, but plus local
1390 modifications. It can be cross-project.
1392 The DESTPAC name is optional; the source packages' name will be used if
1395 Afterwards, you will want to 'checkout DESTPRJ DESTPAC'.
1397 To add a patch, add the patch as file and add it to the _link file.
1398 You can also specify text which will be inserted at the top of the spec file.
1400 See the examples in the _link file.
1403 osc linkpac SOURCEPRJ SOURCEPAC DESTPRJ [DESTPAC]
1407 args = slash_split(args)
1409 if not args or len(args) < 3:
1410 raise oscerr.WrongArgs('Incorrect number of arguments.\n\n' \
1411 + self.get_cmd_help('linkpac'))
1413 rev, dummy = parseRevisionOption(opts.revision)
1415 src_project = args[0]
1416 src_package = args[1]
1417 dst_project = args[2]
1419 dst_package = args[3]
1421 dst_package = src_package
1423 if src_project == dst_project and src_package == dst_package:
1424 raise oscerr.WrongArgs('Error: source and destination are the same.')
1426 if src_project == dst_project and not opts.cicount:
1427 # in this case, the user usually wants to build different spec
1428 # files from the same source
1429 opts.cicount = "copy"
1432 rev = show_upstream_rev(conf.config['apiurl'], src_project, src_package)
1434 if rev and not checkRevision(src_project, src_package, rev):
1435 print >>sys.stderr, 'Revision \'%s\' does not exist' % rev
1438 link_pac(src_project, src_package, dst_project, dst_package, opts.force, rev, opts.cicount, opts.disable_publish)
1440 @cmdln.option('-m', '--map-repo', metavar='SRC=TARGET[,SRC=TARGET]',
1441 help='Allows repository mapping(s) to be given as SRC=TARGET[,SRC=TARGET]')
1442 @cmdln.option('-d', '--disable-publish', action='store_true',
1443 help='disable publishing of the aggregated package')
1444 def do_aggregatepac(self, subcmd, opts, *args):
1445 """${cmd_name}: "Aggregate" a package to another package
1447 Aggregation of a package means that the build results (binaries) of a
1448 package are basically copied into another project.
1449 This can be used to make packages available from building that are
1450 needed in a project but available only in a different project. Note
1451 that this is done at the expense of disk space. See
1452 http://en.opensuse.org/Build_Service/Tips_and_Tricks#_link_and__aggregate
1453 for more information.
1455 The DESTPAC name is optional; the source packages' name will be used if
1459 osc aggregatepac SOURCEPRJ SOURCEPAC DESTPRJ [DESTPAC]
1463 args = slash_split(args)
1465 if not args or len(args) < 3:
1466 raise oscerr.WrongArgs('Incorrect number of arguments.\n\n' \
1467 + self.get_cmd_help('aggregatepac'))
1469 src_project = args[0]
1470 src_package = args[1]
1471 dst_project = args[2]
1473 dst_package = args[3]
1475 dst_package = src_package
1477 if src_project == dst_project and src_package == dst_package:
1478 raise oscerr.WrongArgs('Error: source and destination are the same.')
1482 for pair in opts.map_repo.split(','):
1483 src_tgt = pair.split('=')
1484 if len(src_tgt) != 2:
1485 raise oscerr.WrongOptions('map "%s" must be SRC=TARGET[,SRC=TARGET]' % opts.map_repo)
1486 repo_map[src_tgt[0]] = src_tgt[1]
1488 aggregate_pac(src_project, src_package, dst_project, dst_package, repo_map, opts.disable_publish)
1491 @cmdln.option('-c', '--client-side-copy', action='store_true',
1492 help='do a (slower) client-side copy')
1493 @cmdln.option('-k', '--keep-maintainers', action='store_true',
1494 help='keep original maintainers. Default is remove all and replace with the one calling the script.')
1495 @cmdln.option('-d', '--keep-develproject', action='store_true',
1496 help='keep develproject tag in the package metadata')
1497 @cmdln.option('-r', '--revision', metavar='rev',
1498 help='link the specified revision.')
1499 @cmdln.option('-t', '--to-apiurl', metavar='URL',
1500 help='URL of destination api server. Default is the source api server.')
1501 @cmdln.option('-m', '--message', metavar='TEXT',
1502 help='specify message TEXT')
1503 @cmdln.option('-e', '--expand', action='store_true',
1504 help='if the source package is a link then copy the expanded version of the link')
1505 def do_copypac(self, subcmd, opts, *args):
1506 """${cmd_name}: Copy a package
1508 A way to copy package to somewhere else.
1510 It can be done across buildservice instances, if the -t option is used.
1511 In that case, a client-side copy is implied.
1513 Using --client-side-copy always involves downloading all files, and
1514 uploading them to the target.
1516 The DESTPAC name is optional; the source packages' name will be used if
1520 osc copypac SOURCEPRJ SOURCEPAC DESTPRJ [DESTPAC]
1524 args = slash_split(args)
1526 if not args or len(args) < 3:
1527 raise oscerr.WrongArgs('Incorrect number of arguments.\n\n' \
1528 + self.get_cmd_help('copypac'))
1530 src_project = args[0]
1531 src_package = args[1]
1532 dst_project = args[2]
1534 dst_package = args[3]
1536 dst_package = src_package
1538 src_apiurl = conf.config['apiurl']
1540 dst_apiurl = conf.config['apiurl_aliases'].get(opts.to_apiurl, opts.to_apiurl)
1542 dst_apiurl = src_apiurl
1544 if src_project == dst_project and \
1545 src_package == dst_package and \
1546 src_apiurl == dst_apiurl:
1547 raise oscerr.WrongArgs('Source and destination are the same.')
1549 if src_apiurl != dst_apiurl:
1550 opts.client_side_copy = True
1552 rev, dummy = parseRevisionOption(opts.revision)
1555 comment = opts.message
1558 rev = show_upstream_rev(src_apiurl, src_project, src_package)
1559 comment = 'osc copypac from project:%s package:%s revision:%s' % ( src_project, src_package, rev )
1561 r = copy_pac(src_apiurl, src_project, src_package,
1562 dst_apiurl, dst_project, dst_package,
1563 client_side_copy=opts.client_side_copy,
1564 keep_maintainers=opts.keep_maintainers,
1565 keep_develproject=opts.keep_develproject,
1572 @cmdln.option('-c', '--checkout', action='store_true',
1573 help='Checkout branched package afterwards ' \
1574 '(\'osc bco\' is a shorthand for this option)' )
1575 @cmdln.option('-a', '--attribute', metavar='ATTRIBUTE',
1576 help='Use this attribute to find affected packages (default is OBS:Maintained)')
1577 @cmdln.option('-u', '--update-project-attribute', metavar='UPDATE_ATTRIBUTE',
1578 help='Use this attribute to find update projects (default is OBS:UpdateProject) ')
1579 def do_mbranch(self, subcmd, opts, *args):
1580 """${cmd_name}: Multiple branch of a package
1582 [See http://en.opensuse.org/Build_Service/Concepts/Maintenance for information
1585 This command is used for creating multiple links of defined version of a package
1586 in one project. This is esp. used for maintenance updates.
1588 The branched package will live in
1589 home:USERNAME:branches:ATTRIBUTE:PACKAGE
1590 if nothing else specified.
1593 osc mbranch [ SOURCEPACKAGE [ TARGETPROJECT ] ]
1596 args = slash_split(args)
1599 maintained_attribute = conf.config['maintained_attribute']
1600 maintained_update_project_attribute = conf.config['maintained_update_project_attribute']
1602 if not len(args) or len(args) > 2:
1603 raise oscerr.WrongArgs('Wrong number of arguments.')
1609 r = attribute_branch_pkg(conf.config['apiurl'], maintained_attribute, maintained_update_project_attribute, \
1613 print >>sys.stderr, 'ERROR: Attribute branch call came not back with a project.'
1616 print "Project " + r + " created."
1619 init_project_dir(conf.config['apiurl'], r, r)
1620 print statfrmt('A', r)
1623 for package in meta_get_packagelist(conf.config['apiurl'], r):
1625 checkout_package(conf.config['apiurl'], r, package, expand_link = True, prj_dir = r)
1627 print >>sys.stderr, 'Error while checkout package:\n', package
1629 if conf.config['verbose']:
1630 print 'Note: You can use "osc delete" or "osc submitpac" when done.\n'
1633 @cmdln.alias('branchco')
1635 @cmdln.alias('getpac')
1636 @cmdln.option('--nodevelproject', action='store_true',
1637 help='do not follow a defined devel project ' \
1638 '(primary project where a package is developed)')
1639 @cmdln.option('-c', '--checkout', action='store_true',
1640 help='Checkout branched package afterwards ' \
1641 '(\'osc bco\' is a shorthand for this option)' )
1642 @cmdln.option('-r', '--revision', metavar='rev',
1643 help='branch against a specific revision')
1644 @cmdln.option('-m', '--message', metavar='TEXT',
1645 help='specify message TEXT')
1646 def do_branch(self, subcmd, opts, *args):
1647 """${cmd_name}: Branch a package
1649 [See http://en.opensuse.org/Build_Service/Collaboration for information
1652 Create a source link from a package of an existing project to a new
1653 subproject of the requesters home project (home:branches:)
1655 The branched package will live in
1656 home:USERNAME:branches:PROJECT/PACKAGE
1657 if nothing else specified.
1659 With getpac or bco, the branched package will come from
1660 %(getpac_default_project)s
1661 if nothing else specified.
1664 osc branch SOURCEPROJECT SOURCEPACKAGE
1665 osc branch SOURCEPROJECT SOURCEPACKAGE TARGETPROJECT
1666 osc branch SOURCEPROJECT SOURCEPACKAGE TARGETPROJECT TARGETPACKAGE
1667 osc getpac SOURCEPACKAGE
1672 if subcmd == 'getpac' or subcmd == 'branchco' or subcmd == 'bco': opts.checkout = True
1673 args = slash_split(args)
1674 tproject = tpackage = None
1676 if (subcmd == 'getpac' or subcmd == 'bco') and len(args) == 1:
1677 print >>sys.stderr, 'defaulting to %s/%s' % (conf.config['getpac_default_project'], args[0])
1678 # python has no args.unshift ???
1679 args = [ conf.config['getpac_default_project'] , args[0] ]
1681 if len(args) < 2 or len(args) > 4:
1682 raise oscerr.WrongArgs('Wrong number of arguments.')
1683 expected = 'home:%s:branches:%s' % (conf.config['user'], args[0])
1685 expected = tproject = args[2]
1689 exists, targetprj, targetpkg, srcprj, srcpkg = \
1690 branch_pkg(conf.config['apiurl'], args[0], args[1],
1691 nodevelproject=opts.nodevelproject, rev=opts.revision,
1692 target_project=tproject, target_package=tpackage,
1693 return_existing=opts.checkout, msg=opts.message or '')
1695 print >>sys.stderr, 'Using existing branch project: %s' % targetprj
1698 if not exists and (srcprj is not None and srcprj != args[0] or \
1699 srcprj is None and targetprj != expected):
1700 devloc = srcprj or targetprj
1701 if not srcprj and 'branches:' in targetprj:
1702 devloc = targetprj.split('branches:')[1]
1703 print '\nNote: The branch has been created of a different project,\n' \
1705 ' which is the primary location of where development for\n' \
1706 ' that package takes place.\n' \
1707 ' That\'s also where you would normally make changes against.\n' \
1708 ' A direct branch of the specified package can be forced\n' \
1709 ' with the --nodevelproject option.\n' % devloc
1711 package = tpackage or args[1]
1713 checkout_package(conf.config['apiurl'], targetprj, package,
1714 expand_link=True, prj_dir=targetprj)
1715 if conf.config['verbose']:
1716 print 'Note: You can use "osc delete" or "osc submitpac" when done.\n'
1719 if conf.get_configParser().get('general', 'apiurl') != conf.config['apiurl']:
1720 apiopt = '-A %s ' % conf.config['apiurl']
1721 print 'A working copy of the branched package can be checked out with:\n\n' \
1723 % (apiopt, targetprj, package)
1724 print_request_list(conf.config['apiurl'], args[0], args[1])
1726 print_request_list(conf.config['apiurl'], devloc, args[1])
1730 @cmdln.option('-f', '--force', action='store_true',
1731 help='deletes a package or an empty project')
1732 def do_rdelete(self, subcmd, opts, *args):
1733 """${cmd_name}: Delete a project or packages on the server.
1735 As a safety measure, project must be empty (i.e., you need to delete all
1736 packages first). If you are sure that you want to remove this project and all
1737 its packages use \'--force\' switch.
1740 osc rdelete -f PROJECT
1741 osc rdelete PROJECT PACKAGE [PACKAGE ...]
1746 args = slash_split(args)
1748 raise oscerr.WrongArgs('Missing argument.')
1754 # careful: if pkg is an empty string, the package delete request results
1755 # into a project delete request - which works recursively...
1757 delete_package(conf.config['apiurl'], prj, pkg)
1758 elif len(meta_get_packagelist(conf.config['apiurl'], prj)) >= 1 and not opts.force:
1759 print >>sys.stderr, 'Project contains packages. It must be empty before deleting it. ' \
1760 'If you are sure that you want to remove this project and all its ' \
1761 'packages use the \'--force\' switch'
1764 delete_project(conf.config['apiurl'], prj)
1767 def do_deletepac(self, subcmd, opts, *args):
1768 print """${cmd_name} is obsolete !
1771 osc delete for checked out packages or projects
1773 osc rdelete for server side operations."""
1778 @cmdln.option('-f', '--force', action='store_true',
1779 help='deletes a project and its packages')
1780 def do_deleteprj(self, subcmd, opts, project):
1781 """${cmd_name} is obsolete !
1788 @cmdln.alias('metafromspec')
1789 @cmdln.option('', '--specfile', metavar='FILE',
1790 help='Path to specfile. (if you pass more than working copy this option is ignored)')
1791 def do_updatepacmetafromspec(self, subcmd, opts, *args):
1792 """${cmd_name}: Update package meta information from a specfile
1794 ARG, if specified, is a package working copy.
1800 args = parseargs(args)
1801 if opts.specfile and len(args) == 1:
1802 specfile = opts.specfile
1805 pacs = findpacs(args)
1807 p.read_meta_from_spec(specfile)
1808 p.update_package_meta()
1812 @cmdln.option('-c', '--change', metavar='rev',
1813 help='the change made by revision rev (like -r rev-1:rev).'
1814 'If rev is negative this is like -r rev:rev-1.')
1815 @cmdln.option('-r', '--revision', metavar='rev1[:rev2]',
1816 help='If rev1 is specified it will compare your working copy against '
1817 'the revision (rev1) on the server. '
1818 'If rev1 and rev2 are specified it will compare rev1 against rev2 '
1819 '(NOTE: changes in your working copy are ignored in this case)')
1820 @cmdln.option('-p', '--plain', action='store_true',
1821 help='output the diff in plain (not unified) diff format')
1822 def do_diff(self, subcmd, opts, *args):
1823 """${cmd_name}: Generates a diff
1825 Generates a diff, comparing local changes against the repository
1828 ARG, specified, is a filename to include in the diff.
1834 args = parseargs(args)
1835 pacs = findpacs(args)
1839 rev = int(opts.change)
1849 print >>sys.stderr, 'Revision \'%s\' not an integer' % opts.change
1852 rev1, rev2 = parseRevisionOption(opts.revision)
1856 diff += ''.join(make_diff(pac, rev1))
1858 diff += server_diff(pac.apiurl, pac.prjname, pac.name, rev1,
1859 pac.prjname, pac.name, rev2, not opts.plain)
1864 @cmdln.option('--oldprj', metavar='OLDPRJ',
1865 help='project to compare against'
1866 ' (deprecated, use 3 argument form)')
1867 @cmdln.option('--oldpkg', metavar='OLDPKG',
1868 help='package to compare against'
1869 ' (deprecated, use 3 argument form)')
1870 @cmdln.option('-r', '--revision', metavar='N[:M]',
1871 help='revision id, where N = old revision and M = new revision')
1872 @cmdln.option('-p', '--plain', action='store_true',
1873 help='output the diff in plain (not unified) diff format')
1874 @cmdln.option('-c', '--change', metavar='rev',
1875 help='the change made by revision rev (like -r rev-1:rev). '
1876 'If rev is negative this is like -r rev:rev-1.')
1877 def do_rdiff(self, subcmd, opts, *args):
1878 """${cmd_name}: Server-side "pretty" diff of two packages
1880 Compares two packages (three or four arguments) or shows the
1881 changes of a specified revision of a package (two arguments)
1883 If no revision is specified the latest revision is used.
1885 Note that this command doesn't return a normal diff (which could be
1886 applied as patch), but a "pretty" diff, which also compares the content
1891 osc ${cmd_name} OLDPRJ OLDPAC NEWPRJ [NEWPAC]
1892 osc ${cmd_name} PROJECT PACKAGE
1896 args = slash_split(args)
1907 new_project = args[0]
1908 new_package = args[1]
1910 old_project = opts.oldprj
1912 old_package = opts.oldpkg
1913 elif len(args) == 3 or len(args) == 4:
1914 if opts.oldprj or opts.oldpkg:
1915 raise oscerr.WrongArgs('--oldpkg and --oldprj are only valid with two arguments')
1916 old_project = args[0]
1917 new_package = old_package = args[1]
1918 new_project = args[2]
1920 new_package = args[3]
1922 raise oscerr.WrongArgs('Wrong number of arguments')
1927 rev = int(opts.change)
1937 print >>sys.stderr, 'Revision \'%s\' not an integer' % opts.change
1941 rev1, rev2 = parseRevisionOption(opts.revision)
1943 rdiff = server_diff(conf.config['apiurl'],
1944 old_project, old_package, rev1,
1945 new_project, new_package, rev2, not opts.plain)
1951 def do_install(self, subcmd, opts, *args):
1952 """${cmd_name}: install a package after build via zypper in -r
1954 Not implemented yet. Use osc repourls,
1955 select the url you best like (standard),
1956 chop off after the last /, this should work with zypper.
1963 args = slash_split(args)
1964 args = expand_proj_pack(args)
1967 ## if there is only one argument, and it ends in .ymp
1968 ## then fetch it, Parse XML to get the first
1969 ## metapackage.group.repositories.repository.url
1970 ## and construct zypper cmd's for all
1971 ## metapackage.group.software.item.name
1973 ## if args[0] is already an url, the use it as is.
1975 cmd = "sudo zypper -p http://download.opensuse.org/repositories/%s/%s --no-refresh -v in %s" % (re.sub(':',':/',args[0]), 'openSUSE_11.1', args[1])
1976 print self.do_install.__doc__
1977 print "Example: \n" + cmd
1980 def do_repourls(self, subcmd, opts, *args):
1981 """${cmd_name}: Shows URLs of .repo files
1983 Shows URLs on which to access the project .repos files (yum-style
1984 metadata) on download.opensuse.org.
1987 osc repourls [PROJECT]
1992 apiurl = conf.config['apiurl']
1996 elif len(args) == 0:
1997 project = store_read_project('.')
1998 apiurl = store_read_apiurl('.')
2000 raise oscerr.WrongArgs('Wrong number of arguments')
2002 # XXX: API should somehow tell that
2003 url_tmpl = 'http://download.opensuse.org/repositories/%s/%s/%s.repo'
2004 repos = get_repositories_of_project(apiurl, project)
2006 print url_tmpl % (project.replace(':', ':/'), repo, project)
2009 @cmdln.option('-r', '--revision', metavar='rev',
2010 help='checkout the specified revision. '
2011 'NOTE: if you checkout the complete project '
2012 'this option is ignored!')
2013 @cmdln.option('-e', '--expand-link', action='store_true',
2014 help='if a package is a link, check out the expanded '
2015 'sources (no-op, since this became the default)')
2016 @cmdln.option('-u', '--unexpand-link', action='store_true',
2017 help='if a package is a link, check out the _link file ' \
2018 'instead of the expanded sources')
2019 @cmdln.option('-c', '--current-dir', action='store_true',
2020 help='place PACKAGE folder in the current directory' \
2021 'instead of a PROJECT/PACKAGE directory')
2022 @cmdln.option('-s', '--source-service-files', action='store_true',
2023 help='server side generated files of source services' \
2024 'gets downloaded as well' )
2026 def do_checkout(self, subcmd, opts, *args):
2027 """${cmd_name}: Check out content from the repository
2029 Check out content from the repository server, creating a local working
2032 When checking out a single package, the option --revision can be used
2033 to specify a revision of the package to be checked out.
2035 When a package is a source link, then it will be checked out in
2036 expanded form. If --unexpand-link option is used, the checkout will
2037 instead produce the raw _link file plus patches.
2040 osc co PROJECT [PACKAGE] [FILE]
2041 osc co PROJECT # entire project
2042 osc co PROJECT PACKAGE # a package
2043 osc co PROJECT PACKAGE FILE # single file -> to current dir
2045 while inside a project directory:
2046 osc co PACKAGE # check out PACKAGE from project
2051 if opts.unexpand_link:
2055 if opts.source_service_files:
2056 service_files = True
2058 service_files = False
2060 args = slash_split(args)
2061 project = package = filename = None
2062 apiurl = conf.config['apiurl']
2064 project = project_dir = args[0]
2070 if args and len(args) == 1:
2071 localdir = os.getcwd()
2072 if is_project_dir(localdir):
2073 project = store_read_project(localdir)
2074 project_dir = localdir
2076 apiurl = store_read_apiurl(localdir)
2078 rev, dummy = parseRevisionOption(opts.revision)
2082 if rev and rev != "latest" and not checkRevision(project, package, rev):
2083 print >>sys.stderr, 'Revision \'%s\' does not exist' % rev
2087 get_source_file(apiurl, project, package, filename, revision=rev, progress_obj=self.download_progress)
2090 if opts.current_dir:
2092 checkout_package(apiurl, project, package, rev, expand_link=expand_link, \
2093 prj_dir=project_dir, service_files=service_files, progress_obj=self.download_progress)
2094 print_request_list(apiurl, project, package)
2098 if sys.platform[:3] == 'win':
2099 prj_dir = prj_dir.replace(':', ';')
2100 if os.path.exists(prj_dir):
2101 sys.exit('osc: project \'%s\' already exists' % project)
2103 # check if the project does exist (show_project_meta will throw an exception)
2104 show_project_meta(apiurl, project)
2106 init_project_dir(apiurl, prj_dir, project)
2107 print statfrmt('A', prj_dir)
2110 for package in meta_get_packagelist(apiurl, project):
2112 checkout_package(apiurl, project, package, expand_link = expand_link, \
2113 prj_dir = prj_dir, service_files = service_files, progress_obj=self.download_progress)
2114 except oscerr.LinkExpandError, e:
2115 print >>sys.stderr, 'Link cannot be expanded:\n', e
2116 print >>sys.stderr, 'Use "osc repairlink" for fixing merge conflicts:\n'
2117 # check out in unexpanded form at least
2118 checkout_package(apiurl, project, package, expand_link = False, \
2119 prj_dir = prj_dir, service_files = service_files, progress_obj=self.download_progress)
2120 print_request_list(apiurl, project)
2123 raise oscerr.WrongArgs('Missing argument.\n\n' \
2124 + self.get_cmd_help('checkout'))
2127 @cmdln.option('-q', '--quiet', action='store_true',
2128 help='print as little as possible')
2129 @cmdln.option('-v', '--verbose', action='store_true',
2130 help='print extra information')
2132 def do_status(self, subcmd, opts, *args):
2133 """${cmd_name}: Show status of files in working copy
2135 Show the status of files in a local working copy, indicating whether
2136 files have been changed locally, deleted, added, ...
2138 The first column in the output specifies the status and is one of the
2139 following characters:
2140 ' ' no modifications
2145 '?' item is not under version control
2146 '!' item is missing (removed by non-osc command) or incomplete
2151 osc st file1 file2 ...
2154 osc status [OPTS] [PATH...]
2158 args = parseargs(args)
2160 # storage for single Package() objects
2162 # storage for a project dir ( { prj_instance : [ package objects ] } )
2165 # when 'status' is run inside a project dir, it should
2166 # stat all packages existing in the wc
2167 if is_project_dir(arg):
2168 prj = Project(arg, False)
2170 if conf.config['do_package_tracking']:
2172 for pac in prj.pacs_have:
2173 # we cannot create package objects if the dir does not exist
2174 if not pac in prj.pacs_broken:
2175 prjpacs[prj].append(os.path.join(arg, pac))
2177 pacpaths += [arg + '/' + n for n in prj.pacs_have]
2178 elif is_package_dir(arg):
2179 pacpaths.append(arg)
2180 elif os.path.isfile(arg):
2181 pacpaths.append(arg)
2183 msg = '\'%s\' is neither a project or a package directory' % arg
2184 raise oscerr.NoWorkingCopy, msg
2186 # process single packages
2187 lines = getStatus(findpacs(pacpaths), None, opts.verbose, opts.quiet)
2188 # process project dirs
2189 for prj, pacs in prjpacs.iteritems():
2190 lines += getStatus(findpacs(pacs), prj, opts.verbose, opts.quiet)
2192 print '\n'.join(lines)
2195 def do_add(self, subcmd, opts, *args):
2196 """${cmd_name}: Mark files to be added upon the next commit
2199 osc add FILE [FILE...]
2203 raise oscerr.WrongArgs('Missing argument.\n\n' \
2204 + self.get_cmd_help('add'))
2206 filenames = parseargs(args)
2210 def do_mkpac(self, subcmd, opts, *args):
2211 """${cmd_name}: Create a new package under version control
2214 osc mkpac new_package
2217 if not conf.config['do_package_tracking']:
2218 print >>sys.stderr, "to use this feature you have to enable \'do_package_tracking\' " \
2219 "in the [general] section in the configuration file"
2223 raise oscerr.WrongArgs('Wrong number of arguments.')
2225 createPackageDir(args[0])
2227 @cmdln.option('-r', '--recursive', action='store_true',
2228 help='If CWD is a project dir then scan all package dirs as well')
2230 def do_addremove(self, subcmd, opts, *args):
2231 """${cmd_name}: Adds new files, removes disappeared files
2233 Adds all files new in the local copy, and removes all disappeared files.
2235 ARG, if specified, is a package working copy.
2241 args = parseargs(args)
2243 for arg in arg_list:
2244 if is_project_dir(arg) and conf.config['do_package_tracking']:
2245 prj = Project(arg, False)
2246 for pac in prj.pacs_unvers:
2247 pac_dir = getTransActPath(os.path.join(prj.dir, pac))
2248 if os.path.isdir(pac_dir):
2249 addFiles([pac_dir], prj)
2250 for pac in prj.pacs_broken:
2251 if prj.get_state(pac) != 'D':
2252 prj.set_state(pac, 'D')
2253 print statfrmt('D', getTransActPath(os.path.join(prj.dir, pac)))
2255 for pac in prj.pacs_have:
2256 state = prj.get_state(pac)
2257 if state != None and state != 'D':
2258 pac_dir = getTransActPath(os.path.join(prj.dir, pac))
2259 args.append(pac_dir)
2261 prj.write_packages()
2262 elif is_project_dir(arg):
2263 print >>sys.stderr, 'osc: addremove is not supported in a project dir unless ' \
2264 '\'do_package_tracking\' is enabled in the configuration file'
2267 pacs = findpacs(args)
2269 p.todo = p.filenamelist + p.filenamelist_unvers
2271 for filename in p.todo:
2272 if os.path.isdir(filename):
2274 # ignore foo.rXX, foo.mine for files which are in 'C' state
2275 if os.path.splitext(filename)[0] in p.in_conflict:
2277 state = p.status(filename)
2280 # TODO: should ignore typical backup files suffix ~ or .orig
2282 print statfrmt('A', getTransActPath(os.path.join(p.dir, filename)))
2284 p.put_on_deletelist(filename)
2285 p.write_deletelist()
2286 os.unlink(os.path.join(p.storedir, filename))
2287 print statfrmt('D', getTransActPath(os.path.join(p.dir, filename)))
2292 @cmdln.alias('checkin')
2293 @cmdln.option('-m', '--message', metavar='TEXT',
2294 help='specify log message TEXT')
2295 @cmdln.option('-F', '--file', metavar='FILE',
2296 help='read log message from FILE')
2297 @cmdln.option('-f', '--force', default=False, action="store_true",
2298 help='force commit - do not tests a file list')
2299 def do_commit(self, subcmd, opts, *args):
2300 """${cmd_name}: Upload content to the repository server
2302 Upload content which is changed in your working copy, to the repository
2305 Optionally checks the state of a working copy, if found a file with
2306 unknown state, it requests an user input:
2307 * skip - don't change anything, just move to another file
2308 * remove - remove a file from dir
2309 * edit file list - edit filelist using EDITOR
2310 * commit - don't check anything and commit package
2311 * abort - abort commit - this is default value
2312 This can be supressed by check_filelist config item, or -f/--force
2313 command line option.
2316 osc ci # current dir
2318 osc ci file1 file2 ...
2324 args = parseargs(args)
2331 msg = open(opts.file).read()
2333 sys.exit('could not open file \'%s\'.' % opts.file)
2336 for arg in arg_list:
2337 if conf.config['do_package_tracking'] and is_project_dir(arg):
2338 Project(arg).commit(msg=msg)
2340 msg = edit_message()
2343 pacs = findpacs(args)
2345 if conf.config['check_filelist'] and not opts.force:
2346 check_filelist_before_commit(pacs)
2349 template = store_read_file(os.path.abspath('.'), '_commit_msg')
2350 # open editor for commit message
2351 # but first, produce status and diff to append to the template
2355 changed = getStatus([pac], quiet=True)
2358 diffs += ['\nDiff for working copy: %s' % pac.dir]
2359 diffs += make_diff(pac, 0)
2360 lines.extend(get_commit_message_template(pac))
2361 if template == None:
2362 template='\n'.join(lines)
2363 # if footer is empty, there is nothing to commit, and no edit needed.
2365 msg = edit_message(footer='\n'.join(footer), template=template)
2368 store_write_string(os.path.abspath('.'), '_commit_msg', msg)
2370 store_unlink_file(os.path.abspath('.'), '_commit_msg')
2372 if conf.config['do_package_tracking'] and len(pacs) > 0:
2376 # it is possible to commit packages from different projects at the same
2377 # time: iterate over all pacs and put each pac to the right project in the dict
2379 path = os.path.normpath(os.path.join(pac.dir, os.pardir))
2380 if is_project_dir(path):
2381 pac_path = os.path.basename(os.path.normpath(pac.absdir))
2382 prj_paths.setdefault(path, []).append(pac_path)
2383 files[pac_path] = pac.todo
2385 single_paths.append(pac.dir)
2386 for prj, packages in prj_paths.iteritems():
2387 Project(prj).commit(tuple(packages), msg, files)
2388 for pac in single_paths:
2389 Package(pac).commit(msg)
2394 store_unlink_file(os.path.abspath('.'), '_commit_msg')
2396 @cmdln.option('-r', '--revision', metavar='REV',
2397 help='update to specified revision (this option will be ignored '
2398 'if you are going to update the complete project or more than '
2400 @cmdln.option('-u', '--unexpand-link', action='store_true',
2401 help='if a package is an expanded link, update to the raw _link file')
2402 @cmdln.option('-e', '--expand-link', action='store_true',
2403 help='if a package is a link, update to the expanded sources')
2404 @cmdln.option('-s', '--source-service-files', action='store_true',
2405 help='Use server side generated sources instead of local generation.' )
2407 def do_update(self, subcmd, opts, *args):
2408 """${cmd_name}: Update a working copy
2413 If the current working directory is a package, update it.
2414 If the directory is a project directory, update all contained
2415 packages, AND check out newly added packages.
2417 To update only checked out packages, without checking out new
2418 ones, you might want to use "osc up *" from within the project
2422 Update the packages specified by the path argument(s)
2424 When --expand-link is used with source link packages, the expanded
2425 sources will be checked out. Without this option, the _link file and
2426 patches will be checked out. The option --unexpand-link can be used to
2427 switch back to the "raw" source with a _link file plus patch(es).
2433 if (opts.expand_link and opts.unexpand_link) \
2434 or (opts.expand_link and opts.revision) \
2435 or (opts.unexpand_link and opts.revision):
2436 raise oscerr.WrongOptions('Sorry, the options --expand-link, --unexpand-link and '
2437 '--revision are mutually exclusive.')
2439 if opts.source_service_files: service_files = True
2440 else: service_files = False
2442 args = parseargs(args)
2445 for arg in arg_list:
2446 if is_project_dir(arg):
2447 prj = Project(arg, progress_obj=self.download_progress)
2449 if conf.config['do_package_tracking']:
2450 prj.update(expand_link=opts.expand_link,
2451 unexpand_link=opts.unexpand_link)
2454 # if not tracking package, and 'update' is run inside a project dir,
2455 # it should do the following:
2456 # (a) update all packages
2457 args += prj.pacs_have
2458 # (b) fetch new packages
2459 prj.checkout_missing_pacs(expand_link = not opts.unexpand_link)
2461 print_request_list(prj.apiurl, prj.name)
2464 pacs = findpacs(args, progress_obj=self.download_progress)
2466 if opts.revision and len(args) == 1:
2467 rev, dummy = parseRevisionOption(opts.revision)
2468 if not checkRevision(pacs[0].prjname, pacs[0].name, rev, pacs[0].apiurl):
2469 print >>sys.stderr, 'Revision \'%s\' does not exist' % rev
2476 print 'Updating %s' % p.name
2478 # FIXME: ugly workaround for #399247
2479 if opts.expand_link or opts.unexpand_link:
2480 if [ i for i in p.filenamelist+p.filenamelist_unvers if p.status(i) != ' ' and p.status(i) != '?']:
2481 print >>sys.stderr, 'osc: cannot expand/unexpand because your working ' \
2482 'copy has local modifications.\nPlease revert/commit them ' \
2487 if opts.expand_link and p.islink() and not p.isexpanded():
2488 if p.haslinkerror():
2490 rev = show_upstream_xsrcmd5(p.apiurl, p.prjname, p.name, revision=p.rev)
2492 rev = show_upstream_xsrcmd5(p.apiurl, p.prjname, p.name, revision=p.rev, linkrev="base")
2495 rev = p.linkinfo.xsrcmd5
2496 print 'Expanding to rev', rev
2497 elif opts.unexpand_link and p.islink() and p.isexpanded():
2498 print 'Unexpanding to rev', p.linkinfo.lsrcmd5
2499 rev = p.linkinfo.lsrcmd5
2500 elif p.islink() and p.isexpanded():
2501 rev = p.latest_rev()
2503 p.update(rev, service_files)
2504 if opts.unexpand_link:
2507 print_request_list(p.apiurl, p.prjname, p.name)
2510 @cmdln.option('-f', '--force', action='store_true',
2511 help='forces removal of entire package and its files')
2514 @cmdln.alias('remove')
2515 def do_delete(self, subcmd, opts, *args):
2516 """${cmd_name}: Mark files or package directories to be deleted upon the next 'checkin'
2519 cd .../PROJECT/PACKAGE
2520 osc delete FILE [...]
2522 osc delete PACKAGE [...]
2524 This command works on check out copies. Use "rdelete" for working on server
2525 side only. This is needed for removing the entire project.
2527 As a safety measure, projects must be empty (i.e., you need to delete all
2530 If you are sure that you want to remove a package and all
2531 its files use \'--force\' switch. Sometimes this also works without --force.
2537 raise oscerr.WrongArgs('Missing argument.\n\n' \
2538 + self.get_cmd_help('delete'))
2540 args = parseargs(args)
2541 # check if args contains a package which was removed by
2542 # a non-osc command and mark it with the 'D'-state
2545 if not os.path.exists(i):
2546 prj_dir, pac_dir = getPrjPacPaths(i)
2547 if is_project_dir(prj_dir):
2548 prj = Project(prj_dir, False)
2549 if i in prj.pacs_broken:
2550 if prj.get_state(i) != 'A':
2551 prj.set_state(pac_dir, 'D')
2553 prj.del_package_node(i)
2554 print statfrmt('D', getTransActPath(i))
2556 prj.write_packages()
2557 pacs = findpacs(args)
2561 prj_dir, pac_dir = getPrjPacPaths(p.absdir)
2562 if is_project_dir(prj_dir):
2563 if conf.config['do_package_tracking']:
2564 prj = Project(prj_dir, False)
2565 prj.delPackage(p, opts.force)
2567 print "WARNING: package tracking is disabled, operation skipped !"
2569 pathn = getTransActPath(p.dir)
2570 for filename in p.todo:
2571 ret, state = p.delete_file(filename, opts.force)
2573 print statfrmt('D', os.path.join(pathn, filename))
2576 sys.exit('\'%s\' is not under version control' % filename)
2577 elif state in ['A', 'M'] and not opts.force:
2578 sys.exit('\'%s\' has local modifications (use --force to remove this file)' % filename)
2581 def do_resolved(self, subcmd, opts, *args):
2582 """${cmd_name}: Remove 'conflicted' state on working copy files
2584 If an upstream change can't be merged automatically, a file is put into
2585 in 'conflicted' ('C') state. Within the file, conflicts are marked with
2586 special <<<<<<< as well as ======== and >>>>>>> lines.
2588 After manually resolving all conflicting parts, use this command to
2589 remove the 'conflicted' state.
2591 Note: this subcommand does not semantically resolve conflicts or
2592 remove conflict markers; it merely removes the conflict-related
2593 artifact files and allows PATH to be committed again.
2596 osc resolved FILE [FILE...]
2601 raise oscerr.WrongArgs('Missing argument.\n\n' \
2602 + self.get_cmd_help('resolved'))
2604 args = parseargs(args)
2605 pacs = findpacs(args)
2608 for filename in p.todo:
2609 print 'Resolved conflicted state of "%s"' % filename
2610 p.clear_from_conflictlist(filename)
2613 @cmdln.alias('platforms')
2614 def do_repositories(self, subcmd, opts, *args):
2615 """${cmd_name}: Shows available repositories
2619 Shows all available repositories/build targets
2621 2. osc repositories <project>
2622 Shows the configured repositories/build targets of a project
2630 print '\n'.join(get_repositories_of_project(conf.config['apiurl'], project))
2632 print '\n'.join(get_repositories(conf.config['apiurl']))
2636 def do_results_meta(self, subcmd, opts, *args):
2637 print "Command results_meta is obsolete. Please use: osc results --xml"
2641 @cmdln.option('-l', '--last-build', action='store_true',
2642 help='show last build results (succeeded/failed/unknown)')
2643 @cmdln.option('-r', '--repo', action='append', default = [],
2644 help='Show results only for specified repo(s)')
2645 @cmdln.option('-a', '--arch', action='append', default = [],
2646 help='Show results only for specified architecture(s)')
2647 @cmdln.option('', '--xml', action='store_true',
2648 help='generate output in XML (former results_meta)')
2649 def do_rresults(self, subcmd, opts, *args):
2650 print "Command rresults is obsolete. Running 'osc results' instead"
2651 self.do_results('results', opts, *args)
2655 @cmdln.option('-f', '--force', action='store_true', default=False,
2656 help="Don't ask and delete files")
2657 def do_rremove(self, subcmd, opts, project, package, *files):
2658 """${cmd_name}: Remove source files from selected package
2665 if not '/' in project:
2666 raise oscerr.WrongArgs("Missing operand, type osc help rremove for help")
2669 project, package = project.split('/')
2673 resp = raw_input("rm: remove source file `%s' from `%s/%s'? (yY|nN) " % (file, project, package))
2674 if resp not in ('y', 'Y'):
2677 delete_files(conf.config['apiurl'], project, package, (file, ))
2678 except urllib2.HTTPError, e:
2680 print >>sys.stderr, e
2682 if e.code in [ 400, 403, 404, 500 ]:
2683 if '<summary>' in body:
2684 msg = body.split('<summary>')[1]
2685 msg = msg.split('</summary>')[0]
2686 print >>sys.stderr, msg
2691 @cmdln.option('-l', '--last-build', action='store_true',
2692 help='show last build results (succeeded/failed/unknown)')
2693 @cmdln.option('-r', '--repo', action='append', default = [],
2694 help='Show results only for specified repo(s)')
2695 @cmdln.option('-a', '--arch', action='append', default = [],
2696 help='Show results only for specified architecture(s)')
2697 @cmdln.option('', '--xml', action='store_true',
2698 help='generate output in XML (former results_meta)')
2699 def do_results(self, subcmd, opts, *args):
2700 """${cmd_name}: Shows the build results of a package
2703 osc results (inside working copy)
2704 osc results remote_project remote_package
2709 args = slash_split(args)
2711 apiurl = conf.config['apiurl']
2714 if is_project_dir(wd):
2718 opts.hide_legend = None
2719 opts.name_filter = None
2720 opts.status_filter = None
2721 opts.vertical = None
2722 self.do_prjresults('prjresults', opts, *args)
2725 project = store_read_project(wd)
2726 package = store_read_package(wd)
2727 apiurl = store_read_apiurl(wd)
2729 raise oscerr.WrongArgs('Too few arguments (required none or two)')
2731 raise oscerr.WrongArgs('Too many arguments (required none or two)')
2740 func = show_results_meta
2743 print delim.join(func(apiurl, project, package, opts.last_build, opts.repo, opts.arch))
2745 # WARNING: this function is also called by do_results. You need to set a default there
2746 # as well when adding a new option!
2747 @cmdln.option('-q', '--hide-legend', action='store_true',
2748 help='hide the legend')
2749 @cmdln.option('-c', '--csv', action='store_true',
2751 @cmdln.option('-s', '--status-filter', metavar='STATUS',
2752 help='show only packages with buildstatus STATUS (see legend)')
2753 @cmdln.option('-n', '--name-filter', metavar='EXPR',
2754 help='show only packages whose names match EXPR')
2755 @cmdln.option('-a', '--arch', metavar='ARCH',
2756 help='show results only for specified architecture(s)')
2757 @cmdln.option('-r', '--repo', metavar='REPO',
2758 help='show results only for specified repo(s)')
2759 @cmdln.option('-V', '--vertical', action='store_true',
2760 help='list packages vertically instead horizontally')
2762 def do_prjresults(self, subcmd, opts, *args):
2763 """${cmd_name}: Shows project-wide build results
2766 osc prjresults (inside working copy)
2767 osc prjresults PROJECT
2773 apiurl = conf.config['apiurl']
2777 raise oscerr.WrongArgs('Wrong number of arguments.')
2780 project = store_read_project(wd)
2781 apiurl = store_read_apiurl(wd)
2783 print '\n'.join(get_prj_results(apiurl, project, hide_legend=opts.hide_legend, csv=opts.csv, status_filter=opts.status_filter, name_filter=opts.name_filter, repo=opts.repo, arch=opts.arch, vertical=opts.vertical))
2786 @cmdln.option('-q', '--hide-legend', action='store_true',
2787 help='hide the legend')
2788 @cmdln.option('-c', '--csv', action='store_true',
2790 @cmdln.option('-s', '--status-filter', metavar='STATUS',
2791 help='show only packages with buildstatus STATUS (see legend)')
2792 @cmdln.option('-n', '--name-filter', metavar='EXPR',
2793 help='show only packages whose names match EXPR')
2796 def do_rprjresults(self, subcmd, opts, *args):
2797 print "Command rprjresults is obsolete. Please use 'osc prjresults'"
2801 @cmdln.option('-s', '--start', metavar='START',
2802 help='get log starting from the offset')
2803 def do_buildlog(self, subcmd, opts, *args):
2804 """${cmd_name}: Shows the build log of a package
2806 Shows the log file of the build of a package. Can be used to follow the
2807 log while it is being written.
2808 Needs to be called from within a package directory.
2810 The arguments REPOSITORY and ARCH are the first two columns in the 'osc
2811 results' output. If the buildlog url is used buildlog command has the
2812 same behavior as remotebuildlog.
2814 ${cmd_usage} [REPOSITORY ARCH | BUILDLOGURL]
2818 repository = arch = None
2820 if len(args) == 1 and args[0].startswith('http'):
2821 apiurl, project, package, repository, arch = parse_buildlogurl(args[0])
2824 package = store_read_package(wd)
2825 project = store_read_project(wd)
2826 apiurl = store_read_apiurl(wd)
2830 offset = int(opts.start)
2832 if not repository or not arch:
2836 repository = args[0]
2839 print_buildlog(apiurl, project, package, repository, arch, offset)
2842 def print_repos(self):
2845 if is_package_dir(wd):
2848 elif is_project_dir(wd):
2853 print 'Valid arguments for this %s are:' % str
2855 self.do_repos(None, None)
2857 raise oscerr.WrongArgs('Missing arguments')
2860 @cmdln.alias('rbuildlog')
2861 @cmdln.option('-s', '--start', metavar='START',
2862 help='get log starting from the offset')
2863 def do_remotebuildlog(self, subcmd, opts, *args):
2864 """${cmd_name}: Shows the build log of a package
2866 Shows the log file of the build of a package. Can be used to follow the
2867 log while it is being written.
2870 osc remotebuildlog project package repository arch
2872 osc remotebuildlog project/package/repository/arch
2874 osc remotebuildlog buildlogurl
2877 if len(args) == 1 and args[0].startswith('http'):
2878 apiurl, project, package, repository, arch = parse_buildlogurl(args[0])
2880 args = slash_split(args)
2881 apiurl = conf.config['apiurl']
2883 raise oscerr.WrongArgs('Too few arguments.')
2885 raise oscerr.WrongArgs('Too many arguments.')
2887 project, package, repository, arch = args
2891 offset = int(opts.start)
2893 print_buildlog(apiurl, project, package, repository, arch, offset)
2896 @cmdln.option('-s', '--start', metavar='START',
2897 help='get log starting from offset')
2898 def do_localbuildlog(self, subcmd, opts, *args):
2899 """${cmd_name}: Shows the build log of a local buildchroot
2902 osc lbl [REPOSITORY ARCH]
2903 osc lbl # show log of newest last local build
2907 if conf.config['build-type']:
2908 # FIXME: raise Exception instead
2909 print >>sys.stderr, 'Not implemented for VMs'
2913 package = store_read_package('.')
2915 files = glob.glob(os.path.join(os.getcwd(), store, "_buildinfo-*"))
2918 raise oscerr.WrongArgs('No buildconfig found, please specify repo and arch manually.')
2922 if os.stat(f).st_mtime > os.stat(cfg).st_mtime:
2924 root = ET.parse(cfg).getroot()
2925 project = root.get("project")
2926 repo = root.get("repository")
2927 arch = root.find("arch").text
2928 elif len(args) == 2:
2929 project = store_read_project('.')
2930 package = store_read_package('.')
2934 if is_package_dir(os.curdir):
2936 raise oscerr.WrongArgs('Wrong number of arguments.')
2938 buildroot = os.environ.get('OSC_BUILD_ROOT', conf.config['build-root'])
2939 buildroot = buildroot % {'project': project, 'package': package,
2940 'repo': repo, 'arch': arch}
2943 offset = int(opts.start)
2944 logfile = os.path.join(buildroot, '.build.log')
2945 if not os.path.isfile(logfile):
2946 raise oscerr.OscIOError(None, 'logfile \'%s\' does not exist' % logfile)
2947 f = open(logfile, 'r')
2949 data = f.read(BUFSIZE)
2951 sys.stdout.write(data)
2952 data = f.read(BUFSIZE)
2956 def do_triggerreason(self, subcmd, opts, *args):
2957 """${cmd_name}: Show reason why a package got triggered to build
2959 The server decides when a package needs to get rebuild, this command
2960 shows the detailed reason for a package. A brief reason is also stored
2961 in the jobhistory, which can be accessed via "osc jobhistory".
2963 Trigger reasons might be:
2964 - new build (never build yet or rebuild manually forced)
2965 - source change (eg. on updating sources)
2966 - meta change (packages which are used for building have changed)
2967 - rebuild count sync (In case that it is configured to sync release numbers)
2969 usage in package or project directory:
2970 osc reason REPOSITORY ARCH
2971 osc reason PROJECT PACKAGE REPOSITORY ARCH
2976 args = slash_split(args)
2977 project = package = repository = arch = None
2982 if len(args) == 2: # 2
2983 if is_package_dir('.'):
2984 package = store_read_package(wd)
2986 raise oscerr.WrongArgs('package is not specified.')
2987 project = store_read_project(wd)
2988 apiurl = store_read_apiurl(wd)
2989 repository = args[0]
2991 elif len(args) == 4:
2992 apiurl = conf.config['apiurl']
2995 repository = args[2]
2998 raise oscerr.WrongArgs('Too many arguments.')
3000 print apiurl, project, package, repository, arch
3001 xml = show_package_trigger_reason(apiurl, project, package, repository, arch)
3002 root = ET.fromstring(xml)
3003 reason = root.find('explain').text
3005 if reason == "meta change":
3006 print "changed keys:"
3007 for package in root.findall('packagechange'):
3008 print " ", package.get('change'), package.get('key')
3011 # FIXME: the new osc syntax should allow to specify multiple packages
3012 # FIXME: the command should optionally use buildinfo data to show all dependencies
3013 @cmdln.alias('whatdependson')
3014 def do_dependson(self, subcmd, opts, *args):
3015 """${cmd_name}: Show the build dependencies
3017 The command dependson and whatdependson can be used to find out what
3018 will be triggered when a certain package changes.
3019 This is no guarantee, since the new build might have changed dependencies.
3021 dependson shows the build dependencies inside of a project, valid for a
3022 given repository and architecture.
3023 NOTE: to see all binary packages, which can trigger a build you need to
3024 refer the buildinfo, since this command shows only the dependencies
3025 inside of a project.
3027 The arguments REPOSITORY and ARCH can be taken from the first two columns
3028 of the 'osc repos' output.
3030 usage in package or project directory:
3031 osc dependson REPOSITORY ARCH
3032 osc whatdependson REPOSITORY ARCH
3035 osc dependson PROJECT [PACKAGE] REPOSITORY ARCH
3036 osc whatdependson PROJECT [PACKAGE] REPOSITORY ARCH
3041 args = slash_split(args)
3042 project = packages = repository = arch = reverse = None
3044 if len(args) < 2 and (is_package_dir('.') or is_project_dir('.')):
3048 raise oscerr.WrongArgs('Too many arguments.')
3050 if len(args) < 3: # 2
3051 if is_package_dir('.'):
3052 packages = [store_read_package(wd)]
3053 elif not is_project_dir('.'):
3054 raise oscerr.WrongArgs('Project and package is not specified.')
3055 project = store_read_project(wd)
3056 apiurl = store_read_apiurl(wd)
3057 repository = args[0]
3061 apiurl = conf.config['apiurl']
3063 repository = args[1]
3067 apiurl = conf.config['apiurl']
3069 packages = [args[1]]
3070 repository = args[2]
3073 if subcmd == 'whatdependson':
3076 xml = get_dependson(apiurl, project, repository, arch, packages, reverse)
3078 root = ET.fromstring(xml)
3079 for package in root.findall('package'):
3080 print package.get('name'), ":"
3081 for dep in package.findall('pkgdep'):
3085 @cmdln.option('-x', '--extra-pkgs', metavar='PAC', action='append',
3086 help='Add this package when computing the buildinfo')
3087 def do_buildinfo(self, subcmd, opts, *args):
3088 """${cmd_name}: Shows the build info
3090 Shows the build "info" which is used in building a package.
3091 This command is mostly used internally by the 'build' subcommand.
3092 It needs to be called from within a package directory.
3094 The BUILD_DESCR argument is optional. BUILD_DESCR is a local RPM specfile
3095 or Debian "dsc" file. If specified, it is sent to the server, and the
3096 buildinfo will be based on it. If the argument is not supplied, the
3097 buildinfo is derived from the specfile which is currently on the source
3100 The returned data is XML and contains a list of the packages used in
3101 building, their source, and the expanded BuildRequires.