comet.file

The file module provides file related helper methods.

Methods

comet.file.download(URL, path, replaceExisting=False, options=[])

Load a file defined by an URL. The new file or folder will get name which is specified in the target path. cURL is used for the download.

Parameters:
  • URL (str) – Complete URL to download

  • path (str) – Full target path

  • replaceExisting (bool) – When the target already exists, should it be overwritten?

  • options (dict[str, int | str | list[str]]) –

    Additional cURL options.

    Keys must be str. Value types depend on the provided keys.

    The data type Path is also a str but with the addition that $-Aliases at the beginning of the path are automatically replaced.

    Global and Database tags like <folder> or <sessionId> in str and Path values are automatically replaced by their current values.

    A full description of cURL parameter can be found here.

    Defaults
    Defaults

    Key

    Type

    Value

    ’POSTREDIR’

    int

    7 (CURL_REDIR_POST_ALL)

    ’FOLLOWLOCATION’

    int

    1

    ’FAILONERROR’

    int

    1

    ’USERAGENT’

    str (Path)

    ’ ‘ (blank)

    ’REDIR_PROTOCOLS’

    int

    -1 (CURLPROTO_ALL)

    ’AUTOREFERER’

    int

    1

    ’CONNECTTIMEOUT’

    int

    3

    ’SSL_VERIFYHOST’

    int

    0

    ’SSL_VERIFYPEER’

    int

    0

    ’SSL_SSLCERTTYPE’

    str

    ’PEM’

    ’SSL_CAINFO’

    str

    ’’

    Abbrevations
    Abbrevations

    Key

    Type

    Description

    ’+’ or ‘SECURE’

    int

    Download with activated certificate check (‘SSL_VERIFYPEER’ = 1).

    The value is ignored and should be 0.

    Options
    Options

    Key

    Type

    Description

    ’POSTREDIR’

    int

    ’ABSTRACT_UNIX_SOCKET’

    str

    ’ACCEPTTIMEOUT_MS’

    int

    ’ACCEPT_ENCODING’

    str

    ’ADDRESS_SCOPE’

    int

    ’APPEND’

    int

    ’AUTOREFERER’

    int

    ’CAINFO’

    str (Path)

    Path of a valid PEM file.

    The certificate contained in the file is appended to the user’s current certificate list and the ‘AUTOREFERER’ option is automatically enabled.

    If the file does not exist, the option is ignored.

    Please note that the current user certificates are loaded only once for performance reasons. Any subsequent changes to the certificate files will only be registered when the program is restarted.

    ’CERTINFO’

    int

    ’CONNECTTIMEOUT’

    int

    ’CONNECTTIMEOUT_MS’

    int

    ’COOKIE’

    str

    ’COOKIEFILE’

    str (Path)

    ’COPYPOSTFIELDS’

    str

    ’CRLF’

    int

    ’CRLFILE’

    str (Path)

    ’CUSTOMREQUEST’

    str

    ’DEFAULT_PROTOCOL’

    str

    ’DIRLISTONLY’

    int

    ’DNS_CACHE_TIMEOUT’

    int

    ’DNS_INTERFACE’

    str

    ’DNS_LOCAL_IP4’

    str

    ’DNS_LOCAL_IP6’

    str

    ’DNS_SERVERS’

    str

    ’DNS_USE_GLOBAL_CACHE’

    int

    ’EGDSOCKET’

    str

    ’FILETIME’

    int

    ’FTPPORT’

    str

    ’FTPSSLAUTH’

    int

    ’FTP_ACCOUNT’

    str

    ’FTP_ALTERNATIVE_TO_USER’

    str

    ’FTP_CREATE_MISSING_DIRS’

    int

    ’FTP_FILEMETHOD’

    int

    ’FTP_RESPONSE_TIMEOUT’

    int

    ’FTP_SKIP_PASV_IP’

    int

    ’FTP_SSL_CCC’

    int

    ’FTP_USE_EPRT’

    int

    ’FTP_USE_EPSV’

    int

    ’FTP_USE_PRET’

    int

    ’GSSAPI_DELEGATION’

    int

    ’HEADER’

    str (Path)

    ’HEADEROPT’

    int

    ’HTTP200ALIASES’

    list [str]

    ’HTTPAUTH’

    int

    ’HTTPGET’

    int

    ’HTTPHEADER’

    list [str]

    ’HTTPPROXYTUNNEL’

    int

    ’HTTP_CONTENT_DECODING’

    int

    ’HTTP_TRANSFER_DECODING’

    int

    ’HTTP_VERSION’

    int

    ’IGNORE_CONTENT_LENGTH’

    int

    ’INTERFACE’

    str

    ’IPRESOLVE’

    int

    ’ISSUERCERT’

    str (Path)

    ’KEEP_SENDING_ON_ERROR’

    int

    ’KEYPASSWD’

    str

    ’KRBLEVEL’

    str

    ’LOCALPORT’

    int

    ’LOCALPORTRANGE’

    int

    ’LOGIN_OPTIONS’

    str

    ’LOW_SPEED_LIMIT’

    int

    ’LOW_SPEED_TIME’

    int

    ’MAIL_AUTH’

    str

    ’MAIL_FROM’

    str

    ’MAIL_RCPT’

    list [str]

    ’MAXCONNECTS’

    int

    ’MAXFILESIZE’

    int

    ’MAXFILESIZE_LARGE’

    int

    ’MAXREDIRS’

    int

    ’MAX_RECV_SPEED_LARGE’

    int

    ’MAX_SEND_SPEED_LARGE’

    int

    ’NEW_DIRECTORY_PERMS’

    int

    ’NEW_FILE_PERMS’

    int

    ’NOBODY’

    int

    ’NOPROXY’

    str

    ’PASSWORD’

    str

    ’PATH_AS_IS’

    int

    ’PINNEDPUBLICKEY’

    str

    ’PIPEWAIT’

    int

    ’PORT’

    int

    ’PREQUOTE’

    list [str]

    ’PRE_PROXY’

    str

    ’PROTOCOLS’

    int

    ’PROXY’

    str

    ’PROXYAUTH’

    int

    ’PROXYHEADER’

    list [str]

    ’PROXYPASSWORD’

    str

    ’PROXYPORT’

    int

    ’PROXYTYPE’

    int

    ’PROXYUSERNAME’

    str

    ’PROXYUSERPWD’

    str

    ’PROXY_CAINFO’

    str (Path)

    ’PROXY_CAPATH’

    str (Path)

    ’PROXY_CRLFILE’

    str (Path)

    ’PROXY_KEYPASSWD’

    str

    ’PROXY_SERVICE_NAME’

    str

    ’PROXY_SSLCERT’

    str

    ’PROXY_SSLCERTTYPE’

    str

    ’PROXY_SSLKEY’

    str (Path)

    ’PROXY_SSLKEYTYPE’

    str

    ’PROXY_SSLVERSION’

    int

    ’PROXY_SSL_CIPHER_LIST’

    str

    ’PROXY_SSL_OPTIONS’

    int

    ’PROXY_TLSAUTH_PASSWORD’

    str

    ’PROXY_TLSAUTH_TYPE’

    str

    ’PROXY_TLSAUTH_USERNAME’

    str

    ’PROXY_TRANSFER_MODE’

    int

    ’PUT’

    int

    ’QUOTE’

    list [str]

    ’RANDOM_FILE’

    str (Path)

    ’REDIR_PROTOCOLS’

    int

    ’REFERER’

    str

    ’RESOLVE’

    list [str]

    ’RESUME_FROM’

    int

    ’RESUME_FROM_LARGE’

    int

    ’RTSP_CLIENT_CSEQ’

    int

    ’RTSP_REQUEST’

    int

    ’RTSP_SERVER_CSEQ’

    int

    ’RTSP_SESSION_ID’

    str

    ’RTSP_STREAM_URI’

    str

    ’RTSP_TRANSPORT’

    str

    ’SERVICE_NAME’

    str

    ’SSH_AUTH_TYPES’

    int

    ’SSH_HOST_PUBLIC_KEY_MD5’

    str

    ’SSH_KNOWNHOSTS’

    str (Path)

    ’SSH_PRIVATE_KEYFILE’

    str (Path)

    ’SSH_PUBLIC_KEYFILE’

    str (Path)

    ’SSLCERT’

    str

    ’SSLCERTTYPE’

    str

    ’SSLENGINE’

    str

    ’SSLENGINE_DEFAULT’

    int

    ’SSLKEY’

    str (Path)

    ’SSLKEYTYPE’

    str

    ’SSLVERSION’

    int

    ’SSL_CIPHER_LIST’

    str

    ’SSL_ENABLE_ALPN’

    int

    ’SSL_ENABLE_NPN’

    int

    ’SSL_FALSESTART’

    int

    ’SSL_OPTIONS’

    int

    ’SSL_SESSIONID_CACHE’

    int

    ’SSL_VERIFYHOST’

    int

    ’SSL_VERIFYSTATUS’

    int

    ’SSL_VERIFYPEER’

    int

    ’SUPPRESS_CONNECT_HEADERS’

    INT

    ’TCP_FASTOPEN’

    int

    ’TCP_KEEPALIVE’

    int

    ’TCP_KEEPIDLE’

    int

    ’TCP_KEEPINTVL’

    int

    ’TCP_NODELAY’

    int

    ’TELNETOPTIONS’

    list [str]

    ’TFTP_BLKSIZE’

    int

    ’TFTP_NO_OPTIONS’

    int

    ’TIMECONDITION’

    int

    ’TIMEOUT’

    int

    ’TIMEOUT_MS’

    int

    ’TIMEVALUE’

    int

    ’TLSAUTH_PASSWORD’

    str

    ’TLSAUTH_TYPE’

    str

    ’TLSAUTH_USERNAME’

    str

    ’TRANSFERTEXT’

    int

    ’TRANSFER_ENCODING’

    int

    ’UNIX_SOCKET_PATH’

    str

    ’UNRESTRICTED_AUTH’

    int

    ’USERNAME’

    str

    ’USERPWD’

    str

    ’USE_SSL’

    int

    ’WILDCARDMATCH’

    int

    ’XOAUTH2_BEARER’

    str

