How to get function names of Linux Kernel files with pycparser? - pycparser

I created fake header files under pycparser/utils/fake_libc_include for every header found in kernel/sched/core.c and put
#include "_fake_defines.h"
#include "_fake_typedefs.h"
into them. A few other header files where missing, lot's of headers from kernel/sched/sched.h for example. So I added them too.
Preprocessed the whole stuff with
gcc -nostdinc -E -Ipycparser/utils/fake_libc_include ../kernel/sched/core.c > core_pp.c
which gave no error.
So I tried to get the function names
python3 examples/func_defs.py core_pp.c
but it gives me the error:
Traceback (most recent call last):
File "examples/func_defs.py", line 46, in <module>
show_func_defs(filename)
File "examples/func_defs.py", line 34, in show_func_defs
cpp_args=r'-Iutils/fake_libc_include')
File "/usr/local/lib/python3.4/dist-packages/pycparser/__init__.py", line 93, in parse_file
return parser.parse(text, filename)
File "/usr/local/lib/python3.4/dist-packages/pycparser/c_parser.py", line 151, in parse
debug=debuglevel)
File "/usr/local/lib/python3.4/dist-packages/pycparser/ply/yacc.py", line 331, in parse
return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
File "/usr/local/lib/python3.4/dist-packages/pycparser/ply/yacc.py", line 1181, in parseopt_notrack
tok = call_errorfunc(self.errorfunc, errtoken, self)
File "/usr/local/lib/python3.4/dist-packages/pycparser/ply/yacc.py", line 193, in call_errorfunc
r = errorfunc(token)
File "/usr/local/lib/python3.4/dist-packages/pycparser/c_parser.py", line 1721, in p_error
column=self.clex.find_tok_column(p)))
File "/usr/local/lib/python3.4/dist-packages/pycparser/plyparser.py", line 55, in _parse_error
raise ParseError("%s: %s" % (coord, msg))
pycparser.plyparser.ParseError: ../kernel/sched/cpupri.h:14:2: before: atomic_t
What am I doing wrong? I've tried the redis example from this blog entry and it worked.

Adding the headers is just one part of the solution - this helps the preprocessor resolve the #include statements.
The other part of the solution is adding types that the parser would expect to find there to _fake_typedefs. This way pycparser will know the identified is a type and will be able to parse the code properly.

Related

Pyinstaller no exe created, nothing in dist folder

When i try to run the pyinstall myFile.py, the build and dist folder are created, and the file myFIle.spec, but the dist folder is empty. In the shell I have a traceback at the end :
File "/home/indiana/anaconda3/bin/pyinstaller", line 11, in <module>
sys.exit(run())
File "/home/indiana/anaconda3/lib/python3.6/site-packages/PyInstaller/__main__.py", line 111, in run
run_build(pyi_config, spec_file, **vars(args))
File "/home/indiana/anaconda3/lib/python3.6/site-packages/PyInstaller/__main__.py", line 63, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "/home/indiana/anaconda3/lib/python3.6/site-packages/PyInstaller/building/build_main.py", line 838, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "/home/indiana/anaconda3/lib/python3.6/site-packages/PyInstaller/building/build_main.py", line 784, in build
exec(text, spec_namespace)
File "<string>", line 31, in <module>
File "/home/indiana/anaconda3/lib/python3.6/site-packages/PyInstaller/building/api.py", line 411, in __init__
strip_binaries=self.strip, upx_binaries=self.upx,
File "/home/indiana/anaconda3/lib/python3.6/site-packages/PyInstaller/building/api.py", line 196, in __init__
self.__postinit__()
File "/home/indiana/anaconda3/lib/python3.6/site-packages/PyInstaller/building/datastruct.py", line 158, in __postinit__
self.assemble()
File "/home/indiana/anaconda3/lib/python3.6/site-packages/PyInstaller/building/api.py", line 273, in assemble
pylib_name = os.path.basename(bindepend.get_python_library_path())
File "/home/indiana/anaconda3/lib/python3.6/posixpath.py", line 146, in basename
p = os.fspath(p)
TypeError: expected str, bytes or os.PathLike object, not NoneType
Futhermore, I have a warning during the process :
WARNING: Hidden import "PyQt5.sip" not found!
I'm more concern about the traceback ( since it seems it's not related to my code but more about the environment), so I wonder if somebody had seen this before and if someone has a kind of a solution.
Thanks in advance !

how do I set a turtle to an image

