Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import lib #156

Closed
Delovoj opened this issue Dec 12, 2016 · 7 comments
Closed

import lib #156

Delovoj opened this issue Dec 12, 2016 · 7 comments
Assignees
Labels

Comments

@Delovoj
Copy link

@Delovoj Delovoj commented Dec 12, 2016

Hello. I have project and would like to import your lib.
if i use:
from libs.redmine import Redmine
after this code
wiki_page = redmine.wiki_page.get('name', project_id='projectname') wiki_page.text = mytext wiki_page.save()
i got

ERROR: Unsupported Redmine resource

if i use:
import libs.redmine as Redmine
after this code
wiki_page = redmine.wiki_page.get('name', project_id='projectname') wiki_page.text = mytext wiki_page.save()
i got

ERROR: 'module' object is not callable

how to include your lib?
Thank you.

@maxtepkeev maxtepkeev self-assigned this Dec 12, 2016
@maxtepkeev maxtepkeev added the question label Dec 12, 2016
@maxtepkeev
Copy link
Owner

@maxtepkeev maxtepkeev commented Dec 12, 2016

You're doing something really weird...

Why are you importing redmine from libs ? What is libs ?

It seems to me that you either haven't read the docs at all or read it inattentively, please have a look at the docs, there is everything you need to know about using this lib.

@Delovoj
Copy link
Author

@Delovoj Delovoj commented Dec 12, 2016

i would like to use ur lib without install. my project have folder "libs", where i hold all libs ...

@maxtepkeev
Copy link
Owner

@maxtepkeev maxtepkeev commented Dec 12, 2016

I see, can you show me all the code where you use from libs.redmine import Redmine and below.

@Delovoj
Copy link
Author

@Delovoj Delovoj commented Dec 12, 2016

#!/usr/bin/python

# -*- coding: utf-8 -*-

#
# Cloud VM Management
# By dossif 
#

# Avoid .pyc files - env variable: PYTHONDONTWRITEBYTECODE=True
try:
  import sys
  import config as cfg # configuration file
  from time import sleep
  import subprocess
  from os import getcwd
  import libs.ledo as ledo
  import libs.levpsie as levpsie
  import libs.log as log
  import libs.ledme as ledme # dns made easy leproxy functions
  import socket
  import libs.redmine as Redmine
  from datetime import datetime, date, time
except Exception as e:
  print "ERROR: %s" % e; sys.exit(1)
def WikiUpload():
    try:
        log.Log("try", "Trying connect to REDMINE...")
        # Digital Ocean account
        ddo = cfg.account["digitalocean-desktop"]
        # Redmine authorization
        raa = cfg.redmineauth
        redmine = Redmine(raa['url'], username=raa['username'], password=raa['password'])
    except Exception as e:
        log.Log("error", e)
    else:
        log.Log("ok", "Done! Connected to REDMINE!")
    try:
        log.Log("try", "Trying get list of VMs...")
        # main function
        iir = ledo.VmsListInRedmine(ddo)
    except Exception as e:
        log.Log("error", e)
    else:
        log.Log("ok", "Done! Got list of VMs!")
    try:
        log.Log("try", "Trying upload Wikipage...")
        # str with table of VMs
        mytext = "LAST UPDATE: %s \n\n *%s* \n\n %s \n\n %s" % (str(datetime.now()).split('.')[0], do["name"], iir[0], iir[1])
        # Wiki upload
        #redmine.wiki_page.update('sss', project_id='aaaa', text=mytext)
        wiki_page = redmine.wiki_page.get('sss', project_id='aaaa')
        wiki_page.text = mytext
        wiki_page.save()
    except Exception as e:
        log.Log("error", e)
    else:
        log.Log("ok", "Done! Wikipage VMs updated!")
def VmsListInRedmine(account):
  connection = ApiConnection(account)
  try:
    vms = connection.get_all_droplets()
    tableBody = list()
    tableHeader = ["ID", "      Name", "      Status", "      Created","      IPv4"]
    for vm in vms:
      createdAt = time.strptime(vm.created_at, "%Y-%m-%dT%H:%M:%SZ") # decode from ISO8601
      createdAt = time.strftime('%Y.%m.%d %H:%M:%S', createdAt) # encode to 'pretty' time
      tableBody.append( [vm.id, vm.name, vm.status,
                         createdAt,
                         vm.networks["v4"][0]["ip_address"] ] )
    tableBody =  tabulate(tableBody,tableHeader, tablefmt="simple")
    vmLimit = connection.get_account().droplet_limit
    vmscount = "VMs count: *%s* of *%s*" % (len(vms), vmLimit)
  except Exception as e:
    log.Log("error", e)
  else:
    return vmscount, tableBody
@maxtepkeev
Copy link
Owner

@maxtepkeev maxtepkeev commented Dec 13, 2016

Please go to file managers.py and change line 30 from

resource_paths = tuple((redmine.custom_resource_paths or ())) + ('redmine.resources',)

to

resource_paths = tuple((redmine.custom_resource_paths or ())) + ('resources',)

and line 34 from

resource_class = getattr(__import__(path, fromlist=[resource_name]), resource_name)

to

resource_class = getattr(__import__(path, globals(), fromlist=[resource_name]), resource_name)

And let me know if that solves your issue.

@Delovoj
Copy link
Author

@Delovoj Delovoj commented Dec 13, 2016

Perfect! Thank you!

P.S. using
from libs.redmine import Redmine

@maxtepkeev
Copy link
Owner

@maxtepkeev maxtepkeev commented Dec 13, 2016

Great!

Now I see where this problem comes from. I'll release this fix in the next version.

Thanks for reporting this problem!

@maxtepkeev maxtepkeev closed this Dec 13, 2016
maxtepkeev added a commit that referenced this issue Mar 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.