Return type:

None

Raises:
Available:

InDesign® comet_pdf® Illustrator®

CScript:

file::download

comet.file.downloadWebImages(URLs, target=None, flags=0)

Parallel download of a list of Web Images.Parallel processing vastly speeds up the download process compared to loading the images individually.

Can be used to preload images e.g. before a product build-up to speed up the building process, if the images are known beforehand.

The images are stored in the same file that is used for the Web Images of a document. The //// URL markers supported in Web Images are supported here aswell.

If the URLs contain passwords, the option ‘kNoHash’ should be used, as the encryption of the passwords produces different results with each call and accordingly the hash code generated from the encrypted URL produces different file names with each call, even if the URL does not change.

If this function is used, it makes sense to make subsequent calls to CFrame.setImage() with the value 16 (suppress checking header) in the option ‘kUpdateFlags’.

Parameters:
  • URLs (list[str]) – List of image URLs.

  • target (CDocument | str | None) –

    Where to store the images.

    The parameter can type can be:

    • None:

      Use the script document (comet.gDocument) to determine the download path.

    • CDocument:

      Use this document to determine the download path.

    • str:

      Full path of the download folder. If the folder does not exist, it will be created.

  • flags (int) –

    Additional options.

    • 0: None

    • 1: Show progress bar, InDesign® only