I am trying to set my image to a file, but when i run it i get
Exception in Tkinter callback Traceback (most recent call last):
File
"C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\lib\tkinter__init__.py",
line 1699, in call
return self.func(*args) File "C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\lib\turtle.py",
line 686, in eventfun
fun() File "C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\RPG.py",
line 20, in up
combat() File "C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\RPG.py",
line 57, in combat
enemy.shape(image) File "C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\lib\turtle.py",
line 2777, in shape
self.turtle._setshape(name) File "C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\lib\turtle.py",
line 2506, in _setshape
self._item = screen._createimage(screen._shapes["blank"]._data) File
"C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\lib\turtle.py",
line 723, in _createimage
return self.cv.create_image(0, 0, image=image) File "", line 1, in create_image File
"C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\lib\tkinter__init__.py",
line 2483, in create_image
return self._create('image', args, kw) File "C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\lib\tkinter__init__.py",
line 2474, in _create
*(args + self._options(cnf, kw))))
_tkinter.TclError: image "pyimage1" doesn't exist
when I have the file name clearly stated exactly where it is on my pc.
the code
import os
from turtle import Turtle,Screen
print(os.getcwd())
os.chdir('C:\\Users\\Travi\\Downloads')
screen.register_shape("Crawfish_attack.gif")
turtle = Turtle()
turtle.setimage("Crawfish_attack.gif")
thanks in advance
BTW the link is here
and the rest of the code all works and is not needed to be shown
Remove "\\Crawfish_attack" from the os.chdir() arguments. You need to path to the folder it is in, not the file. That is what the register_shape function will do is pull the exact file in that folder.
You were getting the error because you were trying to path to something (it was looking for a folder) that does not exist.
import os
from turtle import Turtle,Screen
print(os.getcwd())
os.chdir('C:\\Users\\Travi\\Downloads')
screen.register_shape("Crawfish_attack.gif")

Openerp_ Magento Integration/sync Error

Traceback (most recent call last):
File "/opt/openerp/server/openerp/addons/connector/queue/worker.py", line 123, in run_job
job.perform(session)
File "/opt/openerp/server/openerp/addons/connector/queue/job.py", line 492, in perform
self.result = self.func(session, *self.args, **self.kwargs)
File "/opt/openerp/server/openerp/addons/magentoerpconnect/unit/import_synchronizer.py", line 378, in import_record
importer.run(magento_id, force=force)
File "/opt/openerp/server/openerp/addons/magentoerpconnect/unit/import_synchroni zer.py", line 221, in run
self._import_dependencies()
File "/opt/openerp/server/openerp/addons/magentoerpconnect/sale.py", line 849, in _import_dependencies
'magento.product.product')
File "/opt/openerp/server/openerp/addons/magentoerpconnect/unit/import_synchronizer.py", line 124, in _import_dependency
importer.run(magento_id)
File "/opt/openerp/server/openerp/addons/magentoerpconnect/unit/import_synchronizer.py", line 206, in run
self.magento_record = self._get_magento_data()
File "/opt/openerp/server/openerp/addons/magentoerpconnect/unit/import_synchronizer.py", line 63, in _get_magento_data
return self.backend_adapter.read(self.magento_id)
File "/opt/openerp/server/openerp/addons/magentoerpconnect/product.py", line 278, in read
[int(id), storeview_id, attributes, 'id'])
File "/opt/openerp/server/openerp/addons/magentoerpconnect/product.py", line 243, in _call
return super(ProductProductAdapter, self)._call(method, arguments)
File "/opt/openerp/server/openerp/addons/magentoerpconnect/unit/backend_adapter.py", line 168, in _call
result = api.call(method, arguments)
File "/usr/local/lib/python2.7/dist-packages/magento-0.4-py2.7.egg/magento/api.py", line 161, in call
return self.client.call(self.session, resource_path, arguments)
File "/usr/lib/python2.7/xmlrpclib.py", line 1224, in __call__
return self.__send(self.__name, args)
File "/usr/lib/python2.7/xmlrpclib.py", line 1578, in __request
verbose=self.__verbose
File "/usr/lib/python2.7/xmlrpclib.py", line 1264, in request
return self.single_request(host, handler, request_body, verbose)
File "/usr/lib/python2.7/xmlrpclib.py", line 1297, in single_request
return self.parse_response(response)
File "/usr/lib/python2.7/xmlrpclib.py", line 1473, in parse_response
return u.close()
File "/usr/lib/python2.7/xmlrpclib.py", line 793, in close
raise Fault(**self._stack[0])
Fault: <Fault 3: 'Invalid api path.'>
I Am Unable To Integrated & Sync My Products From Magento To Openerp,I Have Used The CampToCamp's Add-on In The Openerp & Have Added The Module On Magento. I Have Used My Magento Server Link & Have Added Enough Test Products Yet The Products Aren't Syncing Due To The Above error As In The Jobs Tab In Openerp. Please Help Me Get Through Or Understand What Am I Doing Wrongly.
Thank You In Advance.
The problem was the integration module which was installed on my magento site didn't match the integration module on Openerp so all i needed to do was install both from the same vender and it worked like a charm.
Just remove both the integration modules from openerp & magento,& follow a single vender for me i used the following guide to get the Integration working.
https://openerp-magento-connector.readthedocs.org/en/develop/index.html

