How to create Xlm file in specific folder ?

30 views
Skip to first unread message

Asad ur Rehman

unread,
Aug 10, 2016, 10:46:32 AM8/10/16
to Django users
I want to create xlm file in django in this path "etc/freeswitch/sip_profiles/external" .

Gateway.objects.values_list('name')

this should be included in file. How can i create function for it. 

Can anyone help me ? If you don't understand tell i will explain you more but please help me.


Thanks in advance !

ludovic coues

unread,
Aug 10, 2016, 10:52:41 AM8/10/16
to django...@googlegroups.com
That sound like a python problem. How to open a file and write in it.
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/619f150a-0cde-4120-887f-1fb85756c15b%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

Asad ur Rehman

unread,
Aug 10, 2016, 11:01:53 AM8/10/16
to Django users
Sir whats its solution ?

M Hashmi

unread,
Aug 10, 2016, 11:23:57 AM8/10/16
to django...@googlegroups.com
Dear Asad,

Google is trying to build such a technology that can help transmit brain waves connected via neurons to some media such as wifi or wire. 

Till the time its not a reality.......you have to paste your complete code to get help because no one can read your mind without you telling or explaining in email. 

In your last question as I've noticed you even ask questions without posting code at all and it took 7 questions to get some code sent from you. 

For above question simply you can write or create an xml file via python using ElementTree XML API. 
You also can join a query result with the xml. 

For details see: 


Post your complete code if you are not doing some cold tests (nuclear tests on your PC) so at least readers can understand the problem. 

Regards,
Mudassar

On Wed, Aug 10, 2016 at 4:01 AM, Asad ur Rehman <asadurr...@gmail.com> wrote:
Sir whats its solution ?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Asad ur Rehman

unread,
Aug 10, 2016, 11:36:41 AM8/10/16
to Django users
M Hashmi

Here is my file format. i want to create it as it is instead of name. i want to get name
Gateway.objects.values_list('name')   by this query ... and then file make in etc/freeswitch/sip_profiles/external directory ..


<profile name="external">
 
<!-- http://wiki.freeswitch.org/wiki/Sofia_Configuration_Files -->
 
<!-- This profile is only for outbound registrations to providers -->
 
<gateways>
   
<X-PRE-PROCESS cmd="include" data="external/*.xml"/>
 
</gateways>


  <aliases>
    <!--
        <alias name="outbound"/
>
       
<alias name="nat"/>
   
-->
 
</aliases>


  <domains>
    <domain name="all" alias="false" parse="true"/
>
 
</domains>


  <settings>
    <param name="debug" value="0"/
>
   
<!-- If you want FreeSWITCH to shutdown if this profile fails to load, uncomment the next line. -->
   
<!-- <param name="shutdown-on-fail" value="true"/> -->
   
<param name="sip-trace" value="no"/>
   
<param name="sip-capture" value="no"/>
   
<param name="rfc2833-pt" value="101"/>
   
<!-- RFC 5626 : Send reg-id and sip.instance -->
   
<!--<param name="enable-rfc-5626" value="true"/> -->
   
<param name="sip-port" value="$${external_sip_port}"/>
   
<param name="dialplan" value="XML"/>
   
<param name="context" value="public"/>
   
<param name="dtmf-duration" value="2000"/>
   
<param name="inbound-codec-prefs" value="$${global_codec_prefs}"/>
   
<param name="outbound-codec-prefs" value="$${outbound_codec_prefs}"/>
   
<param name="hold-music" value="$${hold_music}"/>
   
<param name="rtp-timer-name" value="soft"/>
   
<!--<param name="enable-100rel" value="true"/>-->
   
<!--<param name="disable-srv503" value="true"/>-->
   
<!-- This could be set to "passive" -->
   
<param name="local-network-acl" value="localnet.auto"/>
   
<param name="manage-presence" value="false"/>


   
<!-- used to share presence info across sofia profiles
         manage
