1 | from gluon.fileutils import read_file, write_file |
---|
2 | |
---|
3 | if DEMO_MODE or MULTI_USER_MODE: |
---|
4 | session.flash = T('disabled in demo mode') |
---|
5 | redirect(URL('default', 'site')) |
---|
6 | if not have_mercurial: |
---|
7 | session.flash = T("Sorry, could not find mercurial installed") |
---|
8 | redirect(URL('default', 'design', args=request.args(0))) |
---|
9 | |
---|
10 | _hgignore_content = """\ |
---|
11 | syntax: glob |
---|
12 | *~ |
---|
13 | *.pyc |
---|
14 | *.pyo |
---|
15 | *.bak |
---|
16 | *.bak2 |
---|
17 | cache/* |
---|
18 | private/* |
---|
19 | uploads/* |
---|
20 | databases/* |
---|
21 | sessions/* |
---|
22 | errors/* |
---|
23 | """ |
---|
24 | |
---|
25 | |
---|
26 | def hg_repo(path): |
---|
27 | import os |
---|
28 | uio = ui.ui() |
---|
29 | uio.quiet = True |
---|
30 | if not os.environ.get('HGUSER') and not uio.config("ui", "username"): |
---|
31 | os.environ['HGUSER'] = 'web2py@localhost' |
---|
32 | try: |
---|
33 | repo = hg.repository(ui=uio, path=path) |
---|
34 | except: |
---|
35 | repo = hg.repository(ui=uio, path=path, create=True) |
---|
36 | hgignore = os.path.join(path, '.hgignore') |
---|
37 | if not os.path.exists(hgignore): |
---|
38 | write_file(hgignore, _hgignore_content) |
---|
39 | return repo |
---|
40 | |
---|
41 | |
---|
42 | def commit(): |
---|
43 | app = request.args(0) |
---|
44 | path = apath(app, r=request) |
---|
45 | repo = hg_repo(path) |
---|
46 | form = FORM(T('Comment:'), INPUT(_name='comment', requires=IS_NOT_EMPTY()), |
---|
47 | INPUT(_type='submit', _value=T('Commit'))) |
---|
48 | if form.accepts(request.vars, session): |
---|
49 | oldid = repo[repo.lookup('.')] |
---|
50 | addremove(repo) |
---|
51 | repo.commit(text=form.vars.comment) |
---|
52 | if repo[repo.lookup('.')] == oldid: |
---|
53 | response.flash = T('no changes') |
---|
54 | try: |
---|
55 | files = TABLE(*[TR(file) for file in repo[repo.lookup('.')].files()]) |
---|
56 | changes = TABLE(TR(TH('revision'), TH('description'))) |
---|
57 | for change in repo.changelog: |
---|
58 | ctx = repo.changectx(change) |
---|
59 | revision, description = ctx.rev(), ctx.description() |
---|
60 | changes.append(TR(A(revision, _href=URL('revision', |
---|
61 | args=(app, revision))), |
---|
62 | description)) |
---|
63 | except: |
---|
64 | files = [] |
---|
65 | changes = [] |
---|
66 | return dict(form=form, files=files, changes=changes, repo=repo) |
---|
67 | |
---|
68 | |
---|
69 | def revision(): |
---|
70 | app = request.args(0) |
---|
71 | path = apath(app, r=request) |
---|
72 | repo = hg_repo(path) |
---|
73 | revision = request.args(1) |
---|
74 | ctx = repo.changectx(revision) |
---|
75 | form = FORM(INPUT(_type='submit', _value=T('Revert'))) |
---|
76 | if form.accepts(request.vars): |
---|
77 | hg.update(repo, revision) |
---|
78 | session.flash = T("reverted to revision %s") % ctx.rev() |
---|
79 | redirect(URL('default', 'design', args=app)) |
---|
80 | return dict( |
---|
81 | files=ctx.files(), |
---|
82 | rev=str(ctx.rev()), |
---|
83 | desc=ctx.description(), |
---|
84 | form=form |
---|
85 | ) |
---|