How to commit and push files using python library GitPython - python

Requirement:
Commit and push files to GitHub repository from a python script.
The credentials should be included in the script.
Issue:
If credentials are provided in the script the commit operation is
executing and throwing the following error,
Traceback (most recent call last):
File "/home/amith/example.py", line 14, in <module>
repo.index.add(folder_path)
AttributeError: 'Repository' object has no attribute 'index'
If credentials are, not provided in the script the commit operation is working properly by providing it on the terminal.
I need to integrate this script in Django application which should accept the credentials from the configuration file.
I have tried the following links but nothing has worked for me yet.
- link1
- link2
- link3
from git import Repo
from github import Github
from pdb import set_trace as bp
repo_dir = '--------'
repo = Repo(repo_dir)
# using username and password
g = Github("-----", "------")
folder_path = '----------'
commit_message = 'Add New file'
repo.index.add(folder_path)
repo.index.commit(commit_message)
origin = repo.remote('origin')
origin.push()
So, I am getting this error "AttributeError: 'Repository' object has no attribute 'index'".
Complete error -
Traceback (most recent call last):
File "/home/amith/example.py", line 14, in <module>
repo.index.add(folder_path)
AttributeError: 'Repository' object has no attribute 'index'

Related

Sharing variables in python

So I've recently been working on a simple project, and I've used "Jaheim Archibald's Login System" for logging in to my thing. I've found a variable that is the username entered, and I want to share that variable across another script that I'm creating. I've tried using the 'config' module, but it just gives me an attribute error.
EDIT:
Here is the sharing I tried to do:
Loginregister.py:
import config
config.x = userName
Account.py:
import config
print(config.x)
Error:
Traceback (most recent call last):
File "Account.py", line 3, in <module>
print(config.x)
AttributeError: module 'config' has no attribute 'x'

'NoneType' object is not callable error when using couchbase with git, logbook module

I'd experienced weird result when testing couchbase python SDK.
below is the source code and result:
# xxx.py
from gcouchbase.bucket import Bucket
dsn = 'couchbase://[url-of-couchbase]/[bucket-name]'
db = Bucket(dsn)
# yyy.py
import logbook
import git
from xxx import db
# python yyy.py
Traceback (most recent call last):
File "/home/username/env/local/lib/python2.7/site-packages/gcouchbase/iops_gevent10.py", line 88, in timer_event_factory
return GEventTimer()
TypeError: 'NoneType' object is not callable
[1] 8546 abort (core dumped) python yyy.py
The weird thing is, when I remove import git or import logbook from yyy.py, the error doesn't happen.
Is there any reason for this error? should any resource for couchdb be disposed?
An asynchronous event seems to arrive after the Bucket object has been removed. If you call bucket._close() explicitly, the script would not be crashed. Anyways, it looks like a bug of gcouchbase.

Print Data from PLC to Python using pycomm

