Pārlūkot izejas kodu

Merge pull request #63 from tracim/fix/better_readme

Damien Accorsi 6 gadus atpakaļ
vecāks
revīzija
9fda7dadf3
Revīzijas autora e-pasts nav piesaistīts nevienam kontam

+ 1 - 0
.gitignore Parādīt failu

@@ -60,6 +60,7 @@ wsgidav.conf
60 60
 *~
61 61
 *.sqlite
62 62
 *.lock
63
+depot/
63 64
 
64 65
 # binary translation files
65 66
 *.mo

+ 19 - 6
README.md Parādīt failu

@@ -14,20 +14,23 @@ Installation
14 14
 
15 15
 ### Distribution dependencies ###
16 16
 
17
-on Debian Stretch (9) :
17
+on Debian Stretch (9) with sudo:
18 18
 
19
+    sudo apt update
19 20
     sudo apt install git
20
-    sudo apt install python3 python-virtualenv python3-dev python-pip
21
+    sudo apt install python3 python3-venv python3-dev python3-pip
21 22
 
22 23
 ### Get the source ###
23 24
 
25
+get source from github:
26
+
24 27
     git clone https://github.com/tracim/tracim_backend.git
25 28
 
26
-### Setup Python Virtualenv ###
29
+go to *tracim_backend* directory:
27 30
 
28
-Go to *tracim* subdirectory:
31
+    cd tracim_backend
29 32
 
30
-    cd tracim
33
+### Setup Python Virtualenv ###
31 34
 
32 35
 Create a Python virtual environment:
33 36
 
@@ -64,7 +67,7 @@ For mySQL:
64 67
 
65 68
 Create [configuration file](doc/setting.md) for a development environment:
66 69
 
67
-    cp development.ini.base development.ini
70
+    cp development.ini.sample development.ini
68 71
 
69 72
 Initialize the database using [tracimcli](doc/cli.md) tool
70 73
 
@@ -76,6 +79,16 @@ Run your project:
76 79
 
77 80
     pserve development.ini
78 81
 
82
+### Configure and Run Webdav Server (Unstable) ###
83
+
84
+create wsgidav configuration file :
85
+
86
+    cp wsgidav.conf.sample wsgidav.conf
87
+
88
+run wsgidav server:
89
+
90
+    tracimcli webdav start
91
+
79 92
 ### Run Tests and others checks ###
80 93
 
81 94
 Run your project's tests:

+ 19 - 6
doc/cli.md Parādīt failu

@@ -1,4 +1,4 @@
1
-## TracimCli ##
1
+# TracimCli #
2 2
 
3 3
 Tracim has a build-in command line tool.
4 4
 
@@ -6,18 +6,27 @@ Tracim has a build-in command line tool.
6 6
 
7 7
 This document is intended to developers or sysadmin.
8 8
 
9
-In order to use the `tracimcli` commands, change your current directory to be `tracim/` from the root of the project, also usually named `tracim/` 
9
+In order to use the `tracimcli` commands, go to the root of the project and
10 10
 and active the Tracim virtualenv:
11 11
 
12
-    user@host:~/tracim_backend$ cd tracim/
13
-    user@host:~/tracim_backend/tracim$ source env/bin/activate
14
-    (env) user@host:~/tracim_backend/tracim$
12
+    user@host:~/tracim_backend$ source env/bin/activate
13
+    (env) user@host:~/tracim_backend$
15 14
 
16 15
 ## Database ##
17 16
 
18 17
 ### Create database
19 18
 
20
-    tracim db init
19
+    tracimcli db init
20
+
21
+### Create database with some default test data (many users, workspaces, etc…)
22
+
23
+    tracimcli db init --test-data
24
+
25
+### Delete database /!\
26
+
27
+This will drop all your database, be carefull !
28
+
29
+    tracimcli db delete --force
21 30
 
22 31
 ## User ##
23 32
    
@@ -38,6 +47,10 @@ and active the Tracim virtualenv:
38 47
 
