annotate make.py @ 2622:c5e749f0c1f9

fix _wiki_macro incorrect call arguments
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 08 Jun 2014 15:26:09 +0200
parents 3334da53527e
children 82ffb3f45eed
rev   line source
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
1 #!/usr/bin/python
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
2 # Copyright: 2013 MoinMoin:RogerHaase
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
3 # License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
4
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
5 """
2312
9f516825b465 change default venv name; rename m.py to make.py; delete makemoinmenu.py; rerun "python quickinstall.py" after applying this cs
RogerHaase
parents: 2311
diff changeset
6 make.py provides a menu of commands frequently used by moin2 developers and desktop wiki users.
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
7
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
8 - wraps a few commonly used moin commands, do "moin --help" for other alternatives
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
9 - adds default file names for selected moin commands (backup, restore, ...)
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
10 - creates log files for functions with large output, extracts success/failure messages
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
11 - displays error messages if user tries to run commands out of sequence
2312
9f516825b465 change default venv name; rename m.py to make.py; delete makemoinmenu.py; rerun "python quickinstall.py" after applying this cs
RogerHaase
parents: 2311
diff changeset
12
9f516825b465 change default venv name; rename m.py to make.py; delete makemoinmenu.py; rerun "python quickinstall.py" after applying this cs
RogerHaase
parents: 2311
diff changeset
13 usage (to display a menu of commands):
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
14
2312
9f516825b465 change default venv name; rename m.py to make.py; delete makemoinmenu.py; rerun "python quickinstall.py" after applying this cs
RogerHaase
parents: 2311
diff changeset
15 - unix: ./m
9f516825b465 change default venv name; rename m.py to make.py; delete makemoinmenu.py; rerun "python quickinstall.py" after applying this cs
RogerHaase
parents: 2311
diff changeset
16 - windows: m
9f516825b465 change default venv name; rename m.py to make.py; delete makemoinmenu.py; rerun "python quickinstall.py" after applying this cs
RogerHaase
parents: 2311
diff changeset
17
9f516825b465 change default venv name; rename m.py to make.py; delete makemoinmenu.py; rerun "python quickinstall.py" after applying this cs
RogerHaase
parents: 2311
diff changeset
18 For make.py to work, it needs to know the name of a python executable and the location of a
9f516825b465 change default venv name; rename m.py to make.py; delete makemoinmenu.py; rerun "python quickinstall.py" after applying this cs
RogerHaase
parents: 2311
diff changeset
19 virtual env. These needs are met by running "python quickinstall.py" after cloning the moin2
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
20 repository. quickinstall.py creates these files or symlink in the repo root:
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
21
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
22 - unix: m, activate
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
23 - windows: m.bat, activate.bat, deactivate.bat
2312
9f516825b465 change default venv name; rename m.py to make.py; delete makemoinmenu.py; rerun "python quickinstall.py" after applying this cs
RogerHaase
parents: 2311
diff changeset
24
9f516825b465 change default venv name; rename m.py to make.py; delete makemoinmenu.py; rerun "python quickinstall.py" after applying this cs
RogerHaase
parents: 2311
diff changeset
25 Executing m.bat or ./m will run make.py. The name of the python executable is within the m.bat or ./m
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
26 script. The location of the virtual env is within the activate symlink or activate.bat.
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
27 Depending upon the command to be executed, some mix of the python executable
2312
9f516825b465 change default venv name; rename m.py to make.py; delete makemoinmenu.py; rerun "python quickinstall.py" after applying this cs
RogerHaase
parents: 2311
diff changeset
28 or activate will be used to construct a command string to pass to a subprocess call.
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
29 """
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
30
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
31 import os
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
32 import sys
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
33 import subprocess
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
34 import glob
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
35 import shutil
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
36 import fnmatch
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
37 from collections import Counter
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
38
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
39 import MoinMoin # validate python version
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
40
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
41
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
42 # text files created by commands with high volume output
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
43 QUICKINSTALL = 'm-quickinstall.txt'
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
44 PYTEST = 'm-pytest.txt'
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
45 PEP8 = 'm-pep8.txt'
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
46 CODING_STD = 'm-coding-std.txt'
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
47 DOCS = 'm-docs.txt'
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
48 NEWWIKI = 'm-new-wiki.txt'
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
49 DELWIKI = 'm-delete-wiki.txt'
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
50 BACKUPWIKI = 'm-backup-wiki.txt'
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
51 EXTRAS = 'm-extras.txt'
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
52 DIST = 'm-create-dist.txt'
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
53 # default files used for backup and restore
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
54 BACKUP_FILENAME = os.path.normpath('wiki/backup.moin')
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
55 JUST_IN_CASE_BACKUP = os.path.normpath('wiki/deleted-backup.moin')
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
56
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
57
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
58 if os.name == 'nt':
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
59 M = 'm' # customize help to local OS
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
60 ACTIVATE = 'activate.bat & '
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
61 SEP = ' & '
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
62 WINDOWS_OS = True
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
63 else:
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
64 M = './m'
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
65 # in terminal "source activate" works, but Ubuntu shell requires ". ./activate"
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
66 ACTIVATE = '. ./activate; '
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
67 SEP = ';'
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
68 WINDOWS_OS = False
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
69
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
70
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
71 # commands that create log files; "tests" creates 2 log files - pytest + pep8
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
72 CMD_LOGS = {
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
73 'quickinstall': QUICKINSTALL,
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
74 'pytest': PYTEST,
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
75 'pep8': PEP8,
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
76 # 'coding-std': CODING_STD, # not logged due to small output
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
77 'docs': DOCS,
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
78 'new-wiki': NEWWIKI,
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
79 'del-wiki': DELWIKI,
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
80 'backup': BACKUPWIKI,
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
81 'extras': EXTRAS,
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
82 'dist': DIST,
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
83 }
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
84
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
85
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
86 help = """
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
87
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
88 usage: "{0} <target>" where <target> is:
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
89
2312
9f516825b465 change default venv name; rename m.py to make.py; delete makemoinmenu.py; rerun "python quickinstall.py" after applying this cs
RogerHaase
parents: 2311
diff changeset
90 quickinstall update virtual environment with required packages
2314
42d4f773ca4a rewrite requirements.rst, install.rst, and development.rst to document make.py
RogerHaase <haaserd@gmail.com>
parents: 2312
diff changeset
91 docs create moin html documentation
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
92 extras install OpenID, Pillow, pymongo, sqlalchemy, ldap, upload.py
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
93 interwiki refresh contrib/interwiki/intermap.txt (hg version control)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
94 log <target> view detailed log generated by <target>, omit to see list
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
95
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
96 new-wiki create empty wiki
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
97 sample create wiki and load sample data
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
98 restore * create wiki and restore wiki/backup.moin *option, specify file
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
99 import <dir> import a moin 1.9 wiki/data instance from <dir>
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
100
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
101 run run built-in wiki server
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
102 backup * roll 3 prior backups and create new backup *option, specify file
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
103
2580
fb44a83e9720 add compilation of basic theme CSS files to make.py; requires change to xstatic bootstrap package
RogerHaase <haaserd@gmail.com>
parents: 2555
diff changeset
104 css run Stylus and lessc to update theme CSS files
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
105 tests run tests, output goes to pytest.txt and pytestpep8.txt
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
106 coding-std correct scripts that taint the repository with trailing spaces..
2314
42d4f773ca4a rewrite requirements.rst, install.rst, and development.rst to document make.py
RogerHaase <haaserd@gmail.com>
parents: 2312
diff changeset
107 api update moin api docs (files are under hg version control)
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
108 dist delete wiki data, then create distribution archive in dist/
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
109
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
110 del-all same as running the 4 del-* commands below
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
111 del-orig delete all files matching *.orig
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
112 del-pyc delete all files matching *.pyc
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
113 del-rej delete all files matching *.rej
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
114 del-wiki create a backup, then delete all wiki data
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
115 """.format(M)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
116
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
117
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
118 def search_for_phrase(filename):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
119 """Search a text file for key phrases and print the lines of interest or print a count by phrase."""
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
120 files = {
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
121 # filename: (list of phrases)
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
122 QUICKINSTALL: ('could not find', 'error', 'fail', 'timeout', 'traceback', 'success', 'cache location', 'must be deactivated', ),
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
123 NEWWIKI: ('error', 'fail', 'timeout', 'traceback', 'success', ),
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
124 BACKUPWIKI: ('error', 'fail', 'timeout', 'traceback', 'success', ),
2312
9f516825b465 change default venv name; rename m.py to make.py; delete makemoinmenu.py; rerun "python quickinstall.py" after applying this cs
RogerHaase
parents: 2311
diff changeset
125 # use of 'error ' below is to avoid matching .../Modules/errors.o....
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
126 EXTRAS: ('error ', 'error:', 'error.', 'error,', 'fail', 'timeout', 'traceback', 'success', 'already satisfied', 'active version', 'installed', 'finished', ),
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
127 PYTEST: ('seconds =', ),
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
128 PEP8: ('seconds =', ),
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
129 CODING_STD: ('remove trailing blanks', 'dos line endings', 'unix line endings', 'remove empty lines', ),
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
130 DIST: ('creating', 'copying', 'adding', 'hard linking', ),
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
131 DOCS: ('build finished', 'build succeeded', 'traceback', 'failed', 'error', 'usage', 'importerror', 'Exception occurred', )
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
132 }
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
133 # for these file names, display a count of occurrances rather than each found line
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
134 print_counts = (CODING_STD, DIST, )
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
135
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
136 with open(filename, "r") as f:
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
137 lines = f.readlines()
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
138 name = os.path.split(filename)[1]
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
139 phrases = files[name]
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
140 counts = Counter()
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
141 for idx, line in enumerate(lines):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
142 line = line.lower()
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
143 for phrase in phrases:
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
144 if phrase in line:
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
145 if filename in print_counts:
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
146 counts[phrase] += 1
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
147 else:
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
148 print idx + 1, line.rstrip()
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
149 break
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
150 for key in counts:
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
151 print 'The phrase "%s" was found %s times.' % (key, counts[key])
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
152
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
153
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
154 def wiki_exists():
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
155 """Return true if a wiki exists."""
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
156 return bool(glob.glob('wiki/index/_all_revs_*.toc'))
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
157
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
158
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
159 def make_wiki(command):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
160 """Process command to create a new wiki."""
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
161 if wiki_exists():
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
162 print 'Error: a wiki exists, delete it and try again.'
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
163 else:
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
164 print 'Output messages redirected to {0}.'.format(NEWWIKI)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
165 with open(NEWWIKI, 'w') as messages:
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
166 result = subprocess.call(command, shell=True, stderr=messages, stdout=messages)
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
167 if result == 0:
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
168 print '\nSuccess: a new wiki has been created.'
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
169 else:
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
170 print 'Important messages from %s are shown below:' % NEWWIKI
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
171 search_for_phrase(NEWWIKI)
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
172 print '\nError: attempt to create wiki failed. Do "%s log new-wiki" to see complete log.' % M
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
173
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
174
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
175 def delete_files(pattern):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
176 """Recursively delete all files matching pattern."""
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
177 matches = 0
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
178 for root, dirnames, filenames in os.walk(os.path.abspath(os.path.dirname(__file__))):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
179 for filename in fnmatch.filter(filenames, pattern):
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
180 os.remove(os.path.join(root, filename))
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
181 matches += 1
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
182 print 'Deleted %s files matching "%s".' % (matches, pattern)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
183
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
184
2580
fb44a83e9720 add compilation of basic theme CSS files to make.py; requires change to xstatic bootstrap package
RogerHaase <haaserd@gmail.com>
parents: 2555
diff changeset
185 def get_bootstrap_data_location():
fb44a83e9720 add compilation of basic theme CSS files to make.py; requires change to xstatic bootstrap package
RogerHaase <haaserd@gmail.com>
parents: 2555
diff changeset
186 """Return the virtualenv site-packages/xstatic/pkg/bootstrap/data location."""
fb44a83e9720 add compilation of basic theme CSS files to make.py; requires change to xstatic bootstrap package
RogerHaase <haaserd@gmail.com>
parents: 2555
diff changeset
187 command = ACTIVATE + 'python -c "from xstatic.pkg.bootstrap import BASE_DIR; print BASE_DIR"'
fb44a83e9720 add compilation of basic theme CSS files to make.py; requires change to xstatic bootstrap package
RogerHaase <haaserd@gmail.com>
parents: 2555
diff changeset
188 return subprocess.check_output(command, shell=True)
fb44a83e9720 add compilation of basic theme CSS files to make.py; requires change to xstatic bootstrap package
RogerHaase <haaserd@gmail.com>
parents: 2555
diff changeset
189
fb44a83e9720 add compilation of basic theme CSS files to make.py; requires change to xstatic bootstrap package
RogerHaase <haaserd@gmail.com>
parents: 2555
diff changeset
190
2312
9f516825b465 change default venv name; rename m.py to make.py; delete makemoinmenu.py; rerun "python quickinstall.py" after applying this cs
RogerHaase
parents: 2311
diff changeset
191 class Commands(object):
9f516825b465 change default venv name; rename m.py to make.py; delete makemoinmenu.py; rerun "python quickinstall.py" after applying this cs
RogerHaase
parents: 2311
diff changeset
192 """Each cmd_ method processes a choice on the menu."""
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
193 def __init__(self):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
194 pass
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
195
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
196 def cmd_quickinstall(self, *args):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
197 """create or update a virtual environment with the required packages"""
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
198 command = '{0} quickinstall.py {1}'.format(sys.executable, ' '.join(args))
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
199 print 'Running quickinstall.py... output messages redirected to {0}'.format(QUICKINSTALL)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
200 with open(QUICKINSTALL, 'w') as messages:
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
201 result = subprocess.call(command, shell=True, stderr=messages, stdout=messages)
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
202 if result != 0:
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
203 open(QUICKINSTALL, 'a').write('Error: quickinstall passed non-zero return code: {0}'.format(result))
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
204 print 'Searching {0}, important messages are shown below... Do "{1} log quickinstall" to see complete log.\n'.format(QUICKINSTALL, M)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
205 search_for_phrase(QUICKINSTALL)
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
206
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
207 def cmd_docs(self, *args):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
208 """create local Sphinx html documentation"""
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
209 command = '{0}cd docs{1} make html'.format(ACTIVATE, SEP)
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
210 print 'Creating HTML docs... output messages written to {0}.'.format(DOCS)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
211 with open(DOCS, 'w') as messages:
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
212 result = subprocess.call(command, shell=True, stderr=messages, stdout=messages)
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
213 print 'Searching {0}, important messages are shown below...\n'.format(DOCS)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
214 search_for_phrase(DOCS)
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
215 if result == 0:
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
216 print 'HTML docs successfully created in {0}.'.format(os.path.normpath('docs/_build/html'))
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
217 else:
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
218 print 'Error: creation of HTML docs failed with return code "{0}". Do "{1} log docs" to see complete log.'.format(result, M)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
219
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
220 def cmd_extras(self, *args):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
221 """install optional packages: OpenID, Pillow, pymongo, sqlalchemy, ldap; and upload.py"""
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
222 upload = '{0} MoinMoin/script/win/wget.py https://codereview.appspot.com/static/upload.py upload.py'.format(sys.executable)
2586
2c54228b0cbe change quickinstall.py and make.py to use --upgrade option
RogerHaase <haaserd@gmail.com>
parents: 2580
diff changeset
223 packages = ['python-openid', 'pillow', 'pymongo', 'sqlalchemy', ]
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
224 if WINDOWS_OS:
2586
2c54228b0cbe change quickinstall.py and make.py to use --upgrade option
RogerHaase <haaserd@gmail.com>
parents: 2580
diff changeset
225 installer = 'easy_install --upgrade '
2c54228b0cbe change quickinstall.py and make.py to use --upgrade option
RogerHaase <haaserd@gmail.com>
parents: 2580
diff changeset
226 # TODO: "easy_install python-ldap" fails on windows. Try google: installing python-ldap in a virtualenv on windows
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
227 # or, download from http://www.lfd.uci.edu/~gohlke/pythonlibs/#python-ldap
2586
2c54228b0cbe change quickinstall.py and make.py to use --upgrade option
RogerHaase <haaserd@gmail.com>
parents: 2580
diff changeset
228 # activate.bat
2c54228b0cbe change quickinstall.py and make.py to use --upgrade option
RogerHaase <haaserd@gmail.com>
parents: 2580
diff changeset
229 # easy_install <path to downloaded .exe file>
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
230 else:
2586
2c54228b0cbe change quickinstall.py and make.py to use --upgrade option
RogerHaase <haaserd@gmail.com>
parents: 2580
diff changeset
231 installer = 'pip install --upgrade '
2c54228b0cbe change quickinstall.py and make.py to use --upgrade option
RogerHaase <haaserd@gmail.com>
parents: 2580
diff changeset
232 packages.append('python-ldap')
2c54228b0cbe change quickinstall.py and make.py to use --upgrade option
RogerHaase <haaserd@gmail.com>
parents: 2580
diff changeset
233 command = ACTIVATE + installer + (SEP + installer).join(packages) + SEP + upload
2c54228b0cbe change quickinstall.py and make.py to use --upgrade option
RogerHaase <haaserd@gmail.com>
parents: 2580
diff changeset
234 print 'Installing {0}, upload.py... output messages written to {1}.'.format(', '.join(packages), EXTRAS)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
235 with open(EXTRAS, 'w') as messages:
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
236 subprocess.call(command, shell=True, stderr=messages, stdout=messages)
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
237 print 'Important messages from {0} are shown below. Do "{1} log extras" to see complete log.'.format(EXTRAS, M)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
238 search_for_phrase(EXTRAS)
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
239
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
240 def cmd_interwiki(self, *args):
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
241 """refresh contrib/interwiki/intermap.txt"""
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
242 print 'Refreshing {0}...'.format(os.path.normpath('contrib/interwiki/intermap.txt'))
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
243 command = '{0} MoinMoin/script/win/wget.py http://master19.moinmo.in/InterWikiMap?action=raw contrib/interwiki/intermap.txt'.format(sys.executable)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
244 subprocess.call(command, shell=True)
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
245
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
246 def cmd_log(self, *args):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
247 """View a log file with the default text editor"""
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
248
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
249 def log_help(logs):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
250 """Print list of available logs to view."""
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
251 print "usage: {0} log <target> where <target> is:\n\n".format(M)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
252 choices = '{0: <16}- {1}'
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
253 for log in sorted(logs):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
254 if os.path.isfile(CMD_LOGS[log]):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
255 print choices.format(log, CMD_LOGS[log])
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
256 else:
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
257 print choices.format(log, '* file does not exist')
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
258
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
259 logs = set(CMD_LOGS.keys())
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
260 if args and args[0] in logs and os.path.isfile(CMD_LOGS[args[0]]):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
261 if WINDOWS_OS:
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
262 command = 'start {0}'.format(CMD_LOGS[args[0]])
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
263 else:
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
264 # .format requires {{ and }} to escape { and }
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
265 command = '${{VISUAL:-${{FCEDIT:-${{EDITOR:-less}}}}}} {0}'.format(CMD_LOGS[args[0]])
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
266 subprocess.call(command, shell=True)
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
267 else:
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
268 log_help(logs)
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
269
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
270 def cmd_new_wiki(self, *args):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
271 """create empty wiki"""
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
272 command = '{0}moin index-create -s -i'.format(ACTIVATE)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
273 print 'Creating a new empty wiki...'
2312
9f516825b465 change default venv name; rename m.py to make.py; delete makemoinmenu.py; rerun "python quickinstall.py" after applying this cs
RogerHaase
parents: 2311
diff changeset
274 make_wiki(command) # share code with loading sample data and restoring backups
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
275
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
276 def cmd_sample(self, *args):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
277 """create wiki and load sample data"""
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
278 command = '{0}moin index-create -s -i{1} moin load --file contrib/serialized/items.moin{1} moin index-build'.format(ACTIVATE, SEP)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
279 print 'Creating a new wiki populated with sample data...'
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
280 make_wiki(command)
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
281
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
282 def cmd_restore(self, *args):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
283 """create wiki and load data from wiki/backup.moin or user specified path"""
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
284 command = '{0} moin index-create -s -i{1} moin load --file %s{1} moin index-build'.format(ACTIVATE, SEP)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
285 filename = BACKUP_FILENAME
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
286 if args:
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
287 filename = args[0]
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
288 if os.path.isfile(filename):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
289 command = command % filename
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
290 print 'Creating a new wiki and loading it with data from {0}...'.format(filename)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
291 make_wiki(command)
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
292 else:
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
293 print 'Error: cannot create wiki because {0} does not exist.'.format(filename)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
294
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
295 def cmd_import(self, *args):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
296 """import a moin 1.9 wiki directory named dir"""
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
297 if args:
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
298 dirname = args[0]
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
299 if os.path.isdir(dirname):
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
300 command = '{0}moin import19 -s -i --data_dir {1}'.format(ACTIVATE, dirname)
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
301 print 'Creating a new wiki populated with data from {0}...'.format(dirname)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
302 make_wiki(command)
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
303 else:
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
304 print 'Error: cannot create wiki because {0} does not exist.'.format(dirname)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
305 else:
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
306 print 'Error: a path to the Moin 1.9 wiki/data data directory is required.'
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
307
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
308 def cmd_run(self, *args):
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
309 """run built-in wiki server"""
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
310 if wiki_exists():
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
311 command = '{0}moin moin {1}'.format(ACTIVATE, ' '.join(args))
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
312 try:
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
313 subprocess.call(command, shell=True)
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
314 except KeyboardInterrupt:
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
315 pass # eliminates traceback on windows
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
316 else:
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
317 print 'Error: a wiki must be created before running the built-in server.'
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
318
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
319 def cmd_backup(self, *args):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
320 """roll 3 prior backups and create new wiki/backup.moin or backup to user specified file"""
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
321 if wiki_exists():
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
322 filename = BACKUP_FILENAME
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
323 if args:
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
324 filename = args[0]
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
325 print 'Creating a wiki backup to {0}...'.format(filename)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
326 else:
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
327 print 'Creating a wiki backup to {0} after rolling 3 prior backups...'.format(filename)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
328 b3 = BACKUP_FILENAME.replace('.', '3.')
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
329 b2 = BACKUP_FILENAME.replace('.', '2.')
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
330 b1 = BACKUP_FILENAME.replace('.', '1.')
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
331 if os.path.exists(b3):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
332 os.remove(b3)
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
333 for src, dst in ((b2, b3), (b1, b2), (BACKUP_FILENAME, b1)):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
334 if os.path.exists(src):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
335 os.rename(src, dst)
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
336
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
337 command = '{0}moin save --all-backends --file {1}'.format(ACTIVATE, filename)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
338 with open(BACKUPWIKI, 'w') as messages:
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
339 result = subprocess.call(command, shell=True, stderr=messages, stdout=messages)
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
340 if result == 0:
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
341 print 'Success: wiki was backed up to {0}'.format(filename)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
342 else:
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
343 print 'Important messages from {0} are shown below. Do "{1} log backup" to see complete log.'.format(BACKUPWIKI, M)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
344 search_for_phrase(BACKUPWIKI)
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
345 print '\nError: attempt to backup wiki failed.'
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
346 else:
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
347 print 'Error: cannot backup wiki because it has not been created.'
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
348
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
349 def cmd_css(self, *args):
2580
fb44a83e9720 add compilation of basic theme CSS files to make.py; requires change to xstatic bootstrap package
RogerHaase <haaserd@gmail.com>
parents: 2555
diff changeset
350 """run Stylus and lessc to update CSS files"""
fb44a83e9720 add compilation of basic theme CSS files to make.py; requires change to xstatic bootstrap package
RogerHaase <haaserd@gmail.com>
parents: 2555
diff changeset
351 print 'Running Stylus to update Modernized theme CSS files...'
fb44a83e9720 add compilation of basic theme CSS files to make.py; requires change to xstatic bootstrap package
RogerHaase <haaserd@gmail.com>
parents: 2555
diff changeset
352 # Note: we use / here to specify directory offsets; this works as used below in Windows XP, 2000, 7, 8
fb44a83e9720 add compilation of basic theme CSS files to make.py; requires change to xstatic bootstrap package
RogerHaase <haaserd@gmail.com>
parents: 2555
diff changeset
353 command = 'cd {0}{1}stylus --include-css --compress < main.styl > ../common.css'.format('MoinMoin/themes/modernized/static/css/stylus', SEP)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
354 result = subprocess.call(command, shell=True)
2580
fb44a83e9720 add compilation of basic theme CSS files to make.py; requires change to xstatic bootstrap package
RogerHaase <haaserd@gmail.com>
parents: 2555
diff changeset
355 print 'Running Stylus to update Foobar theme CSS files...'
fb44a83e9720 add compilation of basic theme CSS files to make.py; requires change to xstatic bootstrap package
RogerHaase <haaserd@gmail.com>
parents: 2555
diff changeset
356 command = 'cd {0}{1} stylus --include-css --compress < main.styl > ../common.css'.format('MoinMoin/themes/foobar/static/css/stylus', SEP)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
357 result2 = subprocess.call(command, shell=True)
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
358 if result == 0 and result2 == 0:
2580
fb44a83e9720 add compilation of basic theme CSS files to make.py; requires change to xstatic bootstrap package
RogerHaase <haaserd@gmail.com>
parents: 2555
diff changeset
359 print 'Success: Modernized and Foobar CSS files updated.'
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
360 else:
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
361 print 'Error: stylus failed to update css files, see error messages above.'
2610
3334da53527e prevent stylus vs. coding-std conflict on modernized common.css
RogerHaase <haaserd@gmail.com>
parents: 2586
diff changeset
362 # stylus adds too many blank lines at end of modernized common.css, fix it by running coding_std against css directory
3334da53527e prevent stylus vs. coding-std conflict on modernized common.css
RogerHaase <haaserd@gmail.com>
parents: 2586
diff changeset
363 command = 'python contrib/pep8/coding_std.py MoinMoin/themes/modernized/static/css'
3334da53527e prevent stylus vs. coding-std conflict on modernized common.css
RogerHaase <haaserd@gmail.com>
parents: 2586
diff changeset
364 result = subprocess.call(command, shell=True)
3334da53527e prevent stylus vs. coding-std conflict on modernized common.css
RogerHaase <haaserd@gmail.com>
parents: 2586
diff changeset
365 if result != 0:
3334da53527e prevent stylus vs. coding-std conflict on modernized common.css
RogerHaase <haaserd@gmail.com>
parents: 2586
diff changeset
366 print 'Error: failure running coding_std.py against modernized css files'
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
367
2580
fb44a83e9720 add compilation of basic theme CSS files to make.py; requires change to xstatic bootstrap package
RogerHaase <haaserd@gmail.com>
parents: 2555
diff changeset
368 print 'Running lessc to update Basic theme CSS files...'
fb44a83e9720 add compilation of basic theme CSS files to make.py; requires change to xstatic bootstrap package
RogerHaase <haaserd@gmail.com>
parents: 2555
diff changeset
369 data_loc = get_bootstrap_data_location().strip()
fb44a83e9720 add compilation of basic theme CSS files to make.py; requires change to xstatic bootstrap package
RogerHaase <haaserd@gmail.com>
parents: 2555
diff changeset
370 include = '--include-path=' + data_loc + '/less'
fb44a83e9720 add compilation of basic theme CSS files to make.py; requires change to xstatic bootstrap package
RogerHaase <haaserd@gmail.com>
parents: 2555
diff changeset
371 command = 'cd MoinMoin/themes/basic/static/custom-less{0}lessc {1} basic.less ../css/basic.css'.format(SEP, include)
fb44a83e9720 add compilation of basic theme CSS files to make.py; requires change to xstatic bootstrap package
RogerHaase <haaserd@gmail.com>
parents: 2555
diff changeset
372 result = subprocess.call(command, shell=True)
fb44a83e9720 add compilation of basic theme CSS files to make.py; requires change to xstatic bootstrap package
RogerHaase <haaserd@gmail.com>
parents: 2555
diff changeset
373 if result == 0:
fb44a83e9720 add compilation of basic theme CSS files to make.py; requires change to xstatic bootstrap package
RogerHaase <haaserd@gmail.com>
parents: 2555
diff changeset
374 print 'Success: Basic theme CSS files updated.'
fb44a83e9720 add compilation of basic theme CSS files to make.py; requires change to xstatic bootstrap package
RogerHaase <haaserd@gmail.com>
parents: 2555
diff changeset
375 else:
fb44a83e9720 add compilation of basic theme CSS files to make.py; requires change to xstatic bootstrap package
RogerHaase <haaserd@gmail.com>
parents: 2555
diff changeset
376 print 'Error: Basic theme CSS files update failed, see error messages above.'
fb44a83e9720 add compilation of basic theme CSS files to make.py; requires change to xstatic bootstrap package
RogerHaase <haaserd@gmail.com>
parents: 2555
diff changeset
377
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
378 def cmd_tests(self, *args):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
379 """run tests, output goes to pytest.txt and pytestpep8.txt"""
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
380 print 'Running tests... output written to %s and %s.' % (PYTEST, PEP8)
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
381 command = '{0}py.test > {1} 2>&1{2} py.test --pep8 -k pep8 --clearcache > {3} 2>&1'.format(ACTIVATE, PYTEST, SEP, PEP8)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
382 result = subprocess.call(command, shell=True)
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
383 print 'Summary message from {0} is shown below. Do "{1} log pytest" to see complete log.'.format(PYTEST, M)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
384 search_for_phrase(PYTEST)
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
385 print 'Summary message from {0} is shown below. Do "{1} log pep8" to see complete log.'.format(PEP8, M)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
386 search_for_phrase(PEP8)
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
387
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
388 def cmd_coding_std(self, *args):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
389 """correct scripts that taint the HG repository and clutter subsequent code reviews"""
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
390 print 'Checking for trailing blanks, DOS line endings, Unix line endings, empty lines at eof...'
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
391 command = '%s contrib/pep8/coding_std.py' % sys.executable
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
392 subprocess.call(command, shell=True)
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
393
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
394 def cmd_api(self, *args):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
395 """update Sphinx API docs, these docs are under hg version control"""
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
396 print 'Refreshing api docs...'
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
397 if WINDOWS_OS:
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
398 # after update, convert DOS line endings to unix
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
399 command = '{0}sphinx-apidoc -f -o docs/devel/api MoinMoin & {1} MoinMoin/script/win/dos2unix.py docs/devel/api'.format(ACTIVATE, sys.executable)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
400 else:
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
401 command = '{0}sphinx-apidoc -f -o docs/devel/api MoinMoin'.format(ACTIVATE)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
402 result = subprocess.call(command, shell=True)
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
403
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
404 def cmd_dist(self, *args):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
405 """create distribution archive in dist/"""
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
406 print 'Deleting wiki data, then creating distribution archive in /dist, output written to {0}.'.format(DIST)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
407 self.cmd_del_wiki(*args)
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
408 command = '{0} setup.py sdist'.format(sys.executable)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
409 with open(DIST, 'w') as messages:
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
410 result = subprocess.call(command, shell=True, stderr=messages, stdout=messages)
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
411 print 'Summary message from {0} is shown below:'.format(DIST)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
412 search_for_phrase(DIST)
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
413 if result == 0:
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
414 print 'Success: a distribution archive was created in {0}.'.format(os.path.normpath('/dist'))
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
415 else:
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
416 print 'Error: create dist failed with return code = {0}. Do "{1} log dist" to see complete log.'.format(result, M)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
417
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
418 def cmd_del_all(self, *args):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
419 """same as running the 4 del-* commands below"""
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
420 self.cmd_del_orig(*args)
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
421 self.cmd_del_pyc(*args)
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
422 self.cmd_del_rej(*args)
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
423 self.cmd_del_wiki(*args)
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
424
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
425 def cmd_del_orig(self, *args):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
426 """delete all files matching *.orig"""
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
427 delete_files('*.orig')
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
428
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
429 def cmd_del_pyc(self, *args):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
430 """delete all files matching *.pyc"""
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
431 delete_files('*.pyc')
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
432
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
433 def cmd_del_rej(self, *args):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
434 """delete all files matching *.rej"""
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
435 delete_files('*.rej')
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
436
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
437 def cmd_del_wiki(self, *args):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
438 """create a just-in-case backup, then delete all wiki data"""
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
439 command = '{0}moin save --all-backends --file {1}'.format(ACTIVATE, JUST_IN_CASE_BACKUP)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
440 if wiki_exists():
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
441 print 'Creating a backup named {0}; then deleting all wiki data and indexes...'.format(JUST_IN_CASE_BACKUP)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
442 with open(DELWIKI, 'w') as messages:
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
443 result = subprocess.call(command, shell=True, stderr=messages, stdout=messages)
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
444 if result != 0:
2555
98ab35b03176 fixes #398; simplify code in make.py; eliminate creation of moin.bat, moin symlink
RogerHaase <haaserd@gmail.com>
parents: 2314
diff changeset
445 print 'Error: backup failed with return code = {0}. Complete log is in {1}.'.format(result, DELWIKI)
2312
9f516825b465 change default venv name; rename m.py to make.py; delete makemoinmenu.py; rerun "python quickinstall.py" after applying this cs
RogerHaase
parents: 2311
diff changeset
446 # destroy wiki even if backup fails
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
447 if os.path.isdir('wiki/data') or os.path.isdir('wiki/index'):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
448 shutil.rmtree('wiki/data')
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
449 shutil.rmtree('wiki/index')
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
450 print 'Wiki data successfully deleted.'
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
451 else:
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
452 print 'Wiki data not deleted because it does not exist.'
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
453
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
454
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
455 if __name__ == '__main__':
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
456 # create a set of valid menu choices
2312
9f516825b465 change default venv name; rename m.py to make.py; delete makemoinmenu.py; rerun "python quickinstall.py" after applying this cs
RogerHaase
parents: 2311
diff changeset
457 commands = Commands()
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
458 choices = set()
2312
9f516825b465 change default venv name; rename m.py to make.py; delete makemoinmenu.py; rerun "python quickinstall.py" after applying this cs
RogerHaase
parents: 2311
diff changeset
459 names = dir(commands)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
460 for name in names:
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
461 if name.startswith('cmd_'):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
462 choices.add(name)
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
463
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
464 if len(sys.argv) == 1 or sys.argv[1] == '-h' or sys.argv[1] == '--help':
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
465 print help
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
466 else:
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
467 if sys.argv[1] != 'quickinstall' and not (os.path.isfile('activate') or os.path.isfile('activate.bat')):
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
468 print 'Error: files created by quickinstall are missing, run "%s quickinstall" and try again.' % M
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
469 else:
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
470 choice = 'cmd_%s' % sys.argv[1]
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
471 choice = choice.replace('-', '_')
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
472 if choice in choices:
2312
9f516825b465 change default venv name; rename m.py to make.py; delete makemoinmenu.py; rerun "python quickinstall.py" after applying this cs
RogerHaase
parents: 2311
diff changeset
473 choice = getattr(commands, choice)
2311
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
474 choice(*sys.argv[2:])
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
475 else:
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
476 print help
c4abbe125226 rewrite Makefile as python script for windows and unix
RogerHaase
parents:
diff changeset
477 print 'Error: unknown menu selection "%s"' % sys.argv[1]