I am trying to move data (a dint specifically but my example is a BOOL) from the plc to python to be used as a variable to display a picture. The issue is, if I use pycomm, I am getting an error in Windows Powershell. I feel this is a very simple error from a basic python mistake rather than a pycomm issue but I am not informed enough to tell.
SysInfo:
configparser==3.5.0
cpppo==3.9.7
greenery==2.1
ipaddress==1.0.18
pycomm==1.0.8
pyreadline==2.1
pytz==2017.2
python==2.7.13
Code I am using:
from pycomm.ab_comm.clx import Driver as ClxDriver
import logging
if __name__ == '__main__':
c = ClxDriver()
if c.open('IPADDRESSHERE'):
print(c.read_tag(['new_Bool']))
c.close()
Which is just a stripped down version of one of the examples on github https://github.com/ruscito/pycomm
This is the result from running powershell:
PS C:\Users\Tom\Documents\PythonProjects> python pycomm2.py
Traceback (most recent call last):
File "pycomm2.py", line 10, in
print(c.read_tag(['new_Bool']))
File "C:\Python27\lib\site-packages\pycomm\ab_comm\clx.py", line 359, in read_tag
self.logger.warning(self._status)
AttributeError: 'Driver' object has no attribute 'logger'
PS C:\Users\Tom\Documents\PythonProjects>
I have looked for this AttributeError and tried to find a solution, but I think the solutions I have found are over my head. If I have failed to provide some details in order for this question to make sense please let me know.
Edit:
from pycomm.ab_comm.clx import Driver as ClxDriver
import logging
if __name__ == '__main__':
logging.basicConfig(
filename="ClxDriver.log",
format="%(levelname)-10s %(asctime)s %(message)s",
level=logging.DEBUG
)
c = ClxDriver()
if c.open('IPADRESSHERE'):
print(c.read_tag(['new_Bool']))
c.close()
Yields the same attribute error.
PS C:\Users\Tom\Documents\PythonProjects> python pycommtest.py
Traceback (most recent call last):
File "pycommtest.py", line 15, in
print(c.read_tag(['new_Bool']))
File "C:\Python27\lib\site-packages\pycomm\ab_comm\clx.py", line 359, in read_tag
self.logger.warning(self._status)
AttributeError: 'Driver' object has no attribute 'logger'
PS C:\Users\Tom\Documents\PythonProjects>
I was able to read a value, but not with pycomm. Using CPPPO, I was able to continuously update a variable as needed. This may not answer the question of what was wrong with my old code, but it is my work around in case someone from the future has to do the same thing. Credit to user Liverpool_chris and the abyss of Reddit.
https://www.reddit.com/r/PLC/comments/5x3y5z/python_cpppo_library_writing_to_tag_in_plc/
from cpppo.server.enip.get_attribute import proxy_simple
import time
host = "IPHERE"
while True:
x, = proxy_simple(host).read(( "CPID"))
print x
time.sleep(5)

Getting "global name 'FbxManager' is not defined"

I am working on creating a WebGL interface for which I am trying to convert FBX models to JSON file format in an automated process using python file, convert_fbx_three.py (from Mr. Doob's GitHub project) from command line.
When I try the following command to convert the FBX:
python convert_fbx_three.py Dolpine.fbx Dolpine
I get following errors:
Error in cmd:
Traceback (most recent call last):
File "convert_fbx_three.py", line 1625, in <module>
sdkManager, scene = InitializeSdkObjects()
File "D:\xampp\htdocs\upload\user\fbx\FbxCommon.py", line 7, in InitializeSdkObjects
lSdkManager = KFbxSdkManager.Create()
NameError: global name 'FbxManager' is not defined
I am using Autodesk FBX SDK 2012.2 available here on Windows 7.
Can you please try the following:
import FbxCommon
.
.
.
lSdkManager, lScene = FbxCommon.InitializeSdkObjects()
You probably need to add environment variables pointing to the folder that contains fbx.pyd, FbxCommon.py, and fbxsip.pyd prior to calling anything in those modules.

Trouble running a compiled app which includes singleton

I'm having trouble running a compiled app which includes singleton, the .pyw compilation proccess goes just fine, but when I attempt to run the resulting .exe, it writes an error log with the message shown below:
Traceback (most recent call last):
File "main.pyw", line 16, in <module>
File "tendo\singleton.pyc", line 20, in __init__
AttributeError: 'module' object has no attribute '__file__'
this is how I'm calling singleton:
from tendo import singleton
me = singleton.SingleInstance()
The tendo's singleton module makes use of sys.modules['__main__'].__file__ to find the main directory. In py2exe it doesn't exist, that's why you get this error.
You can fix it with this answer. In tendo/singleton.py, line 20 you have:
self.lockfile = os.path.normpath(tempfile.gettempdir() + '/' +
os.path.splitext(os.path.abspath(sys.modules['__main__'].__file__))[0] \
.replace("/","-").replace(":","").replace("\\","-") + '-%s' % flavor_id +'.lock')
Replace with something like this:
path_to_script = get_main_dir() #see linkd answer
self.lockfile = os.path.normpath(tempfile.gettempdir() + '/' + path_to_script
.replace("/","-").replace(":","").replace("\\","-") + '-%s' % flavor_id +'.lock')
Report this as an issue to the author, and/or make a pull request with the fix.

Categories