#!/usr/bin/python
import os
import sys
#import subprocess

# Parameters:
# TODO parametrize:
docnaet_path = 'C:\\Docnaet\\FileStore'
docnaet_log = 'C:\\Docnaet\\Log\\docnaet.log'
f_log = open(docnaet_log, 'a')

if len(sys.argv) != 2:
    f_log.write('Not all parameters: %s\n' % (sys.argv))
    sys.exit()

# -----------------------------------------------------------------------------
# Extract operation from arguments:
# -----------------------------------------------------------------------------
# Format: docnaet://[operation]parameters
argument = sys.argv[1].split('//')[-1].split(']')
operation = argument[0][1:] # remove [
parameter = argument[1][:-1] # remove /

# -----------------------------------------------------------------------------
# Web Services:
# -----------------------------------------------------------------------------
if operation == 'open':
    # Extract parameters:
    parameters = parameter.split('-')
    protocol_id = parameters[0]
    document_id = parameters[1]
    
    # real: document = os.path.join(docnaet_path, document_id)
    # temp:
    document = os.path.join(docnaet_path, protocol_id, document_id) 
    command = 'start %s' % document
    f_log.write('Command %s: %s\n' % (operation, command))
    try:
        os.system(command)
    except:
        f_log.write('Error launch command %s\n' % (sys.exc_info(), ))
    
elif operation == 'home':
    pass # TODO

@@ -32,16 +32,57 @@
 ort sys%0A
+from datetime import datetime, timedelta%0A
 #import 
@@ -93,16 +93,18 @@
 rocess%0A%0A
+%0A%0A
 # Parame
@@ -245,16 +245,71 @@
 og, 'a')
+%0Adate = datetime.now().strftime('%25Y-%25m-%25d %25H:%25M:%25S.%25f')
 %0A%0Aif len
@@ -342,16 +342,27 @@
 .write('
+%25s %5BERROR%5D 
 Not all 
@@ -378,24 +378,30 @@
 s: %25s%5Cn' %25 (
+date, 
 sys.argv))%0A 
@@ -1317,15 +1317,17 @@
 te('
-Command
+%25s %5BINFO%5D
  %25s:
@@ -1336,16 +1336,22 @@
 s%5Cn' %25 (
+date, 
 operatio
@@ -1436,20 +1436,24 @@
 te('
-Error launch
+%25s %5BERROR%5D Wrong
  com
@@ -1466,16 +1466,22 @@
 s%5Cn' %25 (
+date, 
 sys.exc_
@@ -1486,18 +1486,16 @@
 c_info()
-, 
 ))%0A    %0A

add log better