-presence needs to be set to passive on this profile
         
if you want it to behave as if it were the internal profile
         
for presence.
   
-->
   
<!-- Name of the db to use for this profile -->
   
<!--<param name="dbname" value="share_presence"/>-->
   
<!--<param name="presence-hosts" value="$${domain}"/>-->
   
<!--<param name="force-register-domain" value="$${domain}"/>-->
   
<!--all inbound reg will stored in the db using this domain -->
   
<!--<param name="force-register-db-domain" value="$${domain}"/>-->
   
<!-- ************************************************* -->


   
<!--<param name="aggressive-nat-detection" value="true"/>-->
   
<param name="inbound-codec-negotiation" value="generous"/>
   
<param name="nonce-ttl" value="60"/>
   
<param name="auth-calls" value="false"/>
   
<param name="inbound-late-negotiation" value="true"/>
   
<param name="inbound-zrtp-passthru" value="true"/> <!-- (also enables late negotiation) -->
   
<!--
        DO NOT USE HOSTNAMES
, ONLY IP ADDRESSES IN THESE SETTINGS!
   
-->
   
<param name="rtp-ip" value="$${local_ip_v4}"/>
   
<param name="sip-ip" value="$${local_ip_v4}"/>
   
<param name="ext-rtp-ip" value="auto-nat"/>
   
<param name="ext-sip-ip" value="auto-nat"/>
   
<param name="rtp-timeout-sec" value="300"/>
   
<param name="rtp-hold-timeout-sec" value="1800"/>
   
<!--<param name="enable-3pcc" value="true"/>-->


   
<!-- TLS: disabled by default, set to "true" to enable -->
   
<param name="tls" value="$${external_ssl_enable}"/>
   
<!-- Set to true to not bind on the normal sip-port but only on the TLS port -->
   
<param name="tls-only" value="false"/>
   
<!-- additional bind parameters for TLS -->
   
<param name="tls-bind-params" value="transport=tls"/>
   
<!-- Port to listen on for TLS requests. (5081 will be used if unspecified) -->
   
<param name="tls-sip-port" value="$${external_tls_port}"/>
   
<!-- Location of the agent.pem and cafile.pem ssl certificates (needed for TLS server) -->
   
<!--<param name="tls-cert-dir" value=""/>-->
   
<!-- Optionally set the passphrase password used by openSSL to encrypt/decrypt TLS private key files -->
   
<param name="tls-passphrase" value=""/>
   
<!-- Verify the date on TLS certificates -->
   
<param name="tls-verify-date" value="true"/>
   
<!-- TLS verify policy, when registering/inviting gateways with other servers (outbound) or handling inbound registration/invite requests how should we verify their certificate -->
   
<!-- set to 'in' to only verify incoming connections, 'out' to only verify outgoing connections, 'all' to verify all connections, also 'subjects_in', 'subjects_out' and 'subjects_all' for subject validation. Multiple policies can be split with a '|' pipe -->
   
<param name="tls-verify-policy" value="none"/>
   
<!-- Certificate max verify depth to use for validating peer TLS certificates when the verify policy is not none -->
   
<param name="tls-verify-depth" value="2"/>
   
<!-- If the tls-verify-policy is set to subjects_all or subjects_in this sets which subjects are allowed, multiple subjects can be split with a '|' pipe -->
   
<param name="tls-verify-in-subjects" value=""/>
   
<!-- TLS version ("sslv23" (default), "tlsv1"). NOTE: Phones may not work with TLSv1 -->
   
<param name="tls-version" value="$${sip_tls_version}"/>
 
</settings>
</
profile>





Asad ur Rehman

unread,
Aug 10, 2016, 11:38:13 AM8/10/16
to Django users
M Hashmi Now tell me can you solve my problem or you are only here to criticize others ?

Asad ur Rehman

unread,
Aug 10, 2016, 11:45:31 AM8/10/16
to Django users
M hashmi if someone is not doing question up to the mark you have to guide him/her. We are here for learning not for criticize each other. 

