How to enable console scripts in Django? - python-3.x

Running Python 3.6 on Redhat.
I've installed an extremely complicated project. 5 engineers worked on this for years, but they are all gone now, so I've no one to ask.
At the top level of the project:
setup.py
Inside of that:
# Python command line utilities will be installed in a PATH-accessible bin/
entry_points={
'console_scripts': [
'blueflow-connector-aims = app.connectors.aims.__main__:cli',
'blueflow-connector-csv = app.connectors.csv.__main__:cli',
'blueflow-connector-discovery = app.connectors.discovery.__main__:cli',
'blueflow-connector-fingerprint = app.connectors.fingerprint.__main__:cli',
'blueflow-connector-mock = app.connectors.mock.__main__:cli',
'blueflow-connector-nessusimport = app.connectors.nessusimport.nessusimport:cli',
'blueflow-connector-netflow = app.connectors.netflow.__main__:cli',
'blueflow-connector-passwords = app.connectors.passwords.__main__:cli',
'blueflow-connector-portscan = app.connectors.portscan.__main__:cli',
'blueflow-connector-pulse = app.connectors.pulse.pulse:cli',
'blueflow-connector-qualysimport = app.connectors.qualysimport.qualysimport:cli',
'blueflow-connector-sleep = app.connectors.sleep.__main__:cli',
'blueflow-connector-splunk = app.connectors.splunk.__main__:cli',
'blueflow-connector-tms = app.connectors.tms.__main__:cli',
]
},
I ran:
pipenv shell
to create a shell.
If I try a console script:
blueflow-connector-mock
I get:
bash: blueflow-connector-mock: command not found
That goes to bash which is clearly a mistake. I also tried:
python3 blueflow-connector-mock
which gives me:
python3: can't open file 'blueflow-connector-mock': [Errno 2] No such file or directory
How do I activate these console scripts, so they will actually run?

Related

Python list not sorting when called from inside a bash script

I am trying to print a custom help message for a bash script. Inside the script, I call a function that then uses python to parse the script, find the functions and the function help string, and then print them. This all works. But, when I try to sort the list of tuples that contains the function name and help string, the sort seems to be ignored. Similar code works as expected in a pure python environment.
Edit: Just noticed I tried the sort two different ways. AFAIK either should have sorted the list, but neither worked.
Edit again: see the accepted answer below for code that actually works. I need to remember to reread my problem code in the morning ;)
SCRIPT_PATH=$(realpath $0)
function build() { ## builds source and wheel package
echo "foo"
}
function aa() { ## foo
echo "foo"
}
function release() { ## package and upload a release
echo "foo"
}
function project:init:all() { ## Initialize a venv, update pip, wheels, and setuptools, and install both requirements files.
echo "foo"
}
function venv:init() { ## makes a venv in the project directory
echo "foo"
}
function print:help() {
echo $SCRIPT_PATH
python3 - << EOF
from pathlib import Path
from operator import itemgetter
import re
script_path = Path("$SCRIPT_PATH")
with open(script_path) as file:
for line in file:
match = re.match(r'^function\s*([a-zA-Z0-9\:-]*)\(\)\s*{\s*##\s*(.*)', line)
matches = []
if match is not None:
target, help = match.groups()
matches.append((target,help))
#for help_line in sorted(matches,key=lambda func: func[1]):
matches.sort(key=itemgetter(1))
for help_line in matches:
print(" {0:20} {1}".format(target,help))
EOF
}
results in:
build builds source and wheel package
aa foo
release package and upload a release
project:init:all Initialize a venv, update pip, wheels, and setuptools, and install both requirements files.
venv:init makes a venv in the project directory
but I expected:
aa foo
build builds source and wheel package
project:init:all Initialize a venv, update pip, wheels, and setuptools, and install both requirements files.
release package and upload a release
venv:init makes a venv in the project directory
You need to get all the functions, then sort and print :
function print:help() {
echo $SCRIPT_PATH
python3 - << EOF
from pathlib import Path
from operator import itemgetter
import re
script_path = Path("$SCRIPT_PATH")
with open(script_path) as file:
functions = []
for line in file:
match = re.match(r'^function\s*([a-zA-Z0-9\:-]*)\(\)\s*{\s*##\s*(.*)', line)
if match is not None:
functions.append(match.groups())
for target, help in sorted(functions):
print(" {0:20} {1}".format(target,help))
EOF
}

cx_freeze - How to change reference to lib