39 48
     tracimcli -h
40 49
     
50
+## Run services ##
51
+
52
+### Webdav wsgidav server ###
41 53
 
54
+    tracimcli webdav start
42 55
 
43 56
 

+ 3 - 4
doc/migration.md Parādīt failu

@@ -6,12 +6,11 @@ This document is intended to developers.
6 6
 
7 7
 Migrations on `Tracim` lays on [`alembic`](http://alembic.zzzcomputing.com/en/latest/index.html) which is the migration tool dedicated to `SQLAlchemy`.
8 8
 
9
-In order to use the `alembic` commands, change your current directory to be `tracim/` from the root of the project, also usually named `tracim/` 
9
+In order to use the `tracimcli` commands, go to the root of the project and
10 10
 and active the Tracim virtualenv:
11 11
 
12
-    user@host:~/tracim_backend$ cd tracim/
13
-    user@host:~/tracim_backend/tracim$ source env/bin/activate
14
-    (env) user@host:~/tracim_backend/tracim$
12
+    user@host:~/tracim_backend$ source env/bin/activate
13
+    (env) user@host:~/tracim_backend$
15 14
 
16 15
 ## Migration howto - Overview ##
17 16
    

+ 2 - 1
setup.py Parādīt failu

@@ -98,7 +98,8 @@ setup(
98 98
             'test = tracim.command:TestTracimCommand',
99 99
             'user_create = tracim.command.user:CreateUserCommand',
100 100
             'user_update = tracim.command.user:UpdateUserCommand',
101
-            'db_init = tracim.command.initializedb:InitializeDBCommand',
101
+            'db_init = tracim.command.database:InitializeDBCommand',
102
+            'db_delete = tracim.command.database:DeleteDBCommand',
102 103
             'webdav start = tracim.command.webdav:WebdavRunnerCommand',
103 104
         ]
104 105
     },

+ 132 - 0
tracim/command/database.py Parādīt failu

