मुख्य सामग्री पर जाएँ

कंटेंट एक्सपोर्ट और इम्पोर्ट

Glasswall समर्थित फ़ाइल प्रकारों के लिए content items को export और import करने की क्षमता प्रदान करता है। इससे processed files के internal components को अतिरिक्त processing के लिए, Glasswall Embedded Engine domain के बाहर, external processes और applications के लिए उपलब्ध कराया जा सकता है। Export होने के बाद, Glasswall Engine components को import करके files को फिर से compose करने से पहले इन components को externally validate किया जा सकता है।

फ़ाइलों को Glasswall Embedded Engine द्वारा दो बार प्रोसेस किया जाना चाहिए; एक बार उस पैकेज को निकालने के लिए जिसमें किसी फ़ाइल को बनाने वाले घटक होते हैं (export), और दूसरी बार बाहरी रूप से विश्लेषित और/या संशोधित घटकों को वापस फ़ाइल में एकीकृत करने के लिए (import)। Content Export & Import देखें।

फ़ाइलों को किसी file path से या memory में export_file method का उपयोग करके अलग-अलग export किया जा सकता है, या किसी directory की सभी फ़ाइलों को export_directory method का उपयोग करके export किया जा सकता है।

उदाहरण

Export

फ़ाइल पथ से फ़ाइल पथ में Export

import glasswall


# Load the Glasswall Editor library
editor = glasswall.Editor(r"C:\gwpw\libraries\10.0")

# Use the default policy to export a file, writing the export archive to a new path
editor.export_file(
input_file=r"C:\gwpw\input\TestFile_11.doc",
output_file=r"C:\gwpw\output\editor\export_f2f\TestFile_11.doc.zip",
)

फ़ाइल पथ से मेमोरी में Export

export_file exported archive फ़ाइल के bytes लौटाता है। नीचे दिया गया उदाहरण export_archive वेरिएबल असाइन करना और Editor export archive की शुरुआत की सामग्री की जाँच करना दर्शाता है।

import glasswall


# Load the Glasswall Editor library
editor = glasswall.Editor(r"C:\gwpw\libraries\10.0")

# Use the default policy to export a file
export_archive = editor.export_file(
input_file=r"C:\gwpw\input\TestFile_11.doc",
)

assert export_archive[:8] == b'PK\x03\x04\x14\x00\x0e\x00'

मेमोरी से Export

import glasswall


# Load the Glasswall Editor library
editor = glasswall.Editor(r"C:\gwpw\libraries\10.0")

# Read file from disk to memory
with open(r"C:\gwpw\input\TestFile_11.doc", "rb") as f:
input_bytes = f.read()

# Use the default policy to export a file
export_archive = editor.export_file(
input_file=input_bytes,
)

assert export_archive[:8] == b'PK\x03\x04\x14\x00\x0e\x00'

किसी डायरेक्टरी में फ़ाइलों को Export करें

import glasswall


# Load the Glasswall Editor library
editor = glasswall.Editor(r"C:\gwpw\libraries\10.0")

# Use the default policy to export a directory of files, writing the export archives to a new directory.
editor.export_directory(
input_directory=r"C:\gwpw\input",
output_directory=r"C:\gwpw\output\editor\export_directory"
)

ऐसी डायरेक्टरी में फ़ाइलों को Export करें जिसमें unsupported फ़ाइल प्रकार हो सकते हैं

Glasswall Python wrapper का डिफ़ॉल्ट व्यवहार यह है कि यदि processing विफल हो जाए, तो वह संबंधित exception raise करता है (देखें: glasswall.libraries.editor.errors)। raise_unsupported=False पास करने से exception raise होने से रोका जाएगा, और यह तब उपयोगी हो सकता है जब आप ऐसी directory के साथ काम कर रहे हों जिसमें supported और unsupported दोनों प्रकार की file types का मिश्रण हो, और जहाँ पहली विफलता पर terminate होने के बजाय जितनी संभव हो उतनी files को process करना वांछनीय हो।