Building an Python application with cx_freeze.
from cx_Freeze import setup, Executable
_packages = []
_excludes = []
_include_files = [...]
buildOptions = dict(packages = _packages, enter code here`excludes = _excludes, include_files = _include_files, build_exe = '<app name>')
setup(name = '<app name>',
version = <version>,
description = '<description>',
options = dict(build_exe = buildOptions),
executables = [Executable('<app name>.py',
targetName = '<app name>',
icon = '<app name>.png')])
Attempting to install an application build with cx_freeze on Linux in /usr/bin/ with application resources in /usr/share/.
Of course this results in:
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ModuleNotFoundError: No module name 'encodings'
Current thread 0x0... (most recent call first):...
I think I need to set/change the default location of the lib folder but I have been unable to figure out how to do that. It's entirely possible that I might be on the completely wrong track.
I'm trying to avoid using bbfreeze.
After reviewing the code I believe what I want to do is not possible. The 'lib' directory is hard coded in cx_freeze.

Watson LT SDK create_model() fails if forced_glossary is in /tmp/ folder

The Watson LT create_model() fails if the glossary file is in a folder outside the local dir. Kinda crazy... why would location of TMX file matter?
It works if I just the basename (CustomModel_xxxx.tmx) w/o a folder.
If fails with error below if I use /tmp/CustomModel_xxxx.tmx
I don't want tmx files created in my code base...
Running on Py 3.5. in a jupyter notebook
WatsonApiException: Error: Error while uploading file(s). Please try again!, Code: 500 , X-dp-watson-tran-id: gateway02-898567107 , X-global-transaction-id: ffea405d5bfc5adf358f0bc3
CODE:
from watson_developer_cloud import LanguageTranslatorV3
lt = LanguageTranslatorV3(....)
DIR = kwargs.get('folder','/tmp')
bn = 'CustomModel_%d.tmx' % os.getpid()
# Fails
tmx_name = os.path.join(DIR, bn)
# Is ok
#tmx_name = bn
with open(tmx_FN,'r', encoding='U8') as fio:
x = fio.read()
print("Read ok",)
r = lt.create_model(
base_model_id=model_id,
name = 'xxx',
**{'forced_glossary': fio}
)
I tried your example with Python 2.7 and it works fine on my system. My best guess is that you have some kind of permissions problem with /tmp on your system. Or maybe jupyter is remapping /tmp somehow. What happens if you run this as a standalone python app?

Scons -u option doesn't work?

Seems -u doesn't work on for me ( I am using scons-2.3.6).
To simplify the context, you can imagine my project structure like,
+root
+project
- bar.vcxproj (generated vs project)
-SConstruct
-bar.c
Inside SConstruct, I have put code like:
env_base = Environment()
...
env_base.StaticLibrary(target = 'bar', source = ['bar.c'])
...
If I execute command "scons" in root folder, everything works perfectly.
But If I execute command "scons -u" in project folder, scons can find my SConstruct up in root folder, but no file get compiled.
BTW : The reason for me to execute "scons -u" in project folder is because I want to put the generated vsproj in projet folder and use BuildCommandLine to compile the project.
I guess I didn't use "-u" correctly, what will be the elegant solution for my situation?
1st edit:
As bdbaddog asked, I have put the SConstruct here:
def BuildConfig(env, config):
env.Append(CCFLAGS = '/W 4')
env.Append(CCFLAGS = '/WX')
if config == "debug":
env.Append(CCFLAGS = '/DEBUG')
#env.Append(CCFLAGS = '-Zi /Fd${TARGET}.pdb')
env.Append(CCFLAGS = '/Z7')
elif config == "release":
pass
env_base = Environment()
lib = env_base.StaticLibrary(target = 'bar', source = ['bar.c'])
opts=Variables()
opts.Add('target', 'Compile Target (debug/release).', "debug")
# there is more in my project....
opts.Update(env_base) # update environment
# here I want to use my own command to build the project, so it can support different build option that is defined by me.
env_base['MSVSBUILDCOM'] = "scons -u target=$(Configuration)"
target = env_base["target"]
BuildConfig(env_base, env_base['target'])
env_base.MSVSProject(target = "project\\bar" + env_base['MSVSPROJECTSUFFIX'],
srcs = ["..\\bar.c"],
incs = [],
localincs = "",
resources = "",
misc = "",
buildtarget = lib,
variant = ['debug'],
auto_build_solution=0)
SCons only builds files under the current directory by default.
If you you wanted to only build files in a certain directory (for which there are rules that build the targets there), you can invoke SCons as follows:
scons the_target_directory_I_want_to_build
Though this may cause sources for targets in that directory to also be built.

Python 3.3:cx_freeze & pyserial: cannot import traceback module

I'm newbie in cx_freeze. I'm triing to make an executable from python 3.3 script that uses "time", "serial" and "tkinter".
Cx_freeze run without any errors, but starting the exe file is resulting with error:
cannot import traceback module
Exception: No module named 're'
Original Exception: No module named 'serial'
I have this setup.py of cx_freeze
from cx_Freeze import setup, Executable
includes = ["serial", "tkinter"]
excludes = []
packages = []
path = []
GUI2Exe_Target_1 = Executable(
# what to build
script ='test6.1.py',
initScript = None,
base = 'Win32GUI',
targetDir = r"dist",
targetName = "bludiste2.exe",
compress = True,
copyDependentFiles = True,
appendScriptToExe = False,
appendScriptToLibrary = False,
icon = None
)
Does anyone know, how to solve it, please?
Thank you.
The first two lines are a bug that will be fixed in the next version of cx_Freeze. If you stick an import re in your script, you'll see the correct error message.
The last line is your real problem - that means it didn't find the serial module when you froze it. Check where pyserial is installed on your computer.

Resources