@@ -0,0 +1,132 @@
1
+# -*- coding: utf-8 -*-
2
+import argparse
3
+
4
+import plaster_pastedeploy
5
+import transaction
6
+from depot.manager import DepotManager
7
+from pyramid.paster import (
8
+    get_appsettings,
9
+    setup_logging,
10
+    )
11
+
12
+from tracim import CFG
13
+from tracim.fixtures import FixturesLoader
14
+from tracim.fixtures.users_and_groups import Base as BaseFixture
15
+from tracim.fixtures.content import Content as ContentFixture
16
+from sqlalchemy.exc import IntegrityError
17
+from tracim.command import AppContextCommand
18
+from tracim.models.meta import DeclarativeBase
19
+from tracim.models import (
20
+    get_engine,
21
+    get_session_factory,
22
+    get_tm_session,
23
+    )
24
+
25
+
26
+class InitializeDBCommand(AppContextCommand):
27
+    auto_setup_context = False
28
+
29
+    def get_description(self) -> str:
30
+        return "Initialize database"
31
+
32
+    def get_parser(self, prog_name: str) -> argparse.ArgumentParser:
33
+        parser = super().get_parser(prog_name)
34
+        parser.add_argument(
35
+            "--test-data",
36
+            help='Add some default data to database to make test',
37
+            dest='test_data',
38
+            required=False,
39
+            action='store_true',
40
+            default=False,
41
+        )
42
+        return parser
43
+
44
+    def take_action(self, parsed_args: argparse.Namespace) -> None:
45
+        super(InitializeDBCommand, self).take_action(parsed_args)
46
+        config_uri = parsed_args.config_file
47
+        setup_logging(config_uri)
48
+        settings = get_appsettings(config_uri)
49
+        self._create_schema(settings)
50
+        self._populate_database(settings, add_test_data=parsed_args.test_data)
51
+
52
+    @classmethod
53
+    def _create_schema(
54
+            cls,
55
+            settings: plaster_pastedeploy.ConfigDict
56
+    ) -> None:
57
+        print("- Create Schemas of databases -")
58
+        engine = get_engine(settings)
59
+        DeclarativeBase.metadata.create_all(engine)
60
+
61
+    @classmethod
62
+    def _populate_database(
63
+            cls,
64
+            settings: plaster_pastedeploy.ConfigDict,
65
+            add_test_data: bool
66
+    ) -> None:
67
+        engine = get_engine(settings)
68
+        session_factory = get_session_factory(engine)
69
+        app_config = CFG(settings)
70
+        print("- Populate database with default data -")
71
+        with transaction.manager:
72
+            dbsession = get_tm_session(session_factory, transaction.manager)
73
+            try:
74
+                fixtures = [BaseFixture]
75
+                fixtures_loader = FixturesLoader(dbsession, app_config)
76
+                fixtures_loader.loads(fixtures)
77
+                transaction.commit()
78
+                if add_test_data:
79
+                    app_config.configure_filedepot()
80
+                    fixtures = [ContentFixture]
81
+                    fixtures_loader.loads(fixtures)
82
+                transaction.commit()
83
+                print("Database initialized.")
84
+            except IntegrityError:
85
+                print('Warning, there was a problem when adding default data'
86
+                      ', it may have already been added:')
87
+                import traceback
88
+                print(traceback.format_exc())
89
+                transaction.abort()
90
+                print('Database initialization failed')
91
+
92
+
93
+class DeleteDBCommand(AppContextCommand):
94
+    auto_setup_context = False
95
+
96
+    def get_description(self) -> str:
97
+        return "Delete database"
98
+
99
+    def get_parser(self, prog_name: str) -> argparse.ArgumentParser:
100
+        parser = super().get_parser(prog_name)
101
+        parser.add_argument(
102
+            "--force",
103
+            help='force delete of database',
104
+            dest='force',
105
+            required=False,
106
+            action='store_true',
107
+            default=False,
108
+        )
109
+        return parser
110
+
111
+    def take_action(self, parsed_args: argparse.Namespace) -> None:
112
+        super(DeleteDBCommand, self).take_action(parsed_args)
113
+        config_uri = parsed_args.config_file
114
+        setup_logging(config_uri)
115
+        settings = get_appsettings(config_uri)
116
+        engine = get_engine(settings)
117
+        app_config = CFG(settings)
118
+        app_config.configure_filedepot()
119
+
120
+        if parsed_args.force:
121
+            print('Database deletion begin.')
122
+            DeclarativeBase.metadata.drop_all(engine)
123
+            print('Database deletion done.')
124
+            print('Cleaning depot begin.')
125
+            depot = DepotManager.get()
126
+            depot_files = depot.list()
127
+            for file_ in depot_files:
128
+                depot.delete(file_)
129
+            print('Cleaning depot done.')
130
+        else:
131
+            print('Warning, You should use --force if you really want to'
132
+                  ' delete database.')

+ 0 - 73
tracim/command/initializedb.py Parādīt failu