Sphinx autodoc TypeError: 'type' object is not iterable

When trying to build documentation (any type: html, man pages, latexpdf...) sphinx fails while trying to autodoc a subdirectory of a project. I've tried many different approaches to try to narrow down what the problem is but I can't seem to find the culprit. All of the rst files were generated by sphinx-apidoc.
directory A has the following rst file:
Directory A
=======================================
Submodules
----------
.. toctree::
A.fileB
A.fileC
A.fileD
A.fileE
Module contents
---------------
.. automodule:: A
:members:
:undoc-members:
:show-inheritance:
Failure does not occur if the :members: directive is removed. Failure also does not occur if files B or E are missing, or if the import of file B in E is missing or commented out.
It will still fail if fileB and fileE are paired down to simply the following:
fileB:
class B(object):
pass
fileE:
from fileB import B
class E(B):
pass
with the following stack trace:
# Sphinx version: 1.3b2
# Python version: 2.7.5
# Docutils version: 0.12 release
# Jinja2 version: 2.6
# Last messages:
# reading sources... [ 37%] foo
# reading sources... [ 37%] foo
# reading sources... [ 38%] foo
# reading sources... [ 38%] foo
# reading sources... [ 39%] foo
# reading sources... [ 39%] foo
# reading sources... [ 40%] foo
# reading sources... [ 40%] foo
# reading sources... [ 41%] foo
# reading sources... [ 41%] problem file
# Loaded extensions:
# sphinx.ext.autodoc (1.3b2) from Sphinx-1.3b2-py2.7.egg/sphinx/ext/autodoc.pyc
# sphinx.ext.viewcode (1.3b2) from Sphinx-1.3b2-py2.7.egg/sphinx/ext/viewcode.pyc
Traceback (most recent call last):
File "Sphinx-1.3b2-py2.7.egg/sphinx/cmdline.py", line 246, in main
app.build(opts.force_all, filenames)
File "Sphinx-1.3b2-py2.7.egg/sphinx/application.py", line 257, in build
self.builder.build_update()
File "Sphinx-1.3b2-py2.7.egg/sphinx/builders/__init__.py", line 237, in build_update
'out of date' % len(to_build))
File "Sphinx-1.3b2-py2.7.egg/sphinx/builders/__init__.py", line 251, in build
self.doctreedir, self.app))
File "Sphinx-1.3b2-py2.7.egg/sphinx/environment.py", line 585, in update
self._read_serial(docnames, app)
File "Sphinx-1.3b2-py2.7.egg/sphinx/environment.py", line 601, in _read_serial
self.read_doc(docname, app)
File "Sphinx-1.3b2-py2.7.egg/sphinx/environment.py", line 753, in read_doc
pub.publish()
File "docutils/core.py", line 217, in publish
self.settings)
File "docutils/readers/__init__.py", line 72, in read
self.parse()
File "docutils/readers/__init__.py", line 78, in parse
self.parser.parse(self.input, document)
File "docutils/parsers/rst/__init__.py", line 172, in parse
self.statemachine.run(inputlines, document, inliner=self.inliner)
File "docutils/parsers/rst/states.py", line 170, in run
input_source=document['source'])
File "docutils/statemachine.py", line 239, in run
context, state, transitions)
File "docutils/statemachine.py", line 460, in check_line
return method(match, context, next_state)
File "docutils/parsers/rst/states.py", line 2726, in underline
self.section(title, source, style, lineno - 1, messages)
File "docutils/parsers/rst/states.py", line 327, in section
self.new_subsection(title, lineno, messages)
File "docutils/parsers/rst/states.py", line 395, in new_subsection
node=section_node, match_titles=True)
File "docutils/parsers/rst/states.py", line 282, in nested_parse
node=node, match_titles=match_titles)
File "docutils/parsers/rst/states.py", line 195, in run
results = StateMachineWS.run(self, input_lines, input_offset)
File "docutils/statemachine.py", line 239, in run
context, state, transitions)
File "docutils/statemachine.py", line 460, in check_line
return method(match, context, next_state)
File "docutils/parsers/rst/states.py", line 2726, in underline
self.section(title, source, style, lineno - 1, messages)
File "docutils/parsers/rst/states.py", line 327, in section
self.new_subsection(title, lineno, messages)
File "docutils/parsers/rst/states.py", line 395, in new_subsection
node=section_node, match_titles=True)
File "docutils/parsers/rst/states.py", line 282, in nested_parse
node=node, match_titles=match_titles)
File "docutils/parsers/rst/states.py", line 195, in run
results = StateMachineWS.run(self, input_lines, input_offset)
File "docutils/statemachine.py", line 239, in run
context, state, transitions)
File "docutils/statemachine.py", line 460, in check_line
return method(match, context, next_state)
File "docutils/parsers/rst/states.py", line 2299, in explicit_markup
nodelist, blank_finish = self.explicit_construct(match)
File "docutils/parsers/rst/states.py", line 2311, in explicit_construct
return method(self, expmatch)
File "docutils/parsers/rst/states.py", line 2054, in directive
directive_class, match, type_name, option_presets)
File "docutils/parsers/rst/states.py", line 2103, in run_directive
result = directive_instance.run()
File "Sphinx-1.3b2-py2.7.egg/sphinx/ext/autodoc.py", line 1441, in run
documenter.generate(more_content=self.content)
File "Sphinx-1.3b2-py2.7.egg/sphinx/ext/autodoc.py", line 816, in generate
self.document_members(all_members)
File "Sphinx-1.3b2-py2.7.egg/sphinx/ext/autodoc.py", line 699, in document_members
members_check_module, members = self.get_object_members(want_all)
File "Sphinx-1.3b2-py2.7.egg/sphinx/ext/autodoc.py", line 878, in get_object_members
for mname in memberlist:
TypeError: 'type' object is not iterable
Is there something wrong in the files that autodoc is trying to read or if their is an issue with autodoc itself? is there some kind of work around I can try?
Thanks!
So the solution to my issue was that the init for A simply had
from A.fileD import D
__all__ == D
when it should have contained:
from A.fileD import D
__all__ == ["D"]
Sphinx has also been updated so that instead of failing out when this happens it will issue a warning:
WARNING: missing attribute mentioned in :members: or __all__: ...
see https://github.com/sphinx-doc/sphinx/issues/1674 for more information.