Returns:

A list of results containing [URL, Local result file, Error Code]

Return type:

list[tuple[str, str, int]]

Raises:
  • TypeError – When parameter types are invalid

  • CometError

    • On internal error

    • When parameter target is None and comet.gDocument is None

Available:

InDesign® comet_pdf® Illustrator®

CScript:

file::download_webimages

comet.file.PDFCountPages(path, usePDFLib=False)
Parameters:
  • path (str) – Full path to a PDF file.

  • usePDFLib (bool) –

    Use PDFlib for querying?

    When True PDFLib is used for querying the page count.

    The use of PDFlib is subject to licensing. You will need a PDFlib + PDI license for PDFlib 10. Licenses can be purchased here. The license file must have the name licensekeys.txt and be located in the Plug-Ins folder of your InDesign® resp. in the program folder of comet_pdf.

    Illustrator® Not supported.

Returns:

The number of pages in the provided PDF.

Return type:

int

Raises:
Available:

InDesign® comet_pdf® Illustrator®

CScript:

file::pdf_count_pages

comet.file.getDataFile(ID, enabledOnly=True, autoResolve=True)

Get the (relative) path of a data file definition.

Parameters:
  • ID (int | str) – ID (int) or name (str) of the entry.

  • enabledOnly (bool) –

    Search only for activated entries?

    • True: The entry found must be activated.

    • False: The path of the first entry found is returned. Do not check whether this entry is activated.

  • autoResolve (bool) –

    Resolve full path for the result?

    • True: Incomplete result paths are calculated relative to the current XML data folder.

    • False: The path found is returned unchanged.

Returns:

(Relative) path of the data file alias.

Return type:

str

Raises:
  • TypeError – When parameter types are invalid

  • KeyError

    • When no entry is found.

    • When a deactivated entry is found, but parameter enabledOnly is True.

  • CometError – On internal error

Available:

InDesign® comet_pdf® Illustrator®

CScript:

file::getdatafile

comet.file.setDataFile(ID, value, stage=0, enabledOnly=False)

Change the path definition of a data file definition. If the entry is shown in the Settings panel list, this entry is also changed. File paths are automatically converted to relative paths if the file is located in the following folders:

  • Current desktop : $DESKTOP/…

  • Current document folder : $DOCUMENTS/…

  • Home directory : $HOME/…

  • Plug-ins folder : $PLUGINS/…

  • Comet plug-ins : $COMET/…

  • Comet cache : $CACHE/…

  • User settings folder : $PREFS/…

  • XML folder : $COMETDATA/…. In database and SOAP connections equal to $CACHE/…

Parameters:
  • ID (int | str) – ID (int) or name (str) of the entry.

  • value (str) – New value that is assigned to the entry. Incomplete path specifications always refer to the currently set data folder.

  • stage (int) –

    At which level should the path definition be changed?

    • 0: Global. The definition is changed for all users in the data pool. The change takes effect immediately. This option is not supported in PubServer connections!

    • 1: Local. The definition is changed locally and displayed in red in the ‘Settings’ panel. The entry remains unchanged in the data pool. This option has no effect in PubServer connections!

    • 2: Temporary. Only defined in batch jobs! Create or change a temporary definition of the given alias name. The specification of an ID is not supported here! The entries are not shown in the Settings panel! In contrast to local changes, this definition is also effective in PubServer connections.

      The definition covers definitions of the same name in the datapool. It is removed again when the data connection is disconnected. The definitions $DESKTOP, … must not be changed with the function!

    Illustrator® Not supported.

  • enabledOnly (bool) –

    Change entry only if it is active? This information is particularly important if there are several entries with the same alias name.

    • True: The entry found must be active so that it can be changed.

    • False: The entry found does not have to be active. If a name is specified, the first matching entry is changed.

Return type:

None

Raises:
  • TypeError – When parameter types are invalid

  • ValueError – When parameter stage has invalid value

  • KeyError

    • When no entry is found.

    • When a deactivated entry is found, but parameter enabledOnly is True.

  • CometError – On internal error

Available:

InDesign® comet_pdf® Illustrator®

CScript:

file::setdatafile