import glasswall


# Load the Glasswall Editor library
editor = glasswall.Editor(r"C:\gwpw\libraries\10.0")

# Use the default policy to export a directory of files, writing the export archives to a new directory.
editor.export_directory(
input_directory=r"C:\gwpw\input_with_unsupported_file_types",
output_directory=r"C:\gwpw\output\editor\export_directory_unsupported",
raise_unsupported=False
)

कस्टम content management policy का उपयोग करके किसी डायरेक्टरी में फ़ाइलों को Export करें

glasswall.content_management.policies.Editor का उपयोग करते हुए:

import glasswall


# Load the Glasswall Editor library
editor = glasswall.Editor(r"C:\gwpw\libraries\10.0")

# Use a custom Editor policy to export all files in the input directory
# and write them to export_directory_custom directory. Write streams as
# ".xml" instead of the default interchange_type, ".sisl". Export embedded
# images as ".xml" instead of their default image file type.
editor.export_directory(
input_directory=r"C:\gwpw\input",
output_directory=r"C:\gwpw\output\editor\export_directory_custom",
content_management_policy=glasswall.content_management.policies.Editor(
default="sanitise",
config={
"sysConfig": {
"interchange_type": "xml",
"export_embedded_images": "true",
},
}
),
raise_unsupported=False
)

फ़ाइल format के आधार पर शर्तानुसार directory में files export करें

नीचे दिया गया उदाहरण कई file formats वाली nested directory से केवल doc और docx files को process करना दर्शाता है।

import os

import glasswall


# Load the Glasswall Editor library
editor = glasswall.Editor(r"C:\gwpw\libraries\10.0")

input_directory = r"C:\gwpw\input"
output_directory = r"C:\gwpw\output\editor\export_directory_file_format"

# Iterate relative file paths from input_directory
for relative_file in glasswall.utils.list_file_paths(input_directory, absolute=False):
# Construct absolute paths
input_file = os.path.join(input_directory, relative_file)
output_file = os.path.join(output_directory, relative_file + ".zip")

# Get the file type of the file
file_type = editor.determine_file_type(
input_file=input_file,
as_string=True,
raise_unsupported=False
)

# Export only doc and docx files
if file_type in ["doc", "docx"]:
editor.export_file(input_file, output_file)


Import

Export archives को किसी file path से या memory में import_file method का उपयोग करके अलग-अलग import किया जा सकता है, या किसी directory से सभी export archives को import_directory method का उपयोग करके import किया जा सकता है।

File path से file path में import करें

import glasswall


# Load the Glasswall Editor library
editor = glasswall.Editor(r"C:\gwpw\libraries\10.0")

# Use the default policy to import an export archive, writing the imported file to a new path
editor.import_file(
input_file=r"C:\gwpw\output\editor\export_f2f\TestFile_11.doc.zip",
output_file=r"C:\gwpw\output\editor\import_f2f\TestFile_11.doc",
)

फ़ाइल path से memory में इम्पोर्ट करें

import_file इम्पोर्ट की गई फ़ाइल के bytes लौटाता है। नीचे दिया गया उदाहरण file_bytes वेरिएबल असाइन करना और Editor export archive की शुरुआत की सामग्री की जाँच करना दर्शाता है।

import glasswall


# Load the Glasswall Editor library
editor = glasswall.Editor(r"C:\gwpw\libraries\10.0")

# Use the default policy to import an export archive
file_bytes = editor.import_file(
input_file=r"C:\gwpw\output\editor\export_f2f\TestFile_11.doc.zip",
)

assert file_bytes[:8] == b'\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1'

memory से इम्पोर्ट करें

import glasswall


# Load the Glasswall Editor library
editor = glasswall.Editor(r"C:\gwpw\libraries\10.0")

# Read file from disk to memory
with open(r"C:\gwpw\output\editor\export_f2f\TestFile_11.doc.zip", "rb") as f:
export_archive_bytes = f.read()