Google Apis Client Generator Python Not Running

I'm trying to execute Google APIs Client Generator to build new ADMIN-SDK for Java Language however I'm stuck in the generator, I've tried step by step using python2.6 and python2.7 both had similar outputs.
$ python $(/bin/pwd)/googleapis/codegen/generate_library.py --api_name=plus --api_version=v1 --language=java --output_dir=/tmp/gen --language=java
Traceback (most recent call last): File
"/Users/alejacquet/Development/git/google-apis-client-generator/src/googleapis/codegen/generate_library.py",
line 245, in
app.run() File "/Library/Python/2.7/site-packages/google_apputils-0.3.0-py2.7.egg/google/apputils/app.py",
line 216, in run
return _actual_start() File "/Library/Python/2.7/site-packages/google_apputils-0.3.0-py2.7.egg/google/apputils/app.py",
line 244, in _actual_start
really_start() File "/Library/Python/2.7/site-packages/google_apputils-0.3.0-py2.7.egg/google/apputils/app.py",
line 203, in really_start
sys.exit(main(argv)) File "/Users/alejacquet/Development/git/google-apis-client-generator/src/googleapis/codegen/generate_library.py",
line 152, in main
language_variant=FLAGS.language_variant) File "/Users/alejacquet/Development/git/google-apis-client-generator/src/googleapis/codegen/generate_library.py",
line 179, in Generate
language_variations = Targets().VariationsForLanguage(language) File
"/Users/alejacquet/Development/git/google-apis-client-generator/src/googleapis/codegen/targets.py",
line 68, in init
files.GetFileContents(self.targets_path)) File "/Users/alejacquet/Development/git/google-apis-client-generator/src/googleapis/codegen/json_with_comments.py",
line 54, in Loads
return json.loads(stripped, **kw) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/init.py",
line 326, in loads
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py",
line 366, in decode File
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py",
line 382, in raw_decode ValueError: Expecting property name: line 9
column 9 (char 198)
Any ideas?
You may have to specify --language_variant=XXX, where XXX is one of the directory names under .../templates/java

Resources