+ print 'done'
+
+def __import_file(patch, filename, options):
+ """Import a patch from a file or standard input
+ """
+ if filename:
+ f = file(filename)
+ else:
+ f = sys.stdin
+
+ if options.mail:
+ try:
+ msg = email.message_from_file(f)
+ except Exception, ex:
+ raise CmdException, 'error parsing the e-mail file: %s' % str(ex)
+ message, author_name, author_email, author_date, diff = \
+ __parse_mail(msg)
+ else:
+ message, author_name, author_email, author_date, diff = \
+ __parse_patch(f)
+
+ if filename:
+ f.close()
+
+ __create_patch(patch, message, author_name, author_email,
+ author_date, diff, options)
+
+def __import_series(filename, options):
+ """Import a series of patches
+ """
+ applied = crt_series.get_applied()
+
+ if filename:
+ f = file(filename)
+ patchdir = os.path.dirname(filename)
+ else:
+ f = sys.stdin
+ patchdir = ''
+
+ for line in f:
+ patch = re.sub('#.*$', '', line).strip()
+ if not patch:
+ continue
+ patchfile = os.path.join(patchdir, patch)
+
+ if options.strip:
+ patch = __strip_patch_name(patch)
+ patch = __replace_slashes_with_dashes(patch);
+
+ __import_file(patch, patchfile, options)
+
+ if filename:
+ f.close()
+
+def __import_mbox(filename, options):
+ """Import a series from an mbox file
+ """
+ if filename:
+ f = file(filename, 'rb')
+ else:
+ f = sys.stdin
+
+ try:
+ mbox = UnixMailbox(f, email.message_from_file)
+ except Exception, ex:
+ raise CmdException, 'error parsing the mbox file: %s' % str(ex)
+
+ for msg in mbox:
+ message, author_name, author_email, author_date, diff = \
+ __parse_mail(msg)
+ __create_patch(None, message, author_name, author_email,
+ author_date, diff, options)
+
+ if filename:
+ f.close()
+
+def func(parser, options, args):
+ """Import a GNU diff file as a new patch
+ """
+ if len(args) > 1:
+ parser.error('incorrect number of arguments')
+
+ check_local_changes()
+ check_conflicts()
+ check_head_top_equal()
+
+ if len(args) == 1:
+ filename = args[0]
+ else:
+ filename = None
+
+ if options.series:
+ __import_series(filename, options)
+ elif options.mbox:
+ __import_mbox(filename, options)
+ else:
+ if options.name:
+ patch = options.name
+ elif filename:
+ patch = os.path.basename(filename)
+ else:
+ patch = ''
+ if options.strip:
+ patch = __strip_patch_name(patch)
+
+ __import_file(patch, filename, options)
+