M Hashmi

unread,
Aug 10, 2016, 11:51:32 AM8/10/16
to django...@googlegroups.com
Don't take it personal but if someone is offering you time to help...you also need to be precise with questions. I did solved your problem by suggesting you the correct way to do it. Do you want me to write code for you as well?? Try the solution and then let the group know about error.

On Wed, Aug 10, 2016 at 4:45 AM, Asad ur Rehman <asadurr...@gmail.com> wrote:
M hashmi if someone is not doing question up to the mark you have to guide him/her. We are here for learning not for criticize each other. 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

ludovic coues

unread,
Aug 10, 2016, 12:00:00 PM8/10/16
to django...@googlegroups.com
I'm pretty sure talking about telepathy was rude, outside the django's
code of conduct and some excuses would be nice.

The question make a lot more sense with an exemple :)
I assume Gateway is a django model (I missed that first time, sorry)
and you want to fill an xml file.

Do you mind to share the output of
Gateway.objects.all()[:3].values_list('name') and exactly what part of
your xml you want to change ? I would assume /profile/aliases as it is
filled with a comment but wouldn't be the first time I assume
something wrong.



2016-08-10 13:51 GMT+02:00 M Hashmi <mhash...@gmail.com>:
> Don't take it personal but if someone is offering you time to help...you
> also need to be precise with questions. I did solved your problem by
> suggesting you the correct way to do it. Do you want me to write code for
> you as well?? Try the solution and then let the group know about error.
>
> On Wed, Aug 10, 2016 at 4:45 AM, Asad ur Rehman <asadurr...@gmail.com>
> wrote:
>>
>> M hashmi if someone is not doing question up to the mark you have to guide
>> him/her. We are here for learning not for criticize each other.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users...@googlegroups.com.
>> To post to this group, send email to django...@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/dde7b2d7-ff2e-4d2a-b626-d1056c6018dc%40googlegroups.com.
>>
>> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CANoUts7dTyfQjVuQSpv-bVLPuN-Dw3UiHjjD3Ddt8smfDGqtyA%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.



M Hashmi

unread,
Aug 10, 2016, 12:10:13 PM8/10/16
to Django users
I apologize for my message but it reminded me the last question from asad and frustration due to absence of code. Hope Asad will make it a practice and what Ludovic suggested makes sense. 
Hope it works.

Asad ur Rehman

unread,
Aug 10, 2016, 12:13:30 PM8/10/16
to Django users
ludovic coues

Output of Gateway.objects.all()[:3].values_list('name') is (u 'TestGateway',)

Assume this file i just want to change the <gateway name = result which we get by above query . i think now your requirements are clear. Just want to change name..

<include>
  <gateway name="primo">
  <!--/// account username *required* ///-->
  <param name="username" value="garth84839525sip"/>
  <!--/// auth realm: *optional* same as gateway name, if blank ///-->
  <param name="realm" value="178.62.116.211"/>
  <!--/// username to use in from: *optional* same as  username, if blank ///-->
  <!--<param name="from-user" value="cluecon"/>-->
  <!--/// domain to use in from: *optional* same as  realm, if blank ///-->
  <!--<param name="from-domain" value="asterlink.com"/>-->
  <!--/// account password *required* ///-->
  <param name="password" value="garth52739307pass"/>
  <!--/// extension for inbound calls: *optional* same as username, if blank ///-->
  <!--<param name="extension" value="cluecon"/>-->
  <!--/// proxy host: *optional* same as realm, if blank ///-->
  <!--<param name="proxy" value="asterlink.com"/>-->
  <!--/// send register to this proxy: *optional* same as proxy, if blank ///-->
  <!--<param name="register-proxy" value="mysbc.com"/>-->
  <!--/// expire in seconds: *optional* 3600, if blank ///-->
  <!--<param name="expire-seconds" value="60"/>-->
  <!--/// do not register ///-->
  <param name="register" value="false"/>
  <!-- which transport to use for register -->
  <!--<param name="register-transport" value="udp"/>-->
  <!--How many seconds before a retry when a failure or timeout occurs -->
  <!--<param name="retry-seconds" value="30"/>-->
  <!--Use the callerid of an inbound call in the from field on outbound calls via this gateway -->
  <param name="caller-id-in-from" value="true"/>
  <!--extra sip params to send in the contact-->
  <!--<param name="contact-params" value=""/>-->
  <!-- Put the extension in the contact -->
  <!--<param name="extension-in-contact" value="true"/>-->
  <!--send an options ping every x seconds, failure will unregister and/or mark it down-->
  <!--<param name="ping" value="25"/>-->
  <!--<param name="cid-type" value="rpid"/>-->
  <!--rfc5626 : Abilitazione rfc5626 ///-->
  <!--<param name="rfc-5626" value="true"/>-->
  <!--rfc5626 : extra sip params to send in the contact-->
  <!--<param name="reg-id" value="1"/>-->
