Skip to content

Commit

Permalink
[nrf noup] Fix generate zap sript on windows
Browse files Browse the repository at this point in the history
Usage of generate.py script is not possible on windows
due to fcntl package available onlu on unix pyhton packages
using I/O control on descriptor file is not needed on windows.
This change enhance script to use fcntl on non-window system.
  • Loading branch information
doublemis1 committed Jul 6, 2023
1 parent d6ddd68 commit b5fbf81
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions scripts/tools/zap/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#

import argparse
import fcntl
import platform
import json
import os
import shutil
Expand All @@ -30,6 +30,13 @@

from zap_execution import ZapTool

def isWindows():
return platform.system() == "Windows"

# fcntl is not supported on widows platfrom due to lack of necessity of I/O control on file descriptor
if not isWindows():
import fcntl


@dataclass
class CmdLineArgs:
Expand Down Expand Up @@ -287,16 +294,17 @@ def __init__(self, path):
self.lock_file = None

def __enter__(self):
if not self.lock_file_path:
# fcntl is not supported on widows platfrom due to lack of necessity of I/O control on file descriptor
if not self.lock_file_path or isWindows():
return

self.lock_file = open(self.lock_file_path, 'wb')
fcntl.lockf(self.lock_file, fcntl.LOCK_EX)


def __exit__(self, *args):
if not self.lock_file:
# fcntl is not supported on widows platfrom due to lack of necessity of I/O control on file descriptor
if not self.lock_file or isWindows():
return

fcntl.lockf(self.lock_file, fcntl.LOCK_UN)
self.lock_file.close()
self.lock_file = None
Expand Down

0 comments on commit b5fbf81

Please sign in to comment.