]> git.pld-linux.org Git - packages/archivemail.git/blob - archivemail-add-prefix-switch.patch
BR: rpmbuild(macros) >= 1.710
[packages/archivemail.git] / archivemail-add-prefix-switch.patch
1 # Description: add, document and test --prefix option for archive name
2 # Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=247340
3 # Author: Serafeim Zanikolas <serzan@hellug.gr>
4 # Last-Update: 2009-02-22
5 Index: archivemail/archivemail
6 ===================================================================
7 --- archivemail.orig/archivemail        2008-08-15 21:40:17.000000000 +0100
8 +++ archivemail/archivemail     2008-08-15 21:40:17.000000000 +0100
9 @@ -171,6 +171,7 @@
10  
11  class Options:
12      """Class to store runtime options, including defaults"""
13 +    archive_prefix       = None
14      archive_suffix       = "_archive"
15      archive_name         = None
16      days_old_max         = 180
17 @@ -208,13 +209,14 @@
18  
19          """
20          try:
21 -            opts, args = getopt.getopt(args, '?D:S:Vd:hno:F:P:qs:uv', 
22 +            opts, args = getopt.getopt(args, '?D:S:Vd:hno:F:P:qs:uvp:', 
23                               ["date=", "days=", "delete", "dry-run", "help",
24                               "include-flagged", "no-compress", "output-dir=",
25 -                            "archive-name=",
26 +                             "archive-name=",
27                               "filter-append=", "pwfile=", "dont-mangle",
28                               "preserve-unread", "quiet", "size=", "suffix=",
29 -                             "verbose", "version", "warn-duplicate", "copy"])
30 +                             "verbose", "version", "warn-duplicate", "copy",
31 +                             "prefix="])
32          except getopt.error, msg:
33              user_error(msg)
34  
35 @@ -254,6 +256,8 @@
36                  self.dry_run = 1
37              if o in ('-q', '--quiet'):
38                  self.quiet = 1
39 +            if o in ('-p', '--prefix'):
40 +                self.archive_prefix = a
41              if o in ('-s', '--suffix'):
42                  self.archive_suffix = a
43              if o in ('-S', '--size'):
44 @@ -682,6 +686,7 @@
45    -o, --output-dir=DIR  directory to store archives (default: same as original)
46    -P, --pwfile=FILE     file to read imap password from (default: None)
47    -F, --filter-append=STRING  append arbitrary string to the IMAP filter string
48 +  -p, --prefix=NAME     prefix for archive filename (default: none)
49    -s, --suffix=NAME     suffix for archive filename (default: '%s')
50        --archive-name=NAME  specify whole archive filename, overrides prefix
51                             and suffix
52 @@ -1124,8 +1129,11 @@
53          final_archive_name = mailbox_name.split('/')[-1] + parsed_suffix
54      else:
55          final_archive_name = mailbox_name + parsed_suffix
56 +    if options.archive_prefix:
57 +        final_archive_name = os.path.join(os.path.dirname(final_archive_name),\
58 +                options.archive_prefix + os.path.basename(final_archive_name))
59      if options.archive_name:
60 -       final_archive_name = options.archive_name
61 +        final_archive_name = options.archive_name
62      if options.output_dir:
63          final_archive_name = os.path.join(options.output_dir, 
64                  os.path.basename(final_archive_name))
65 Index: archivemail/test_archivemail.py
66 ===================================================================
67 --- archivemail.orig/test_archivemail.py        2008-08-15 21:40:17.000000000 +0100
68 +++ archivemail/test_archivemail.py     2008-08-15 21:40:17.000000000 +0100
69 @@ -889,6 +889,54 @@
70          archivemail.options.archive_suffix = "_archive"
71          super(TestArchiveMboxSuffix, self).tearDown()
72  
73 +class TestArchiveMboxPrefix(TestCaseInTempdir):
74 +    """make sure the 'prefix' option works"""
75 +    def setUp(self):
76 +        super(TestArchiveMboxPrefix, self).setUp()
77 +        archivemail.options.quiet = 1
78 +
79 +    def testPrefix(self):
80 +        """archiving with specified --prefix arguments"""
81 +        for prefix in ["blah-"]:
82 +            for execute in ("system_long", "system_short", "package"):
83 +                self.setUp()
84 +                days_old_max = 180
85 +                self.mbox_name = make_mbox(messages=3, 
86 +                    hours_old=(24 * (days_old_max+1)))
87 +                self.copy_name = tempfile.mkstemp()[1]
88 +                shutil.copyfile(self.mbox_name, self.copy_name)
89 +                if execute == "system_long":
90 +                    run = "./archivemail.py --quiet --prefix='%s' %s" % \
91 +                        (prefix, self.mbox_name)
92 +                    self.assertEqual(os.system(run), 0)
93 +                elif execute == "system_short":
94 +                    run = "./archivemail.py --quiet -p'%s' %s" % \
95 +                        (prefix, self.mbox_name)
96 +                    self.assertEqual(os.system(run), 0)
97 +                elif execute == "package":
98 +                    archivemail.options.archive_prefix = prefix
99 +                    archivemail.archive(self.mbox_name)
100 +                else:
101 +                    sys.exit(1)
102 +                assert(os.path.exists(self.mbox_name))
103 +                self.assertEqual(os.path.getsize(self.mbox_name), 0)
104 +
105 +                archive_name = os.path.join(os.path.dirname(self.mbox_name),\
106 +                        prefix + os.path.basename(self.mbox_name) +\
107 +                        "_archive.gz")
108 +                assert(os.path.exists(archive_name))
109 +                self.assertEqual(os.system("gzip -d %s" % archive_name), 0)
110 +                archive_name = re.sub("\.gz$", "", archive_name)
111 +                assert(os.path.exists(archive_name))
112 +                assert(filecmp.cmp(archive_name, self.copy_name, shallow=0))
113 +                os.remove(archive_name)
114 +                self.tearDown()
115 +
116 +    def tearDown(self):
117 +        archivemail.options.quiet = 0
118 +        archivemail.options.archive_prefix = None
119 +        super(TestArchiveMboxPrefix, self).tearDown()
120 +
121  
122  class TestArchiveDryRun(TestCaseInTempdir):
123      """make sure the 'dry-run' option works"""
124 Index: archivemail/archivemail.sgml
125 ===================================================================
126 --- archivemail.orig/archivemail.sgml   2008-08-15 21:38:49.000000000 +0100
127 +++ archivemail/archivemail.sgml        2008-08-15 21:40:34.000000000 +0100
128 @@ -170,6 +170,14 @@
129  
130  <VarListEntry>
131  <Term>
132 +    <Option>-p <Replaceable/NAME/, --prefix=<Replaceable/NAME/</Option>
133 +</Term>
134 +<ListItem><Para>Prefix <Replaceable/NAME/ to the archive name.
135 +</Para></ListItem>
136 +</VarListEntry>
137 +
138 +<VarListEntry>
139 +<Term>
140      <Option>-s <Replaceable/NAME/, --suffix=<Replaceable/NAME/</Option>
141  </Term>
142  <ListItem><Para>
This page took 0.127052 seconds and 3 git commands to generate.