Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
CodiMD export script
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
stgroup
misc
CodiMD export script
Commits
e3356194
Commit
e3356194
authored
2 years ago
by
Andreas Domanowski
Browse files
Options
Downloads
Patches
Plain Diff
Add accessibility check to export
parent
ca32e660
Branches
Branches containing commit
No related tags found
1 merge request
!1
Hedgedoc import
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
common.py
+22
-0
22 additions, 0 deletions
common.py
export_md/codimd_export.py
+3
-1
3 additions, 1 deletion
export_md/codimd_export.py
md-import-export.py
+5
-1
5 additions, 1 deletion
md-import-export.py
with
30 additions
and
2 deletions
common.py
+
22
−
0
View file @
e3356194
import
json
import
sys
import
sys
import
urllib.request
if
not
sys
.
platform
.
startswith
(
"
win
"
):
if
not
sys
.
platform
.
startswith
(
"
win
"
):
from
getpass
import
getpass
from
getpass
import
getpass
...
@@ -21,3 +23,23 @@ def get_sessionid(service_name, cookie_key):
...
@@ -21,3 +23,23 @@ def get_sessionid(service_name, cookie_key):
if
sid
.
startswith
(
"
s%3A
"
):
if
sid
.
startswith
(
"
s%3A
"
):
return
sid
return
sid
raise
SystemExit
(
f
"
error: the supplied session id seems to be malformed
"
)
raise
SystemExit
(
f
"
error: the supplied session id seems to be malformed
"
)
def
print_block_heading
(
message
):
separator
=
"
======================================================================================================
"
print
(
separator
)
print
(
message
)
print
(
separator
)
def
check_accessibility
(
instance_url
,
session_id
):
request_url
=
instance_url
+
'
/me/
'
headers
=
{
"
Cookie
"
:
f
"
connect.hedgeDoc.sid=
{
session_id
}
"
}
req
=
urllib
.
request
.
Request
(
request_url
,
headers
=
headers
)
with
urllib
.
request
.
urlopen
(
req
)
as
response
:
response_json
=
json
.
load
(
response
)
if
response_json
[
"
status
"
]
!=
"
ok
"
:
raise
SystemExit
(
f
"
Could not access protected resources at
{
request_url
}
. Make sure that the specified
"
f
"
cookie is correct. Aborting...
"
)
print
(
f
"
Could access protected resources at
{
instance_url
}
. Proceeding...
"
)
This diff is collapsed.
Click to expand it.
export_md/codimd_export.py
+
3
−
1
View file @
e3356194
...
@@ -10,7 +10,7 @@ from urllib.parse import quote
...
@@ -10,7 +10,7 @@ from urllib.parse import quote
from
urllib.request
import
Request
,
urlopen
from
urllib.request
import
Request
,
urlopen
import
sys
import
sys
from
common
import
get_sessionid
from
common
import
get_sessionid
,
check_accessibility
,
print_block_heading
def
slurp
(
url
,
session_id
):
def
slurp
(
url
,
session_id
):
...
@@ -31,6 +31,7 @@ def prepare_target_dir(pathname):
...
@@ -31,6 +31,7 @@ def prepare_target_dir(pathname):
def
export_from_codimd
(
instance_url
,
session_id
,
export_to
):
def
export_from_codimd
(
instance_url
,
session_id
,
export_to
):
check_accessibility
(
instance_url
,
session_id
)
"""
Retrieve CodiMD document history and try to download each document.
"""
"""
Retrieve CodiMD document history and try to download each document.
"""
try
:
try
:
data
=
json
.
loads
(
slurp
(
f
"
{
instance_url
}
/history
"
,
session_id
))
data
=
json
.
loads
(
slurp
(
f
"
{
instance_url
}
/history
"
,
session_id
))
...
@@ -38,6 +39,7 @@ def export_from_codimd(instance_url, session_id, export_to):
...
@@ -38,6 +39,7 @@ def export_from_codimd(instance_url, session_id, export_to):
raise
SystemExit
(
f
"
error: couldn
'
t access the /history endpoint:
{
error
}
"
)
raise
SystemExit
(
f
"
error: couldn
'
t access the /history endpoint:
{
error
}
"
)
except
json
.
JSONDecodeError
as
error
:
except
json
.
JSONDecodeError
as
error
:
raise
SystemExit
(
f
"
error: received malformed JSON:
{
error
}
"
)
raise
SystemExit
(
f
"
error: received malformed JSON:
{
error
}
"
)
print_block_heading
(
f
"
Preparing target directory (
{
export_to
}
)
"
)
target_dir
=
prepare_target_dir
(
export_to
)
target_dir
=
prepare_target_dir
(
export_to
)
num_ok
=
num_fail
=
0
num_ok
=
num_fail
=
0
for
row
in
data
[
"
history
"
]:
for
row
in
data
[
"
history
"
]:
...
...
This diff is collapsed.
Click to expand it.
md-import-export.py
+
5
−
1
View file @
e3356194
from
export_md.codimd_export
import
export_from_codimd
from
export_md.codimd_export
import
export_from_codimd
from
import_md.hedgedoc_import
import
import_into_hedgedoc
from
import_md.hedgedoc_import
import
import_into_hedgedoc
from
common
import
get_sessionid
from
common
import
get_sessionid
,
print_block_heading
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
export_folder
=
"
codimd-documents
"
export_folder
=
"
codimd-documents
"
export_archive
=
"
archive.zip
"
export_archive
=
"
archive.zip
"
print_block_heading
(
"
Beginning export from CodiMD...
"
)
export_from_codimd
(
"
http://localhost:3001
"
,
get_sessionid
(
"
CodiMD
"
,
"
connect.sid
"
),
export_folder
)
export_from_codimd
(
"
http://localhost:3001
"
,
get_sessionid
(
"
CodiMD
"
,
"
connect.sid
"
),
export_folder
)
print_block_heading
(
"
Beginning import to HedgeDoc...
"
)
import_into_hedgedoc
(
"
http://hedgedoc:3000
"
,
get_sessionid
(
"
HedgeDoc
"
,
"
connect.hedgeDoc.sid
"
),
import_into_hedgedoc
(
"
http://hedgedoc:3000
"
,
get_sessionid
(
"
HedgeDoc
"
,
"
connect.hedgeDoc.sid
"
),
export_folder
,
export_archive
)
export_folder
,
export_archive
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment