Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.d.ts 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /// <reference types="node" />
  2. import { EventEmitter } from 'events';
  3. import { ChildProcess, SpawnOptions } from 'child_process';
  4. import { Readable, Writable } from 'stream';
  5. export interface Options extends SpawnOptions {
  6. mode?: 'text' | 'json' | 'binary';
  7. formatter?: (param: string) => any;
  8. parser?: (param: string) => any;
  9. stderrParser?: (param: string) => any;
  10. encoding?: string;
  11. pythonPath?: string;
  12. /**
  13. * see https://docs.python.org/3.7/using/cmdline.html
  14. */
  15. pythonOptions?: string[];
  16. /**
  17. * overrides scriptPath passed into PythonShell constructor
  18. */
  19. scriptPath?: string;
  20. /**
  21. * arguments to your program
  22. */
  23. args?: string[];
  24. }
  25. export declare class PythonShellError extends Error {
  26. traceback: string | Buffer;
  27. exitCode?: number;
  28. }
  29. /**
  30. * An interactive Python shell exchanging data through stdio
  31. * @param {string} script The python script to execute
  32. * @param {object} [options] The launch options (also passed to child_process.spawn)
  33. * @constructor
  34. */
  35. export declare class PythonShell extends EventEmitter {
  36. scriptPath: string;
  37. command: string[];
  38. mode: string;
  39. formatter: (param: string | Object) => any;
  40. parser: (param: string) => any;
  41. stderrParser: (param: string) => any;
  42. terminated: boolean;
  43. childProcess: ChildProcess;
  44. stdin: Writable;
  45. stdout: Readable;
  46. stderr: Readable;
  47. exitSignal: string;
  48. exitCode: number;
  49. private stderrHasEnded;
  50. private stdoutHasEnded;
  51. private _remaining;
  52. private _endCallback;
  53. static defaultPythonPath: string;
  54. static defaultOptions: Options;
  55. /**
  56. * spawns a python process
  57. * @param scriptPath path to script. Relative to current directory or options.scriptFolder if specified
  58. * @param options
  59. */
  60. constructor(scriptPath: string, options?: Options);
  61. static format: {
  62. text: (data: any) => string;
  63. json: (data: any) => string;
  64. };
  65. static parse: {
  66. text: (data: any) => string;
  67. json: (data: string) => any;
  68. };
  69. /**
  70. * checks syntax without executing code
  71. * @param {string} code
  72. * @returns {Promise} rejects w/ stderr if syntax failure
  73. */
  74. static checkSyntax(code: string): Promise<{}>;
  75. static getPythonPath(): string;
  76. /**
  77. * checks syntax without executing code
  78. * @param {string} filePath
  79. * @returns {Promise} rejects w/ stderr if syntax failure
  80. */
  81. static checkSyntaxFile(filePath: string): Promise<string>;
  82. /**
  83. * Runs a Python script and returns collected messages
  84. * @param {string} scriptPath The path to the script to execute
  85. * @param {Options} options The execution options
  86. * @param {Function} callback The callback function to invoke with the script results
  87. * @return {PythonShell} The PythonShell instance
  88. */
  89. static run(scriptPath: string, options?: Options, callback?: (err?: PythonShellError, output?: any[]) => any): PythonShell;
  90. /**
  91. * Runs the inputted string of python code and returns collected messages. DO NOT ALLOW UNTRUSTED USER INPUT HERE!
  92. * @param {string} code The python code to execute
  93. * @param {Options} options The execution options
  94. * @param {Function} callback The callback function to invoke with the script results
  95. * @return {PythonShell} The PythonShell instance
  96. */
  97. static runString(code: string, options?: Options, callback?: (err: PythonShellError, output?: any[]) => any): PythonShell;
  98. static getVersion(pythonPath?: string): Promise<{
  99. stdout: string;
  100. stderr: string;
  101. }>;
  102. static getVersionSync(pythonPath?: string): string;
  103. /**
  104. * Parses an error thrown from the Python process through stderr
  105. * @param {string|Buffer} data The stderr contents to parse
  106. * @return {Error} The parsed error with extended stack trace when traceback is available
  107. */
  108. private parseError;
  109. /**
  110. * Sends a message to the Python shell through stdin
  111. * Override this method to format data to be sent to the Python process
  112. * @param {string|Object} data The message to send
  113. * @returns {PythonShell} The same instance for chaining calls
  114. */
  115. send(message: string | Object): this;
  116. /**
  117. * Parses data received from the Python shell stdout stream and emits "message" events
  118. * This method is not used in binary mode
  119. * Override this method to parse incoming data from the Python process into messages
  120. * @param {string|Buffer} data The data to parse into messages
  121. */
  122. receive(data: string | Buffer): this;
  123. /**
  124. * Parses data received from the Python shell stderr stream and emits "stderr" events
  125. * This method is not used in binary mode
  126. * Override this method to parse incoming logs from the Python process into messages
  127. * @param {string|Buffer} data The data to parse into messages
  128. */
  129. receiveStderr(data: string | Buffer): this;
  130. private receiveInternal;
  131. /**
  132. * Closes the stdin stream, which should cause the process to finish its work and close
  133. * @returns {PythonShell} The same instance for chaining calls
  134. */
  135. end(callback: (err: PythonShellError, exitCode: number, exitSignal: string) => any): this;
  136. /**
  137. * Closes the stdin stream, which should cause the process to finish its work and close
  138. * @returns {PythonShell} The same instance for chaining calls
  139. */
  140. terminate(signal?: string): this;
  141. }