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
c0ab6f2f
Commit
c0ab6f2f
authored
2 years ago
by
Andreas Domanowski
Browse files
Options
Downloads
Patches
Plain Diff
Remove accessibility check
parent
0bf70bcc
No related branches found
No related tags found
1 merge request
!1
Hedgedoc import
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
common.py
+19
-11
19 additions, 11 deletions
common.py
export_md/codimd_export.py
+1
-2
1 addition, 2 deletions
export_md/codimd_export.py
import_md/hedgedoc_import.py
+6
-7
6 additions, 7 deletions
import_md/hedgedoc_import.py
with
26 additions
and
20 deletions
common.py
+
19
−
11
View file @
c0ab6f2f
import
json
import
sys
import
urllib.request
from
urllib.error
import
HTTPError
if
not
sys
.
platform
.
startswith
(
"
win
"
):
from
getpass
import
getpass
...
...
@@ -32,14 +33,21 @@ def print_block_heading(message):
print
(
separator
)
def
check_accessibility
(
instance_url
,
session_id
,
cookie_key
):
request_url
=
instance_url
+
'
/me/
'
headers
=
{
"
Cookie
"
:
f
"
{
cookie_key
}
=
{
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...
"
)
#def check_accessibility(instance_url, session_id, cookie_key):
# request_url = instance_url + '/me/'
# headers = {"Cookie": f"{cookie_key}={session_id}"}
# try:
# 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_no_connection_error(request_url)
# print(f"Could access protected resources at {instance_url}. Proceeding...")
# except HTTPError as error:
# print(f"HTTP {error.status} {error.reason}")
# raise_no_connection_error(request_url)
def
raise_no_connection_error
(
request_url
):
raise
SystemExit
(
f
"
Could not access protected resources at
{
request_url
}
. Make sure that the specified
"
f
"
cookie is correct. Aborting...
"
)
This diff is collapsed.
Click to expand it.
export_md/codimd_export.py
+
1
−
2
View file @
c0ab6f2f
...
...
@@ -10,7 +10,7 @@ from urllib.parse import quote
from
urllib.request
import
Request
,
urlopen
import
sys
from
common
import
get_sessionid
,
check_accessibility
,
print_block_heading
from
common
import
get_sessionid
,
print_block_heading
def
slurp
(
url
,
session_id
):
...
...
@@ -31,7 +31,6 @@ def prepare_target_dir(pathname):
def
export_from_codimd
(
instance_url
,
session_id
,
export_to
):
check_accessibility
(
instance_url
,
session_id
,
"
connect.sid
"
)
"""
Retrieve CodiMD document history and try to download each document.
"""
print_block_heading
(
f
"
Trying to fetch history (
{
instance_url
}
)
"
)
try
:
...
...
This diff is collapsed.
Click to expand it.
import_md/hedgedoc_import.py
+
6
−
7
View file @
c0ab6f2f
#!/usr/bin/env python3
import
json
from
urllib.error
import
HTTPError
from
common
import
get_sessionid
,
check_accessibility
,
print_block_heading
from
common
import
get_sessionid
,
print_block_heading
from
pathlib
import
Path
import
urllib.parse
import
urllib.request
...
...
@@ -30,9 +30,8 @@ def check_file_exists(file):
def
import_into_hedgedoc
(
instance_url
,
session_id
,
export_folder
,
archive_file
):
print_block_heading
(
f
"
Checking existence of archive file (
{
archive_file
}
)
exists and authorization at
{
instance_url
}
"
)
f
"
Checking existence of archive file (
{
archive_file
}
)
"
)
check_file_exists
(
archive_file
)
check_accessibility
(
instance_url
,
session_id
,
"
connect.hedgeDoc.sid
"
)
# get exported history map
with
open
(
os
.
path
.
join
(
export_folder
,
"
history.json
"
))
as
map_file
:
history_dictionary
=
json
.
load
(
map_file
)
...
...
@@ -45,15 +44,15 @@ def import_into_hedgedoc(instance_url, session_id, export_folder, archive_file):
# URLs to visit to make the new document available in the history
urls_to_visit
=
[]
process_archive_export
(
archive_file
,
instance_url
,
lookup_map
,
session_id
,
urls_to_visit
)
create_urls_to_visit_file
(
"
history_scripts/hedgedoc_documents_to_visit.url
"
,
urls_to_visit
)
#
process_archive_export(archive_file, instance_url, lookup_map, session_id, urls_to_visit)
#
create_urls_to_visit_file("history_scripts/hedgedoc_documents_to_visit.url", urls_to_visit)
def
process_archive_export
(
archive_file
,
instance_url
,
lookup_map
,
session_id
,
urls_to_visit
):
# iterate over files in archive
with
ZipFile
(
archive_file
)
as
zf
:
print
(
"
Now scanning your provided archive file containing the documents you are the owner of
"
)
print
(
"
If you visited your own document via a, e.g.,
\"
codi-instance.tld/my_
own_path
\"
)
"
+
print
(
"
If you visited your own document via a, e.g.,
\"
codi-instance.tld/my_
specified_free_url
\"
"
+
"
this script tries to migrate it to the HedgeDoc instance at
\"
hedgedoc-instance.tld/my_own_path
\"
"
)
print
(
"
If this is not possible, a new random URL for the document will be created
"
)
for
file
in
zf
.
namelist
():
...
...
@@ -65,7 +64,7 @@ def process_archive_export(archive_file, instance_url, lookup_map, session_id, u
if
document_title
in
lookup_map
:
print
(
f
"
You visited your own document
\"
{
document_title
}
\"
.md
)
via the identifier/path
"
+
f
"
You visited your own document
\"
{
document_title
}
.md
\"
via the identifier/path
"
+
f
"
\"
{
lookup_map
[
document_title
]
}
\"
"
)
print
(
f
"
Trying to migrate this document and make it available under the already visited path
"
)
try
:
...
...
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