<param name="dtmf-type" value="rfc2833"/>
<param name="disable-transcoding" value="true"/>
<param name="codec-prefs" value="PCMA"/>
<param name="codec-prefs" value="PCMU"/>
   <variables>
     <variable name="absolute_codec_string" value="PCMA" direction="outbound"/>
   </variables>
  </gateway>
</include>

Asad ur Rehman

unread,
Aug 10, 2016, 12:31:34 PM8/10/16
to Django users
M Hashmi its Ok.... Next i will try to Post question that you can easily understand.

Fabio C. Barrionuevo da Luz

unread,
Aug 10, 2016, 12:37:59 PM8/10/16
to django...@googlegroups.com
Dear Asad, 

Ludovic Coues has already answered your question.

simply create a new file and save the content in it:


from django.template.loader import render_to_string

xml_content = render_to_string('my_xml_template_with_django_template_variables.xml', {'foo': 'bar'})

file_path = '/etc/freeswitch/sip_profiles/external'  # this is not the best way to indicate the file.

with open(file_path, 'w') as the_file:
    the_file.write(xml_content)


probably the python process must be running on a linux user with permissions to write to the folder you want to create the file.

operations in harddisk are usually expensive (because HD is usually thousands of times slower than RAM memory), and depending on how you program it can also be dangerous.

to this question, you could create a post_save signal, which starts a task in Celery, which will create the xml file.

said that, all here are busy people. We have bills to pay.
If you want to help, the least you can do is try to write your question so try to help us give you an answer that is useful for you.

learn how to ask questions to facilitate get a useful answer, it is important part of learning information technology and in life in general.


When I was starting, this text helped me a lot, gave me a lot of cool tips on how to ask questions:

http://www.catb.org/esr/faqs/smart-questions.html

good studies :-)



On Wed, Aug 10, 2016 at 9:31 AM, Asad ur Rehman <asadurr...@gmail.com> wrote:
M Hashmi its Ok.... Next i will try to Post question that you can easily understand.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/d/optout.



--
Fábio C. Barrionuevo da Luz
Palmas - Tocantins - Brasil - América do Sul


Blog colaborativo sobre Python e tecnologias Relacionadas, mantido totalmente no https://github.com/pythonclub/pythonclub.github.io .

Todos são livres para publicar. É só fazer fork, escrever sua postagem e mandar o pull-request. Leia mais sobre como publicar em README.md e contributing.md.
Regra básica de postagem:
"Você" acha interessante? É útil para "você"? Pode ser utilizado com Python ou é útil para quem usa Python? Está esperando o que? Publica logo, que estou louco para ler...

Asad ur Rehman

unread,
Aug 10, 2016, 12:49:07 PM8/10/16
to Django users
Fabio Caritas Barrionuevo da Luz Thanks dear i will follow your link to improve my questioning ! Thanks again.
Reply all
Reply to author
Forward
0 new messages