# Use the default policy to import an export archive
file_bytes = editor.import_file(
input_file=export_archive_bytes,
)

assert file_bytes[:8] == b'\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1'

किसी directory में फ़ाइलें इम्पोर्ट करें

import glasswall


# Load the Glasswall Editor library
editor = glasswall.Editor(r"C:\gwpw\libraries\10.0")

# Use the default policy to import a directory of export archives, writing the import archives to a new directory.
editor.import_directory(
input_directory=r"C:\gwpw\output\editor\export_directory",
output_directory=r"C:\gwpw\output\editor\import_directory"
)

ऐसी directory में फ़ाइलें इम्पोर्ट करें जिसमें unsupported file types हो सकते हैं

Glasswall Python wrapper का डिफ़ॉल्ट व्यवहार यह है कि यदि processing विफल हो जाए, तो वह संबंधित exception raise करता है (देखें: glasswall.libraries.editor.errors)। raise_unsupported=False पास करने से exception raise होने से रोका जाएगा, और यह तब उपयोगी हो सकता है जब आप ऐसी directory के साथ काम कर रहे हों जिसमें supported और unsupported दोनों प्रकार की file types का मिश्रण हो, और जहाँ पहली विफलता पर terminate होने के बजाय जितनी संभव हो उतनी files को process करना वांछनीय हो।

import glasswall


# Load the Glasswall Editor library
editor = glasswall.Editor(r"C:\gwpw\libraries\10.0")

# Use the default policy to export a directory of export archives, writing the export archives to a new directory.
editor.import_directory(
input_directory=r"C:\gwpw\output\editor\export_directory_unsupported",
output_directory=r"C:\gwpw\output\editor\import_directory_unsupported",
raise_unsupported=False
)

कस्टम content management policy का उपयोग करके किसी डायरेक्टरी में फ़ाइलें इम्पोर्ट करें

glasswall.content_management.policies.Editor का उपयोग करते हुए:

import glasswall


# Load the Glasswall Editor library
editor = glasswall.Editor(r"C:\gwpw\libraries\10.0")

# Use a custom Editor policy to import all files in the export directory
# and write them to import_directory_custom directory. Read streams as
# ".xml" instead of the default interchange_type, ".sisl".
editor.import_directory(
input_directory=r"C:\gwpw\output\editor\export_directory_custom",
output_directory=r"C:\gwpw\output\editor\import_directory_custom",
content_management_policy=glasswall.content_management.policies.Editor(
default="sanitise",
config={
"sysConfig": {
"interchange_type": "xml",
},
}
),
raise_unsupported=False
)

फ़ाइल फ़ॉर्मैट के आधार पर शर्तानुसार किसी डायरेक्टरी में फ़ाइलें इम्पोर्ट करें

नीचे दिया गया उदाहरण कई file formats वाली nested directory से केवल doc और docx files को process करना दर्शाता है।

import os

import glasswall


# Load the Glasswall Editor library
editor = glasswall.Editor(r"C:\gwpw\libraries\10.0")

input_directory = r"C:\gwpw\output\editor\export_directory_file_format"
output_directory = r"C:\gwpw\output\editor\import_directory_file_format"

# Iterate relative file paths from input_directory
for relative_file in glasswall.utils.list_file_paths(input_directory, absolute=False):
# Construct absolute paths
input_file = os.path.join(input_directory, relative_file)
output_file = os.path.join(output_directory, os.path.splitext(relative_file)[0])

# Get the file type of the file
file_type = editor.determine_file_type(
input_file=input_file,
as_string=True,
raise_unsupported=False
)

# Import only doc.zip and docx.zip files
if file_type == "zip" and input_file.endswith(("doc.zip", "docx.zip",)):
editor.import_file(input_file, output_file)


Export/Import और Analyse

ये उच्च-स्तरीय फ़ंक्शन आपको एक ही session के भीतर Export या Import चलाने और analysis report जनरेट करने देते हैं। अधिक जानकारी के लिए, नीचे दिए गए documentation links देखें।