@@ -1,73 +0,0 @@
1
-# -*- coding: utf-8 -*-
2
-import argparse
3
-
4
-import plaster_pastedeploy
5
-import transaction
6
-from pyramid.paster import (
7
-    get_appsettings,
8
-    setup_logging,
9
-    )
10
-
11
-from tracim import CFG
12
-from tracim.fixtures import FixturesLoader
13
-from tracim.fixtures.users_and_groups import Base as BaseFixture
14
-from sqlalchemy.exc import IntegrityError
15
-from tracim.command import AppContextCommand
16
-from tracim.models.meta import DeclarativeBase
17
-from tracim.models import (
18
-    get_engine,
19
-    get_session_factory,
20
-    get_tm_session,
21
-    )
22
-
23
-
24
-class InitializeDBCommand(AppContextCommand):
25
-    auto_setup_context = False
26
-
27
-    def get_description(self) -> str:
28
-        return "Initialize DB"
29
-
30
-    def get_parser(self, prog_name: str) -> argparse.ArgumentParser:
31
-        parser = super().get_parser(prog_name)
32
-        return parser
33
-
34
-    def take_action(self, parsed_args: argparse.Namespace) -> None:
35
-        super(InitializeDBCommand, self).take_action(parsed_args)
36
-        config_uri = parsed_args.config_file
37
-        setup_logging(config_uri)
38
-        settings = get_appsettings(config_uri)
39
-        self._create_schema(settings)
40
-        self._populate_database(settings)
41
-
42
-    @classmethod
43
-    def _create_schema(
44
-            cls,
45
-            settings: plaster_pastedeploy.ConfigDict
46
-    ) -> None:
47
-        print("- Create Schemas of databases -")
48
-        engine = get_engine(settings)
49
-        DeclarativeBase.metadata.create_all(engine)
50
-
51
-    @classmethod
52
-    def _populate_database(
53
-            cls,
54
-            settings: plaster_pastedeploy.ConfigDict
55
-    ) -> None:
56
-        engine = get_engine(settings)
57
-        session_factory = get_session_factory(engine)
58
-        app_config = CFG(settings)
59
-        print("- Populate database with default data -")
60
-        with transaction.manager:
61
-            dbsession = get_tm_session(session_factory, transaction.manager)
62
-            try:
63
-                fixtures_loader = FixturesLoader(dbsession, app_config)
64
-                fixtures_loader.loads([BaseFixture])
65
-                transaction.commit()
66
-                print("Database initialized.")
67
-            except IntegrityError:
68
-                print('Warning, there was a problem when adding default data'
69
-                      ', it may have already been added:')
70
-                import traceback
71
-                print(traceback.format_exc())
72
-                transaction.abort()
73
-                print('Database initialization failed')

+ 1 - 1
tracim/tests/__init__.py Parādīt failu

@@ -5,7 +5,7 @@ from depot.manager import DepotManager
5 5
 from pyramid import testing
6 6
 from sqlalchemy.exc import IntegrityError
7 7
 
8
-from tracim.command.initializedb import InitializeDBCommand
8
+from tracim.command.database import InitializeDBCommand
9 9
 from tracim.lib.core.content import ContentApi
10 10
 from tracim.lib.core.workspace import WorkspaceApi
11 11
 from tracim.models import get_engine, DeclarativeBase, get_session_factory, \

+ 1 - 0
tracim/tests/commands/test_commands.py Parādīt failu

@@ -19,3 +19,4 @@ class TestCommands(object):
19 19
         assert output.find('user create') > 0
20 20
         assert output.find('user update') > 0
21 21
         assert output.find('db init') > 0
22
+        assert output.find('db delete') > 0

+ 38 - 0
wsgidav.conf.sample Parādīt failu

@@ -0,0 +1,38 @@
1
+################################################################################
2
+# Sample WsgiDAV configuration file
3
+#
4
+# 1. Rename this file to `wsgidav.conf`
5
+# 2. Adjust settings as appropriate
6
+# 3. Run tracim as you always do :)
7
+#
8
+################################################################################
9
+
10
+################################################################################
11
+# SERVER OPTIONS
12
+#===============================================================================
13
+
14
+
15
+# host  = "localhost"
16
+# host  = "192.168.0.1"
17
+host  = "0.0.0.0"
18
+
19
+port = 3030
20
+
21
+show_history = True
22
+show_deleted = True
23
+show_archived = True
24
+
25
+manager_locks = True
26
+
27
+root_path = ''
28
+
29
+# Tracim doesn't support digest auth for webdav
30
+acceptbasic = True
31
+acceptdigest = False
32
+defaultdigest = False
33
+#===============================================================================
34
+# Lock Manager
35
+#
36
+# Example: Use PERSISTENT shelve based lock manager
37
+#from wsgidav.lock_storage import LockStorageShelve
38
+#locksmanager = LockStorageShelve("wsgidav-locks.shelve")